From 2fabe55272336cb1a90703a1769d0957120ef1cf Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 16 Jun 2020 15:25:23 -0400 Subject: [PATCH 01/17] Stop using fc::optional. Start using std::optional --- libraries/chain/abi_serializer.cpp | 10 +- libraries/chain/authorization_manager.cpp | 18 +-- libraries/chain/block.cpp | 2 +- libraries/chain/block_header_state.cpp | 2 +- libraries/chain/block_log.cpp | 8 +- libraries/chain/controller.cpp | 100 ++++++++-------- .../include/eosio/chain/abi_serializer.hpp | 10 +- .../include/eosio/chain/authority_checker.hpp | 4 +- .../eosio/chain/authorization_manager.hpp | 4 +- libraries/chain/include/eosio/chain/block.hpp | 2 +- .../include/eosio/chain/block_header.hpp | 2 +- .../eosio/chain/block_header_state.hpp | 2 +- .../chain/include/eosio/chain/block_log.hpp | 2 +- .../include/eosio/chain/block_timestamp.hpp | 1 - .../chain/include/eosio/chain/controller.hpp | 14 +-- .../chain/include/eosio/chain/exceptions.hpp | 2 +- .../eosio/chain/global_property_object.hpp | 8 +- .../eosio/chain/protocol_feature_manager.hpp | 6 +- .../include/eosio/chain/resource_limits.hpp | 4 +- .../include/eosio/chain/thread_utils.hpp | 3 +- libraries/chain/include/eosio/chain/trace.hpp | 18 +-- .../eosio/chain/transaction_context.hpp | 2 +- libraries/chain/include/eosio/chain/types.hpp | 6 +- .../eosio/chain/wasm_eosio_binary_ops.hpp | 1 - .../eosio/chain/wasm_interface_private.hpp | 2 +- .../webassembly/eos-vm-oc/ipc_protocol.hpp | 2 +- libraries/chain/protocol_feature_manager.cpp | 2 +- libraries/chain/resource_limits.cpp | 8 +- libraries/chain/transaction_context.cpp | 2 +- .../fc/include/fc/exception/exception.hpp | 3 +- libraries/fc/include/fc/filesystem.hpp | 7 +- libraries/fc/include/fc/io/raw.hpp | 9 +- libraries/fc/include/fc/io/raw_fwd.hpp | 4 +- libraries/fc/include/fc/log/logger_config.hpp | 2 +- libraries/fc/include/fc/network/url.hpp | 11 +- libraries/fc/include/fc/reflect/typename.hpp | 3 +- libraries/fc/include/fc/reflect/variant.hpp | 4 +- .../fc/include/fc/rpc/api_connection.hpp | 5 +- .../include/fc/rpc/binary_api_connection.hpp | 5 +- libraries/fc/include/fc/string.hpp | 6 +- libraries/fc/include/fc/time.hpp | 3 +- libraries/fc/include/fc/variant.hpp | 11 +- libraries/fc/src/filesystem.cpp | 6 +- libraries/fc/src/log/gelf_appender.cpp | 6 +- libraries/fc/src/log/logger_config.cpp | 4 +- libraries/fc/src/network/gntp.cpp | 16 +-- libraries/fc/src/network/http/http_client.cpp | 16 +-- libraries/fc/src/network/ntp.cpp | 4 +- libraries/fc/src/network/url.cpp | 20 ++-- libraries/fc/src/rpc/websocket_api.cpp | 2 +- .../eosio/state_history/serialization.hpp | 26 ++-- .../state_history/transaction_trace_cache.hpp | 2 +- .../include/eosio/state_history/types.hpp | 40 +++---- .../testing/include/eosio/testing/tester.hpp | 10 +- libraries/testing/tester.cpp | 22 ++-- plugins/chain_plugin/chain_plugin.cpp | 77 ++++++------ .../eosio/chain_plugin/chain_plugin.hpp | 41 ++++--- plugins/history_plugin/history_plugin.cpp | 8 +- .../eosio/history_plugin/history_plugin.hpp | 9 +- plugins/http_plugin/http_plugin.cpp | 8 +- .../include/eosio/net_plugin/net_plugin.hpp | 2 +- .../include/eosio/net_plugin/protocol.hpp | 2 +- plugins/net_plugin/net_plugin.cpp | 33 +++--- .../eosio/producer_plugin/producer_plugin.hpp | 34 +++--- plugins/producer_plugin/producer_plugin.cpp | 42 +++---- .../signature_provider_plugin.cpp | 2 +- .../state_history_plugin.cpp | 22 ++-- .../test_control_plugin.cpp | 5 +- .../eosio/trace_api/chain_extraction.hpp | 2 +- .../eosio/trace_api/request_handler.hpp | 2 +- plugins/trace_api_plugin/store_provider.cpp | 2 +- .../trace_api_plugin/test/test_trace_file.cpp | 10 +- plugins/trace_api_plugin/trace_api_plugin.cpp | 8 +- .../txn_test_gen_plugin.cpp | 2 +- .../include/eosio/wallet_plugin/se_wallet.hpp | 2 +- .../include/eosio/wallet_plugin/wallet.hpp | 2 +- .../eosio/wallet_plugin/wallet_api.hpp | 2 +- .../eosio/wallet_plugin/yubihsm_wallet.hpp | 2 +- plugins/wallet_plugin/se_wallet.cpp | 4 +- plugins/wallet_plugin/wallet.cpp | 10 +- plugins/wallet_plugin/wallet_manager.cpp | 4 +- plugins/wallet_plugin/yubihsm_wallet.cpp | 6 +- programs/cleos/httpc.cpp | 2 +- programs/cleos/main.cpp | 28 ++--- programs/eosio-blocklog/main.cpp | 4 +- programs/eosio-launcher/main.cpp | 5 +- programs/eosio-tester/main.cpp | 12 +- tests/chain_plugin_tests.cpp | 6 +- unittests/abi_tests.cpp | 2 +- unittests/api_tests.cpp | 112 +++++++++--------- unittests/chain_tests.cpp | 2 +- unittests/delay_tests.cpp | 2 +- unittests/forked_tests.cpp | 4 +- unittests/misc_tests.cpp | 2 +- unittests/producer_schedule_tests.cpp | 30 ++--- unittests/protocol_feature_tests.cpp | 58 ++++----- unittests/resource_limits_test.cpp | 2 +- unittests/restart_chain_tests.cpp | 2 +- unittests/state_history_tests.cpp | 6 +- unittests/wasm_tests.cpp | 4 +- unittests/whitelist_blacklist_tests.cpp | 6 +- 101 files changed, 553 insertions(+), 573 deletions(-) diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index a950d2d815e..66b60a2b2f4 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -38,7 +38,7 @@ namespace eosio { namespace chain { if( is_array ) fc::raw::pack( ds, var.as>() ); else if ( is_optional ) - fc::raw::pack( ds, var.as>() ); + fc::raw::pack( ds, var.as>() ); else fc::raw::pack( ds, var.as()); }; @@ -51,7 +51,7 @@ namespace eosio { namespace chain { if( is_array ) return variant_from_stream>(stream); else if ( is_optional ) - return variant_from_stream>(stream); + return variant_from_stream>(stream); return variant_from_stream(stream); }, pack_function() @@ -65,7 +65,7 @@ namespace eosio { namespace chain { if( is_array ) return variant_from_stream>(stream); else if ( is_optional ) - return variant_from_stream>(stream); + return variant_from_stream>(stream); return variant_from_stream(stream, yield); }, pack_function() @@ -605,10 +605,10 @@ namespace eosio { namespace chain { return type_name(); } - optional abi_serializer::get_error_message( uint64_t error_code )const { + std::optional abi_serializer::get_error_message( uint64_t error_code )const { auto itr = error_messages.find( error_code ); if( itr == error_messages.end() ) - return optional(); + return std::optional(); return itr->second; } diff --git a/libraries/chain/authorization_manager.cpp b/libraries/chain/authorization_manager.cpp index c12a3c27cc0..135aed6ed14 100644 --- a/libraries/chain/authorization_manager.cpp +++ b/libraries/chain/authorization_manager.cpp @@ -276,7 +276,7 @@ namespace eosio { namespace chain { return _db.get( boost::make_tuple(level.actor,level.permission) ); } EOS_RETHROW_EXCEPTIONS( chain::permission_query_exception, "Failed to retrieve permission: ${level}", ("level", level) ) } - optional authorization_manager::lookup_linked_permission( account_name authorizer_account, + std::optional authorization_manager::lookup_linked_permission( account_name authorizer_account, account_name scope, action_name act_name )const @@ -295,13 +295,13 @@ namespace eosio { namespace chain { if (link != nullptr) { return link->required_permission; } - return optional(); + return std::optional(); - // return optional(); + // return std::optional(); } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) } - optional authorization_manager::lookup_minimum_permission( account_name authorizer_account, + std::optional authorization_manager::lookup_minimum_permission( account_name authorizer_account, account_name scope, action_name act_name )const @@ -318,12 +318,12 @@ namespace eosio { namespace chain { } try { - optional linked_permission = lookup_linked_permission(authorizer_account, scope, act_name); - if( !linked_permission ) + std::optional linked_permission = lookup_linked_permission(authorizer_account, scope, act_name); + if( !linked_permission.has_value() ) return config::active_name; if( *linked_permission == config::eosio_any_name ) - return optional(); + return std::optional(); return linked_permission; } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) @@ -397,7 +397,7 @@ namespace eosio { namespace chain { const auto linked_permission_name = lookup_minimum_permission(link.account, link.code, link.type); - if( !linked_permission_name ) // if action is linked to eosio.any permission + if( !linked_permission_name.has_value() ) // if action is linked to eosio.any permission return; EOS_ASSERT( get_permission(auth).satisfies( get_permission({link.account, *linked_permission_name}), @@ -418,7 +418,7 @@ namespace eosio { namespace chain { "the owner of the linked permission needs to be the actor of the declared authorization" ); const auto unlinked_permission_name = lookup_linked_permission(unlink.account, unlink.code, unlink.type); - EOS_ASSERT( unlinked_permission_name.valid(), transaction_exception, + EOS_ASSERT( unlinked_permission_name.has_value(), transaction_exception, "cannot unlink non-existent permission link of account '${account}' for actions matching '${code}::${action}'", ("account", unlink.account)("code", unlink.code)("action", unlink.type) ); diff --git a/libraries/chain/block.cpp b/libraries/chain/block.cpp index ddee4ff0911..39322d12d25 100644 --- a/libraries/chain/block.cpp +++ b/libraries/chain/block.cpp @@ -133,7 +133,7 @@ namespace eosio { namespace chain { return validate_and_extract_block_extensions( block_extensions ); } - fc::optional signed_block::to_signed_block_v0() const { + std::optional signed_block::to_signed_block_v0() const { if (prune_state != prune_state_type::complete_legacy) return {}; diff --git a/libraries/chain/block_header_state.cpp b/libraries/chain/block_header_state.cpp index c79d7c7f3f2..ffc1fcb23dd 100644 --- a/libraries/chain/block_header_state.cpp +++ b/libraries/chain/block_header_state.cpp @@ -173,7 +173,7 @@ namespace eosio { namespace chain { signed_block_header pending_block_header_state::make_block_header( const checksum256_type& transaction_mroot, const checksum256_type& action_mroot, - const optional& new_producers, + const std::optional& new_producers, vector&& new_protocol_feature_activations, const protocol_feature_set& pfs )const diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index da38b3f9a2d..6cef49b1683 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -296,9 +296,9 @@ namespace eosio { namespace chain { uint64_t first_block_position() const { return first_block_pos; } chain_id_type chain_id() const { return preamble.chain_id(); } - fc::optional get_genesis_state() const { - return std::visit(overloaded{[](const chain_id_type&) { return fc::optional{}; }, - [](const genesis_state& state) { return fc::optional{state}; }}, + std::optional get_genesis_state() const { + return std::visit(overloaded{[](const chain_id_type&) { return std::optional{}; }, + [](const genesis_state& state) { return std::optional{state}; }}, preamble.chain_context); } @@ -952,7 +952,7 @@ namespace eosio { namespace chain { return backup_dir; } - fc::optional block_log::extract_genesis_state( const fc::path& block_dir ) { + std::optional block_log::extract_genesis_state( const fc::path& block_dir ) { boost::filesystem::path p(block_dir / "blocks.log"); for_each_file_in_dir_matches(block_dir, R"(blocks-1-\d+\.log)", [&p](boost::filesystem::path log_path) { p = log_path; }); return block_log_data(p).get_genesis_state(); diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 5f3ee8563fc..c8b040e677c 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -74,7 +74,7 @@ class maybe_session { } explicit maybe_session(database& db) { - _session = db.start_undo_session(true); + _session.emplace(db.start_undo_session(true)); } maybe_session(const maybe_session&) = delete; @@ -96,7 +96,7 @@ class maybe_session { maybe_session& operator = ( maybe_session&& mv ) { if (mv._session) { - _session = move(*mv._session); + _session.emplace(move(*mv._session)); mv._session.reset(); } else { _session.reset(); @@ -106,7 +106,7 @@ class maybe_session { }; private: - optional _session; + std::optional _session; }; struct building_block { @@ -120,7 +120,7 @@ struct building_block { {} pending_block_header_state _pending_block_header_state; - optional _new_pending_producer_schedule; + std::optional _new_pending_producer_schedule; vector _new_protocol_feature_activations; size_t _num_new_protocol_features_that_have_activated = 0; deque _pending_trx_metas; @@ -136,7 +136,7 @@ struct assembled_block { signed_block_ptr _unsigned_block; // if the _unsigned_block pre-dates block-signing authorities this may be present. - optional _new_producer_authority_cache; + std::optional _new_producer_authority_cache; }; struct completed_block { @@ -157,7 +157,7 @@ struct pending_state { maybe_session _db_session; block_stage_type _block_stage; controller::block_status _block_status = controller::block_status::incomplete; - optional _producer_block_id; + std::optional _producer_block_id; /** @pre _block_stage cannot hold completed_block alternative */ const pending_block_header_state& get_pending_block_header_state()const { @@ -232,7 +232,7 @@ struct controller_impl { chainbase::database db; chainbase::database reversible_blocks; ///< a special database to persist blocks that have successfully been applied but are still reversible block_log blog; - optional pending; + std::optional pending; block_state_ptr head; fork_database fork_db; wasm_interface wasmif; @@ -241,10 +241,10 @@ struct controller_impl { protocol_feature_manager protocol_features; controller::config conf; const chain_id_type chain_id; // read by thread_pool threads, value will not be changed - optional replay_head_time; + std::optional replay_head_time; db_read_mode read_mode = db_read_mode::SPECULATIVE; bool in_trx_requiring_checks = false; ///< if true, checks that are normally skipped on replay (e.g. auth checks) cannot be skipped - optional subjective_cpu_leeway; + std::optional subjective_cpu_leeway; bool trusted_producer_light_validation = false; uint32_t snapshot_head_block = 0; named_thread_pool thread_pool; @@ -891,8 +891,8 @@ struct controller_impl { resource_limits.add_to_snapshot(snapshot); } - static fc::optional extract_legacy_genesis_state( snapshot_reader& snapshot, uint32_t version ) { - fc::optional genesis; + static std::optional extract_legacy_genesis_state( snapshot_reader& snapshot, uint32_t version ) { + std::optional genesis; using v2 = legacy::snapshot_global_property_object_v2; if (std::clamp(version, v2::minimum_version, v2::maximum_version) == version ) { @@ -961,8 +961,8 @@ struct controller_impl { using v3 = legacy::snapshot_global_property_object_v3; if (std::clamp(header.version, v2::minimum_version, v2::maximum_version) == header.version ) { - fc::optional genesis = extract_legacy_genesis_state(*snapshot, header.version); - EOS_ASSERT( genesis, snapshot_exception, + std::optional genesis = extract_legacy_genesis_state(*snapshot, header.version); + EOS_ASSERT( genesis.has_value(), snapshot_exception, "Snapshot indicates chain_snapshot_header version 2, but does not contain a genesis_state. " "It must be corrupted."); snapshot->read_section([&db=this->db,gs_chain_id=genesis->compute_chain_id()]( auto §ion ) { @@ -1477,7 +1477,7 @@ struct controller_impl { fc::time_point deadline, uint32_t billed_cpu_time_us, bool explicit_billed_cpu_time, - fc::optional explicit_net_usage_words ) + std::optional explicit_net_usage_words ) { EOS_ASSERT(deadline != fc::time_point(), transaction_exception, "deadline cannot be uninitialized"); @@ -1509,7 +1509,7 @@ struct controller_impl { try { const transaction& trn = trx->packed_trx()->get_transaction(); if( trx->implicit ) { - EOS_ASSERT( !explicit_net_usage_words.valid(), transaction_exception, "NET usage cannot be explicitly set for implicit transactions" ); + EOS_ASSERT( !explicit_net_usage_words.has_value(), transaction_exception, "NET usage cannot be explicitly set for implicit transactions" ); trx_context.init_for_implicit_trx(); trx_context.enforce_whiteblacklist = false; } else { @@ -1595,9 +1595,9 @@ struct controller_impl { uint16_t confirm_block_count, const vector& new_protocol_feature_activations, controller::block_status s, - const optional& producer_block_id ) + const std::optional& producer_block_id ) { - EOS_ASSERT( !pending, block_validate_exception, "pending block already exists" ); + EOS_ASSERT( !pending.has_value(), block_validate_exception, "pending block already exists" ); if (auto dm_logger = get_deep_mind_logger()) { // The head block represents the block just before this one that is about to start, so add 1 to get this block num @@ -1696,13 +1696,13 @@ struct controller_impl { const auto& gpo = self.get_global_properties(); - if( gpo.proposed_schedule_block_num.valid() && // if there is a proposed schedule that was proposed in a block ... + if( gpo.proposed_schedule_block_num.has_value() && // if there is a proposed schedule that was proposed in a block ... ( *gpo.proposed_schedule_block_num <= pbhs.dpos_irreversible_blocknum ) && // ... that has now become irreversible ... pbhs.prev_pending_schedule.schedule.producers.size() == 0 // ... and there was room for a new pending schedule prior to any possible promotion ) { // Promote proposed schedule to pending schedule. - if( !replay_head_time ) { + if( !replay_head_time.has_value() ) { ilog( "promoting proposed schedule (set in block ${proposed_num}) to pending; current block: ${n} lib: ${lib} schedule: ${schedule} ", ("proposed_num", *gpo.proposed_schedule_block_num)("n", pbhs.block_num) ("lib", pbhs.dpos_irreversible_blocknum) @@ -1714,7 +1714,7 @@ struct controller_impl { pending->_block_stage.get()._new_pending_producer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); db.modify( gpo, [&]( auto& gp ) { - gp.proposed_schedule_block_num = optional(); + gp.proposed_schedule_block_num = std::optional(); gp.proposed_schedule.version=0; gp.proposed_schedule.producers.clear(); }); @@ -1751,7 +1751,7 @@ struct controller_impl { void finalize_block() { - EOS_ASSERT( pending, block_validate_exception, "it is not valid to finalize when there is no pending block"); + EOS_ASSERT( pending.has_value(), block_validate_exception, "it is not valid to finalize when there is no pending block"); EOS_ASSERT( pending->_block_stage.contains(), block_validate_exception, "already called finalize_block"); try { @@ -1833,7 +1833,7 @@ struct controller_impl { EOS_ASSERT( bsp == head, fork_database_exception, "committed block did not become the new head in fork database"); } - if( !replay_head_time && read_mode != db_read_mode::IRREVERSIBLE ) { + if( !replay_head_time.has_value() && read_mode != db_read_mode::IRREVERSIBLE ) { reversible_blocks.create( [&]( auto& ubo ) { ubo.blocknum = bsp->block_num; ubo.set_block( bsp->block ); @@ -1972,7 +1972,7 @@ struct controller_impl { : ( !!std::get<0>( trx_metas.at( packed_idx ) ) ? std::get<0>( trx_metas.at( packed_idx ) ) : std::get<1>( trx_metas.at( packed_idx ) ).get() ) ); - fc::optional explicit_net_usage_words; + std::optional explicit_net_usage_words; if( explicit_net ) { explicit_net_usage_words = receipt.net_usage_words.value; } @@ -2067,7 +2067,7 @@ struct controller_impl { const forked_branch_callback& forked_branch_cb, const trx_meta_cache_lookup& trx_lookup ) { controller::block_status s = controller::block_status::complete; - EOS_ASSERT(!pending, block_validate_exception, "it is not valid to push a block when there is a pending block"); + EOS_ASSERT(!pending.has_value(), block_validate_exception, "it is not valid to push a block when there is a pending block"); auto reset_prod_light_validation = fc::make_scoped_exit([old_value=trusted_producer_light_validation, this]() { trusted_producer_light_validation = old_value; @@ -2105,7 +2105,7 @@ struct controller_impl { self.validate_db_available_size(); self.validate_reversible_available_size(); - EOS_ASSERT(!pending, block_validate_exception, "it is not valid to push a block when there is a pending block"); + EOS_ASSERT(!pending.has_value(), block_validate_exception, "it is not valid to push a block when there is a pending block"); try { EOS_ASSERT( b, block_validate_exception, "trying to push empty block" ); @@ -2197,7 +2197,7 @@ struct controller_impl { } for( auto ritr = branches.first.rbegin(); ritr != branches.first.rend(); ++ritr ) { - optional except; + std::optional except; try { apply_block( *ritr, (*ritr)->is_valid() ? controller::block_status::validated : controller::block_status::complete, trx_lookup ); @@ -2705,7 +2705,7 @@ void controller::start_block( block_timestamp_type when, uint16_t confirm_block_ { validate_db_available_size(); - EOS_ASSERT( !my->pending, block_validate_exception, "pending block already exists" ); + EOS_ASSERT( !my->pending.has_value(), block_validate_exception, "pending block already exists" ); vector new_protocol_feature_activations; @@ -2721,7 +2721,7 @@ void controller::start_block( block_timestamp_type when, uint16_t confirm_block_ } my->start_block( when, confirm_block_count, new_protocol_feature_activations, - block_status::incomplete, optional() ); + block_status::incomplete, std::optional() ); } void controller::start_block( block_timestamp_type when, @@ -2735,7 +2735,7 @@ void controller::start_block( block_timestamp_type when, } my->start_block( when, confirm_block_count, new_protocol_feature_activations, - block_status::incomplete, optional() ); + block_status::incomplete, std::optional() ); } block_state_ptr controller::finalize_block( const signer_callback_type& signer_callback ) { @@ -2898,7 +2898,7 @@ account_name controller::fork_db_pending_head_block_producer()const { } time_point controller::pending_block_time()const { - EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->header.timestamp; @@ -2907,7 +2907,7 @@ time_point controller::pending_block_time()const { } account_name controller::pending_block_producer()const { - EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->header.producer; @@ -2916,7 +2916,7 @@ account_name controller::pending_block_producer()const { } const block_signing_authority& controller::pending_block_signing_authority()const { - EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->valid_block_signing_authority; @@ -2924,13 +2924,13 @@ const block_signing_authority& controller::pending_block_signing_authority()cons return my->pending->get_pending_block_header_state().valid_block_signing_authority; } -optional controller::pending_producer_block_id()const { - EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); +std::optional controller::pending_producer_block_id()const { + EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); return my->pending->_producer_block_id; } const deque& controller::get_pending_trx_receipts()const { - EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); return my->pending->get_trx_receipts(); } @@ -3030,7 +3030,7 @@ sha256 controller::calculate_integrity_hash()const { try { } FC_LOG_AND_RETHROW() } void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) const { - EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" ); + EOS_ASSERT( !my->pending.has_value(), block_validate_exception, "cannot take a consistent snapshot with a pending block" ); return my->add_to_snapshot(snapshot); } @@ -3042,7 +3042,7 @@ int64_t controller::set_proposed_producers( vector producers return -1; } - if( gpo.proposed_schedule_block_num.valid() ) { + if( gpo.proposed_schedule_block_num.has_value() ) { if( *gpo.proposed_schedule_block_num != cur_block_num ) return -1; // there is already a proposed schedule set in a previous block, wait for it to become pending @@ -3086,7 +3086,7 @@ int64_t controller::set_proposed_producers( vector producers } const producer_authority_schedule& controller::active_producers()const { - if( !(my->pending) ) + if( !(my->pending.has_value()) ) return my->head->active_schedule; if( my->pending->_block_stage.contains() ) @@ -3096,7 +3096,7 @@ const producer_authority_schedule& controller::active_producers()const { } const producer_authority_schedule& controller::pending_producers()const { - if( !(my->pending) ) + if( !(my->pending.has_value()) ) return my->head->pending_schedule.schedule; if( my->pending->_block_stage.contains() ) @@ -3117,16 +3117,16 @@ const producer_authority_schedule& controller::pending_producers()const { return bb._pending_block_header_state.prev_pending_schedule.schedule; } -optional controller::proposed_producers()const { +std::optional controller::proposed_producers()const { const auto& gpo = get_global_properties(); - if( !gpo.proposed_schedule_block_num.valid() ) - return optional(); + if( !gpo.proposed_schedule_block_num.has_value() ) + return std::optional(); return producer_authority_schedule::from_shared(gpo.proposed_schedule); } bool controller::light_validation_allowed() const { - if (!my->pending || my->in_trx_requiring_checks) { + if (!my->pending.has_value() || my->in_trx_requiring_checks) { return false; } @@ -3231,11 +3231,11 @@ void controller::check_key_list( const public_key_type& key )const { } bool controller::is_building_block()const { - return my->pending.valid(); + return my->pending.has_value(); } bool controller::is_producing_block()const { - if( !my->pending ) return false; + if( !my->pending.has_value() ) return false; return (my->pending->_block_status == block_status::incomplete); } @@ -3311,7 +3311,7 @@ void controller::set_subjective_cpu_leeway(fc::microseconds leeway) { my->subjective_cpu_leeway = leeway; } -fc::optional controller::get_subjective_cpu_leeway() const { +std::optional controller::get_subjective_cpu_leeway() const { return my->subjective_cpu_leeway; } @@ -3396,12 +3396,12 @@ vm::wasm_allocator& controller::get_wasm_allocator() { } #endif -fc::optional controller::convert_exception_to_error_code( const fc::exception& e ) { +std::optional controller::convert_exception_to_error_code( const fc::exception& e ) { const chain_exception* e_ptr = dynamic_cast( &e ); if( e_ptr == nullptr ) return {}; - if( !e_ptr->error_code ) return static_cast(system_error_code::generic_system_error); + if( !e_ptr->error_code.has_value() ) return static_cast(system_error_code::generic_system_error); return e_ptr->error_code; } @@ -3414,7 +3414,7 @@ chain_id_type controller::extract_chain_id(snapshot_reader& snapshot) { }); // check if this is a legacy version of the snapshot, which has a genesis state instead of chain id - fc::optional genesis = controller_impl::extract_legacy_genesis_state(snapshot, header.version); + std::optional genesis = controller_impl::extract_legacy_genesis_state(snapshot, header.version); if (genesis) { return genesis->compute_chain_id(); } @@ -3428,7 +3428,7 @@ chain_id_type controller::extract_chain_id(snapshot_reader& snapshot) { return chain_id; } -fc::optional controller::extract_chain_id_from_db( const path& state_dir ) { +std::optional controller::extract_chain_id_from_db( const path& state_dir ) { try { chainbase::database db( state_dir, chainbase::database::read_only ); diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index 6f39dd95f6a..d5844f7e4b3 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -62,7 +62,7 @@ struct abi_serializer { type_name get_table_type(name action)const; type_name get_action_result_type(name action_result)const; - optional get_error_message( uint64_t error_code )const; + std::optional get_error_message( uint64_t error_code )const; fc::variant binary_to_variant( const std::string_view& type, const bytes& binary, const yield_function_t& yield, bool short_path = false )const; [[deprecated("use the overload with yield_function_t[=create_yield_function(max_serialization_time)]")]] @@ -442,7 +442,7 @@ namespace impl { try { auto abi = resolver(act.account); - if (abi.valid()) { + if (abi.has_value()) { auto type = abi->get_action_type(act.name); if (!type.empty()) { try { @@ -684,7 +684,7 @@ namespace impl { * this will degrade to the common fc::to_variant as soon as the type no longer contains * ABI related info * - * @tparam Reslover - callable with the signature (const name& code_account) -> optional + * @tparam Reslover - callable with the signature (const name& code_account) -> std::optional */ template class abi_to_variant_visitor @@ -812,7 +812,7 @@ namespace impl { valid_empty_data = act.data.empty(); } else if ( data.is_object() ) { auto abi = resolver(act.account); - if (abi.valid()) { + if (abi.has_value()) { auto type = abi->get_action_type(act.name); if (!type.empty()) { variant_to_binary_context _ctx(*abi, ctx, type); @@ -890,7 +890,7 @@ namespace impl { * this will degrade to the common fc::from_variant as soon as the type no longer contains * ABI related info * - * @tparam Reslover - callable with the signature (const name& code_account) -> optional + * @tparam Reslover - callable with the signature (const name& code_account) -> std::optional */ template class abi_from_variant_visitor : public reflector_init_visitor diff --git a/libraries/chain/include/eosio/chain/authority_checker.hpp b/libraries/chain/include/eosio/chain/authority_checker.hpp index b79971295ae..16a3f954090 100644 --- a/libraries/chain/include/eosio/chain/authority_checker.hpp +++ b/libraries/chain/include/eosio/chain/authority_checker.hpp @@ -129,7 +129,7 @@ namespace detail { return {range.begin(), range.end()}; } - static optional + static std::optional permission_status_in_cache( const permission_cache_type& permissions, const permission_level& level ) { @@ -141,7 +141,7 @@ namespace detail { if( itr != permissions.end() ) return itr->second; - return optional(); + return std::optional(); } private: diff --git a/libraries/chain/include/eosio/chain/authorization_manager.hpp b/libraries/chain/include/eosio/chain/authorization_manager.hpp index df441c1eb2c..429f6728321 100644 --- a/libraries/chain/include/eosio/chain/authorization_manager.hpp +++ b/libraries/chain/include/eosio/chain/authorization_manager.hpp @@ -61,7 +61,7 @@ namespace eosio { namespace chain { * @param code_account The account which publishes the contract that handles the message * @param type The type of message */ - optional lookup_minimum_permission( account_name authorizer_account, + std::optional lookup_minimum_permission( account_name authorizer_account, scope_name code_account, action_name type )const; @@ -126,7 +126,7 @@ namespace eosio { namespace chain { void check_unlinkauth_authorization( const unlinkauth& unlink, const vector& auths )const; fc::microseconds check_canceldelay_authorization( const canceldelay& cancel, const vector& auths )const; - optional lookup_linked_permission( account_name authorizer_account, + std::optional lookup_linked_permission( account_name authorizer_account, scope_name code_account, action_name type )const; diff --git a/libraries/chain/include/eosio/chain/block.hpp b/libraries/chain/include/eosio/chain/block.hpp index 7053993a99f..5850c6c2350 100644 --- a/libraries/chain/include/eosio/chain/block.hpp +++ b/libraries/chain/include/eosio/chain/block.hpp @@ -144,7 +144,7 @@ namespace eosio { namespace chain { signed_block& operator=(const signed_block&) = delete; signed_block& operator=(signed_block&&) = default; signed_block clone() const { return *this; } - fc::optional to_signed_block_v0() const; + std::optional to_signed_block_v0() const; fc::enum_type prune_state{prune_state_type::complete_legacy}; deque transactions; /// new or generated transactions diff --git a/libraries/chain/include/eosio/chain/block_header.hpp b/libraries/chain/include/eosio/chain/block_header.hpp index faf00797de7..9f1d5b130b7 100644 --- a/libraries/chain/include/eosio/chain/block_header.hpp +++ b/libraries/chain/include/eosio/chain/block_header.hpp @@ -53,7 +53,7 @@ namespace eosio { namespace chain { * irreversible and that it the new producer schedule takes effect this block. */ - using new_producers_type = optional; + using new_producers_type = std::optional; uint32_t schedule_version = 0; new_producers_type new_producers; diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index c3eef9a032d..259a593fa21 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -83,7 +83,7 @@ struct pending_block_header_state : public detail::block_header_state_common { signed_block_header make_block_header( const checksum256_type& transaction_mroot, const checksum256_type& action_mroot, - const optional& new_producers, + const std::optional& new_producers, vector&& new_protocol_feature_activations, const protocol_feature_set& pfs)const; diff --git a/libraries/chain/include/eosio/chain/block_log.hpp b/libraries/chain/include/eosio/chain/block_log.hpp index fe6e6e9b10f..d1aa26a1a5e 100644 --- a/libraries/chain/include/eosio/chain/block_log.hpp +++ b/libraries/chain/include/eosio/chain/block_log.hpp @@ -72,7 +72,7 @@ namespace eosio { namespace chain { static fc::path repair_log( const fc::path& data_dir, uint32_t truncate_at_block = UINT32_MAX, const char* reversible_block_dir_name="" ); - static fc::optional extract_genesis_state( const fc::path& data_dir ); + static std::optional extract_genesis_state( const fc::path& data_dir ); static chain_id_type extract_chain_id( const fc::path& data_dir ); diff --git a/libraries/chain/include/eosio/chain/block_timestamp.hpp b/libraries/chain/include/eosio/chain/block_timestamp.hpp index 821e44efbff..a20f609ddcc 100644 --- a/libraries/chain/include/eosio/chain/block_timestamp.hpp +++ b/libraries/chain/include/eosio/chain/block_timestamp.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include namespace eosio { namespace chain { diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 44620f09a8c..298afeeece8 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -225,13 +225,13 @@ namespace eosio { namespace chain { time_point pending_block_time()const; account_name pending_block_producer()const; const block_signing_authority& pending_block_signing_authority()const; - optional pending_producer_block_id()const; + std::optional pending_producer_block_id()const; const deque& get_pending_trx_receipts()const; const producer_authority_schedule& active_producers()const; const producer_authority_schedule& pending_producers()const; - optional proposed_producers()const; + std::optional proposed_producers()const; uint32_t last_irreversible_block_num() const; block_id_type last_irreversible_block_id() const; @@ -296,7 +296,7 @@ namespace eosio { namespace chain { uint32_t get_terminate_at_block()const; void set_subjective_cpu_leeway(fc::microseconds leeway); - fc::optional get_subjective_cpu_leeway() const; + std::optional get_subjective_cpu_leeway() const; void set_greylist_limit( uint32_t limit ); uint32_t get_greylist_limit()const; @@ -312,7 +312,7 @@ namespace eosio { namespace chain { vm::wasm_allocator& get_wasm_allocator(); #endif - static fc::optional convert_exception_to_error_code( const fc::exception& e ); + static std::optional convert_exception_to_error_code( const fc::exception& e ); signal block_start; // block_num signal pre_accepted_block; @@ -337,7 +337,7 @@ namespace eosio { namespace chain { wasm_interface& get_wasm_interface(); - optional get_abi_serializer( account_name n, const abi_serializer::yield_function_t& yield )const { + std::optional get_abi_serializer( account_name n, const abi_serializer::yield_function_t& yield )const { if( n.good() ) { try { const auto& a = get_account( n ); @@ -346,7 +346,7 @@ namespace eosio { namespace chain { return abi_serializer( abi, yield ); } FC_CAPTURE_AND_LOG((n)) } - return optional(); + return std::optional(); } template @@ -369,7 +369,7 @@ namespace eosio { namespace chain { static chain_id_type extract_chain_id(snapshot_reader& snapshot); - static fc::optional extract_chain_id_from_db( const path& state_dir ); + static std::optional extract_chain_id_from_db( const path& state_dir ); void replace_producer_keys( const public_key_type& key ); void replace_account_keys( name account, name permission, const public_key_type& key ); diff --git a/libraries/chain/include/eosio/chain/exceptions.hpp b/libraries/chain/include/eosio/chain/exceptions.hpp index 6d99432749f..50686ab814b 100644 --- a/libraries/chain/include/eosio/chain/exceptions.hpp +++ b/libraries/chain/include/eosio/chain/exceptions.hpp @@ -125,7 +125,7 @@ { if( code() == CODE ) throw *this;\ else fc::exception::dynamic_rethrow_exception(); \ } \ - fc::optional error_code; \ + std::optional error_code; \ }; namespace eosio { namespace chain { diff --git a/libraries/chain/include/eosio/chain/global_property_object.hpp b/libraries/chain/include/eosio/chain/global_property_object.hpp index 1570a73ab95..5831eafcff4 100644 --- a/libraries/chain/include/eosio/chain/global_property_object.hpp +++ b/libraries/chain/include/eosio/chain/global_property_object.hpp @@ -26,7 +26,7 @@ namespace eosio { namespace chain { static constexpr uint32_t maximum_version = 2; static_assert(chain_snapshot_header::minimum_compatible_version <= maximum_version, "snapshot_global_property_object_v2 is no longer needed"); - optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_schedule_type proposed_schedule; chain_config configuration; }; @@ -35,7 +35,7 @@ namespace eosio { namespace chain { static constexpr uint32_t maximum_version = 3; static_assert(chain_snapshot_header::minimum_compatible_version <= maximum_version, "snapshot_global_property_object_v3 is no longer needed"); - optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; @@ -54,7 +54,7 @@ namespace eosio { namespace chain { public: id_type id; - optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; shared_producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; @@ -91,7 +91,7 @@ namespace eosio { namespace chain { >; struct snapshot_global_property_object { - optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; diff --git a/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp b/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp index 6e6b1e81eb9..be0db8cea62 100644 --- a/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp +++ b/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp @@ -99,7 +99,7 @@ struct protocol_feature { time_point earliest_allowed_activation_time; bool preactivation_required = false; bool enabled = false; - optional builtin_feature; + std::optional builtin_feature; fc::variant to_variant( bool include_subjective_restrictions = true, fc::mutable_variant_object* additional_fields = nullptr )const; @@ -133,7 +133,7 @@ class protocol_feature_set { recognized_t is_recognized( const digest_type& feature_digest, time_point now )const; - optional get_builtin_digest( builtin_protocol_feature_t feature_codename )const; + std::optional get_builtin_digest( builtin_protocol_feature_t feature_codename )const; const protocol_feature& get_protocol_feature( const digest_type& feature_digest )const; @@ -316,7 +316,7 @@ class protocol_feature_manager { const protocol_feature_set& get_protocol_feature_set()const { return _protocol_feature_set; } - optional get_builtin_digest( builtin_protocol_feature_t feature_codename )const { + std::optional get_builtin_digest( builtin_protocol_feature_t feature_codename )const { return _protocol_feature_set.get_builtin_digest( feature_codename ); } diff --git a/libraries/chain/include/eosio/chain/resource_limits.hpp b/libraries/chain/include/eosio/chain/resource_limits.hpp index a49fbf36276..5eeaa8d7514 100644 --- a/libraries/chain/include/eosio/chain/resource_limits.hpp +++ b/libraries/chain/include/eosio/chain/resource_limits.hpp @@ -98,9 +98,9 @@ namespace eosio { namespace chain { namespace resource_limits { std::pair get_account_net_limit( const account_name& name, uint32_t greylist_limit = config::maximum_elastic_resource_multiplier ) const; std::pair - get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit = config::maximum_elastic_resource_multiplier, const fc::optional& current_time={} ) const; + get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit = config::maximum_elastic_resource_multiplier, const std::optional& current_time={} ) const; std::pair - get_account_net_limit_ex( const account_name& name, uint32_t greylist_limit = config::maximum_elastic_resource_multiplier, const fc::optional& current_time={} ) const; + get_account_net_limit_ex( const account_name& name, uint32_t greylist_limit = config::maximum_elastic_resource_multiplier, const std::optional& current_time={} ) const; int64_t get_account_ram_usage( const account_name& name ) const; diff --git a/libraries/chain/include/eosio/chain/thread_utils.hpp b/libraries/chain/include/eosio/chain/thread_utils.hpp index 3ec462d5402..3869c3b8a67 100644 --- a/libraries/chain/include/eosio/chain/thread_utils.hpp +++ b/libraries/chain/include/eosio/chain/thread_utils.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -32,7 +31,7 @@ namespace eosio { namespace chain { boost::asio::thread_pool _thread_pool; boost::asio::io_context _ioc; - fc::optional _ioc_work; + std::optional _ioc_work; }; diff --git a/libraries/chain/include/eosio/chain/trace.hpp b/libraries/chain/include/eosio/chain/trace.hpp index ca2b2d937a1..eabf9146395 100644 --- a/libraries/chain/include/eosio/chain/trace.hpp +++ b/libraries/chain/include/eosio/chain/trace.hpp @@ -31,7 +31,7 @@ namespace eosio { namespace chain { fc::unsigned_int action_ordinal; fc::unsigned_int creator_action_ordinal; fc::unsigned_int closest_unnotified_ancestor_action_ordinal; - fc::optional receipt; + std::optional receipt; action_name receiver; action act; bool context_free = false; @@ -40,11 +40,11 @@ namespace eosio { namespace chain { transaction_id_type trx_id; ///< the transaction that generated this action uint32_t block_num = 0; block_timestamp_type block_time; - fc::optional producer_block_id; + std::optional producer_block_id; flat_set account_ram_deltas; flat_set account_disk_deltas; - fc::optional except; - fc::optional error_code; + std::optional except; + std::optional error_code; std::vector return_value; }; @@ -52,17 +52,17 @@ namespace eosio { namespace chain { transaction_id_type id; uint32_t block_num = 0; block_timestamp_type block_time; - fc::optional producer_block_id; - fc::optional receipt; + std::optional producer_block_id; + std::optional receipt; fc::microseconds elapsed; uint64_t net_usage = 0; bool scheduled = false; vector action_traces; - fc::optional account_ram_delta; + std::optional account_ram_delta; transaction_trace_ptr failed_dtrx_trace; - fc::optional except; - fc::optional error_code; + std::optional except; + std::optional error_code; std::exception_ptr except_ptr; }; diff --git a/libraries/chain/include/eosio/chain/transaction_context.hpp b/libraries/chain/include/eosio/chain/transaction_context.hpp index 0dbfcf6d912..d6d830fc7cb 100644 --- a/libraries/chain/include/eosio/chain/transaction_context.hpp +++ b/libraries/chain/include/eosio/chain/transaction_context.hpp @@ -152,7 +152,7 @@ namespace eosio { namespace chain { controller& control; const packed_transaction& packed_trx; - optional undo_session; + std::optional undo_session; transaction_trace_ptr trace; fc::time_point start; diff --git a/libraries/chain/include/eosio/chain/types.hpp b/libraries/chain/include/eosio/chain/types.hpp index 9c7ef150369..780e74492eb 100644 --- a/libraries/chain/include/eosio/chain/types.hpp +++ b/libraries/chain/include/eosio/chain/types.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -66,7 +65,6 @@ namespace eosio { namespace chain { using fc::variant_object; using fc::variant; using fc::enum_type; - using fc::optional; using fc::unsigned_int; using fc::signed_int; using fc::time_point_sec; @@ -408,7 +406,7 @@ namespace eosio { namespace chain { struct decompose<> { template static auto extract( uint16_t id, const vector& data, ResultVariant& result ) - -> fc::optional + -> std::optional { return {}; } @@ -421,7 +419,7 @@ namespace eosio { namespace chain { template static auto extract( uint16_t id, const vector& data, ResultVariant& result ) - -> fc::optional + -> std::optional { if( id == head_t::extension_id() ) { result = fc::raw::unpack( data ); diff --git a/libraries/chain/include/eosio/chain/wasm_eosio_binary_ops.hpp b/libraries/chain/include/eosio/chain/wasm_eosio_binary_ops.hpp index cc6149f5ba9..36c6327981c 100644 --- a/libraries/chain/include/eosio/chain/wasm_eosio_binary_ops.hpp +++ b/libraries/chain/include/eosio/chain/wasm_eosio_binary_ops.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include diff --git a/libraries/chain/include/eosio/chain/wasm_interface_private.hpp b/libraries/chain/include/eosio/chain/wasm_interface_private.hpp index 68a002713ee..3e15ed824de 100644 --- a/libraries/chain/include/eosio/chain/wasm_interface_private.hpp +++ b/libraries/chain/include/eosio/chain/wasm_interface_private.hpp @@ -213,7 +213,7 @@ namespace eosio { namespace chain { const wasm_interface::vm_type wasm_runtime_time; #ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED - fc::optional eosvmoc; + std::optional eosvmoc; #endif }; diff --git a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/ipc_protocol.hpp b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/ipc_protocol.hpp index 01d9cc91d06..98949c4f79c 100644 --- a/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/ipc_protocol.hpp +++ b/libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/ipc_protocol.hpp @@ -11,7 +11,7 @@ struct initialize_message { }; struct initalize_response_message { - fc::optional error_message; //no error message? everything groovy + std::optional error_message; //no error message? everything groovy }; struct code_tuple { diff --git a/libraries/chain/protocol_feature_manager.cpp b/libraries/chain/protocol_feature_manager.cpp index 8dfa40576a9..b19f34f5465 100644 --- a/libraries/chain/protocol_feature_manager.cpp +++ b/libraries/chain/protocol_feature_manager.cpp @@ -377,7 +377,7 @@ Allows privileged contracts to set the constraints on WebAssembly code. return recognized_t::ready; } - optional protocol_feature_set::get_builtin_digest( builtin_protocol_feature_t feature_codename )const { + std::optional protocol_feature_set::get_builtin_digest( builtin_protocol_feature_t feature_codename )const { uint32_t indx = static_cast( feature_codename ); if( indx >= _recognized_builtin_protocol_features.size() ) diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index bef37ed2ae8..4b0ec69db90 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -446,7 +446,7 @@ std::pair resource_limits_manager::get_account_cpu_limit( const a } std::pair -resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit, const fc::optional& current_time) const { +resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uint32_t greylist_limit, const std::optional& current_time) const { const auto& state = _db.get(); const auto& usage = _db.get(name); @@ -492,7 +492,7 @@ resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uin arl.max = impl::downgrade_cast(max_user_use_in_window); arl.last_usage_update_time = block_timestamp_type(usage.cpu_usage.last_ordinal); arl.current_used = arl.used; - if ( current_time.valid() ) { + if ( current_time.has_value() ) { if (current_time->slot > usage.cpu_usage.last_ordinal) { auto history_usage = usage.cpu_usage; history_usage.add(0, current_time->slot, window_size); @@ -508,7 +508,7 @@ std::pair resource_limits_manager::get_account_net_limit( const a } std::pair -resource_limits_manager::get_account_net_limit_ex( const account_name& name, uint32_t greylist_limit, const fc::optional& current_time) const { +resource_limits_manager::get_account_net_limit_ex( const account_name& name, uint32_t greylist_limit, const std::optional& current_time) const { const auto& config = _db.get(); const auto& state = _db.get(); const auto& usage = _db.get(name); @@ -553,7 +553,7 @@ resource_limits_manager::get_account_net_limit_ex( const account_name& name, uin arl.max = impl::downgrade_cast(max_user_use_in_window); arl.last_usage_update_time = block_timestamp_type(usage.net_usage.last_ordinal); arl.current_used = arl.used; - if ( current_time.valid() ) { + if ( current_time.has_value() ) { if (current_time->slot > usage.net_usage.last_ordinal) { auto history_usage = usage.net_usage; history_usage.add(0, current_time->slot, window_size); diff --git a/libraries/chain/transaction_context.cpp b/libraries/chain/transaction_context.cpp index 9d191b5cad9..11981eb6097 100644 --- a/libraries/chain/transaction_context.cpp +++ b/libraries/chain/transaction_context.cpp @@ -57,7 +57,7 @@ namespace eosio { namespace chain { ,pseudo_start(s) { if (!c.skip_db_sessions()) { - undo_session = c.mutable_db().start_undo_session(true); + undo_session.emplace(c.mutable_db().start_undo_session(true)); } trace->id = packed_trx.id(); trace->block_num = c.head_block_num() + 1; diff --git a/libraries/fc/include/fc/exception/exception.hpp b/libraries/fc/include/fc/exception/exception.hpp index 83ebb338eb2..c8565ccdd75 100644 --- a/libraries/fc/include/fc/exception/exception.hpp +++ b/libraries/fc/include/fc/exception/exception.hpp @@ -4,7 +4,6 @@ * @brief Defines exception's used by fc */ #include -#include #include #include #include @@ -139,7 +138,7 @@ namespace fc void from_variant( const variant& e, exception& ll ); typedef std::shared_ptr exception_ptr; - typedef optional oexception; + typedef std::optional oexception; /** diff --git a/libraries/fc/include/fc/filesystem.hpp b/libraries/fc/include/fc/filesystem.hpp index e3bfc3fa158..389c6108251 100644 --- a/libraries/fc/include/fc/filesystem.hpp +++ b/libraries/fc/include/fc/filesystem.hpp @@ -4,7 +4,6 @@ #include #include -#include #include namespace boost { @@ -195,13 +194,13 @@ namespace fc { { public: inline ~temp_file_base() { remove(); } - inline operator bool() const { return _path.valid(); } - inline bool operator!() const { return !_path; } + inline operator bool() const { return _path.has_value(); } + inline bool operator!() const { return !_path.has_value(); } const fc::path& path() const; void remove(); void release(); protected: - typedef fc::optional path_t; + typedef std::optional path_t; inline temp_file_base(const path_t& path) : _path(path) {} inline temp_file_base(path_t&& path) : _path(std::move(path)) {} path_t _path; diff --git a/libraries/fc/include/fc/io/raw.hpp b/libraries/fc/include/fc/io/raw.hpp index b861bb4ced7..834e720d164 100644 --- a/libraries/fc/include/fc/io/raw.hpp +++ b/libraries/fc/include/fc/io/raw.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -268,13 +267,13 @@ namespace fc { // optional template - void pack( Stream& s, const fc::optional& v ) { - fc::raw::pack( s, bool(!!v) ); - if( !!v ) fc::raw::pack( s, *v ); + void pack( Stream& s, const std::optional& v ) { + fc::raw::pack( s, v.has_value() ); + if( v.has_value() ) fc::raw::pack( s, *v ); } template - void unpack( Stream& s, fc::optional& v ) + void unpack( Stream& s, std::optional& v ) { try { bool b; fc::raw::unpack( s, b ); if( b ) { v = T(); fc::raw::unpack( s, *v ); } diff --git a/libraries/fc/include/fc/io/raw_fwd.hpp b/libraries/fc/include/fc/io/raw_fwd.hpp index cb334cc67a2..e71d26ec3e3 100644 --- a/libraries/fc/include/fc/io/raw_fwd.hpp +++ b/libraries/fc/include/fc/io/raw_fwd.hpp @@ -83,9 +83,9 @@ namespace fc { template inline void unpack( Stream& s, ip::endpoint& v ); - template void unpack( Stream& s, fc::optional& v ); + template void unpack( Stream& s, std::optional& v ); template void unpack( Stream& s, const T& v ); - template void pack( Stream& s, const fc::optional& v ); + template void pack( Stream& s, const std::optional& v ); template void pack( Stream& s, const safe& v ); template void unpack( Stream& s, fc::safe& v ); diff --git a/libraries/fc/include/fc/log/logger_config.hpp b/libraries/fc/include/fc/log/logger_config.hpp index ffcb2f978a4..8d021cdc575 100644 --- a/libraries/fc/include/fc/log/logger_config.hpp +++ b/libraries/fc/include/fc/log/logger_config.hpp @@ -28,7 +28,7 @@ namespace fc { string name; ostring parent; /// if not set, then parents level is used. - fc::optional level; + std::optional level; bool enabled; /// if any appenders are sepecified, then parent's appenders are not set. bool additivity; diff --git a/libraries/fc/include/fc/network/url.hpp b/libraries/fc/include/fc/network/url.hpp index 09007073ef0..217f4e611a1 100644 --- a/libraries/fc/include/fc/network/url.hpp +++ b/libraries/fc/include/fc/network/url.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include @@ -8,9 +7,9 @@ namespace fc { - typedef fc::optional ostring; - typedef fc::optional opath; - typedef fc::optional ovariant_object; + typedef std::optional ostring; + typedef std::optional opath; + typedef std::optional ovariant_object; namespace detail { class url_impl; } @@ -28,7 +27,7 @@ namespace fc { url( const url& c ); url( url&& c ); url( const string& proto, const ostring& host, const ostring& user, const ostring& pass, - const opath& path, const ostring& query, const ovariant_object& args, const fc::optional& port); + const opath& path, const ostring& query, const ovariant_object& args, const std::optional& port); ~url(); url& operator=( const url& c ); @@ -49,7 +48,7 @@ namespace fc { opath path()const; ostring query()const; ovariant_object args()const; - fc::optional port()const; + std::optional port()const; private: friend class mutable_url; diff --git a/libraries/fc/include/fc/reflect/typename.hpp b/libraries/fc/include/fc/reflect/typename.hpp index d96cfd9b248..889c8fefa8d 100644 --- a/libraries/fc/include/fc/reflect/typename.hpp +++ b/libraries/fc/include/fc/reflect/typename.hpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -58,7 +57,7 @@ namespace fc { return n.c_str(); } }; - template struct get_typename> + template struct get_typename> { static const char* name() { static std::string n = std::string("optional<") + get_typename::name() + ">"; diff --git a/libraries/fc/include/fc/reflect/variant.hpp b/libraries/fc/include/fc/reflect/variant.hpp index f26f73cbe15..c3089b4cb14 100644 --- a/libraries/fc/include/fc/reflect/variant.hpp +++ b/libraries/fc/include/fc/reflect/variant.hpp @@ -25,9 +25,9 @@ namespace fc private: template - void add( mutable_variant_object& vo, const char* name, const optional& v )const + void add( mutable_variant_object& vo, const char* name, const std::optional& v )const { - if( v.valid() ) + if( v.has_value() ) vo(name,*v); } template diff --git a/libraries/fc/include/fc/rpc/api_connection.hpp b/libraries/fc/include/fc/rpc/api_connection.hpp index c2268ea724a..8cd6c94fa14 100644 --- a/libraries/fc/include/fc/rpc/api_connection.hpp +++ b/libraries/fc/include/fc/rpc/api_connection.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include @@ -174,7 +173,7 @@ namespace fc { std::function to_generic( const std::function(Args...)>& f )const; template - std::function to_generic( const std::function>(Args...)>& f )const; + std::function to_generic( const std::function>(Args...)>& f )const; template std::function to_generic( const std::function& f )const; @@ -393,7 +392,7 @@ namespace fc { } template std::function generic_api::api_visitor::to_generic( - const std::function>(Args...)>& f )const + const std::function>(Args...)>& f )const { auto api_con = _api_con; auto gapi = &_api; diff --git a/libraries/fc/include/fc/rpc/binary_api_connection.hpp b/libraries/fc/include/fc/rpc/binary_api_connection.hpp index 9c9ce2f7d11..81a81d33292 100644 --- a/libraries/fc/include/fc/rpc/binary_api_connection.hpp +++ b/libraries/fc/include/fc/rpc/binary_api_connection.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include #include #include @@ -178,7 +177,7 @@ namespace fc { std::function to_generic( const std::function(Args...)>& f )const; template - std::function to_generic( const std::function>(Args...)>& f )const; + std::function to_generic( const std::function>(Args...)>& f )const; template std::function to_generic( const std::function& f )const; @@ -401,7 +400,7 @@ namespace fc { } template std::function generic_api::api_visitor::to_generic( - const std::function>(Args...)>& f )const + const std::function>(Args...)>& f )const { auto api_con = _api_con; auto gapi = &api; diff --git a/libraries/fc/include/fc/string.hpp b/libraries/fc/include/fc/string.hpp index 3a932351490..74dcf690b1d 100644 --- a/libraries/fc/include/fc/string.hpp +++ b/libraries/fc/include/fc/string.hpp @@ -1,9 +1,9 @@ #pragma once #include #include -#include #ifndef USE_FC_STRING +#include #include namespace fc { @@ -23,7 +23,7 @@ namespace fc inline fc::string to_string( size_t s) { return to_string(uint64_t(s)); } #endif - typedef fc::optional ostring; + typedef std::optional ostring; class variant_object; fc::string format_string( const fc::string&, const variant_object&, bool minimize = false ); fc::string trim( const fc::string& ); @@ -143,7 +143,7 @@ namespace fc { fc::string to_string( uint64_t ); fc::string to_string( int64_t ); - typedef fc::optional ostring; + typedef std::optional ostring; class variant_object; fc::string format_string( const fc::string&, const variant_object& ); diff --git a/libraries/fc/include/fc/time.hpp b/libraries/fc/include/fc/time.hpp index a401476e4ff..1c1b433bd53 100644 --- a/libraries/fc/include/fc/time.hpp +++ b/libraries/fc/include/fc/time.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #ifdef _MSC_VER #pragma warning (push) @@ -121,7 +120,7 @@ namespace fc { uint32_t utc_seconds; }; - typedef fc::optional otime_point; + typedef std::optional otime_point; /** return a human-readable approximate time, relative to now() * e.g., "4 hours ago", "2 months ago", etc. diff --git a/libraries/fc/include/fc/variant.hpp b/libraries/fc/include/fc/variant.hpp index a9f98a74982..9c372e3c8be 100644 --- a/libraries/fc/include/fc/variant.hpp +++ b/libraries/fc/include/fc/variant.hpp @@ -10,7 +10,6 @@ #include // memset -#include #include #include #include @@ -349,10 +348,10 @@ namespace fc } template - variant( const optional& v ) + variant( const std::optional& v ) { memset( this, 0, sizeof(*this) ); - if( v.valid() ) *this = variant(*v); + if( v.has_value() ) *this = variant(*v); } template @@ -367,7 +366,7 @@ namespace fc double _data; ///< Alligned according to double requirements char _type[sizeof(void*)]; ///< pad to void* size }; - typedef optional ovariant; + typedef std::optional ovariant; /** @ingroup Serializable */ void from_variant( const variant& var, string& vo ); @@ -390,9 +389,9 @@ namespace fc void from_variant( const variant& var, uint32_t& vo ); /** @ingroup Serializable */ template - void from_variant( const variant& var, optional& vo ) + void from_variant( const variant& var, std::optional& vo ) { - if( var.is_null() ) vo = optional(); + if( var.is_null() ) vo = std::optional(); else { vo = T(); diff --git a/libraries/fc/src/filesystem.cpp b/libraries/fc/src/filesystem.cpp index 24a96c99a17..a32cbae20e8 100644 --- a/libraries/fc/src/filesystem.cpp +++ b/libraries/fc/src/filesystem.cpp @@ -421,7 +421,7 @@ namespace fc { const fc::path& temp_file_base::path() const { - if (!_path) + if (!_path.has_value()) { FC_THROW( "Temporary directory has been released." ); } @@ -430,7 +430,7 @@ namespace fc { void temp_file_base::remove() { - if (_path.valid()) + if (_path.has_value()) { try { @@ -446,7 +446,7 @@ namespace fc { void temp_file_base::release() { - _path = fc::optional(); + _path = std::optional(); } const fc::path& home_path() diff --git a/libraries/fc/src/log/gelf_appender.cpp b/libraries/fc/src/log/gelf_appender.cpp index b5b3fc643a6..74e2e4b444a 100644 --- a/libraries/fc/src/log/gelf_appender.cpp +++ b/libraries/fc/src/log/gelf_appender.cpp @@ -30,7 +30,7 @@ namespace fc { public: config cfg; - optional gelf_endpoint; + std::optional gelf_endpoint; udp_socket gelf_socket; impl(const config& c) : @@ -60,7 +60,7 @@ namespace fc catch (...) { } - if (!my->gelf_endpoint) + if (!my->gelf_endpoint.has_value()) { // couldn't parse as a numeric ip address, try resolving as a DNS name. // This can yield, so don't do it in the catch block above @@ -100,7 +100,7 @@ namespace fc void gelf_appender::log(const log_message& message) { - if (!my->gelf_endpoint) + if (!my->gelf_endpoint.has_value()) return; log_context context = message.get_context(); diff --git a/libraries/fc/src/log/logger_config.cpp b/libraries/fc/src/log/logger_config.cpp index 032b29c26d4..4d2ef776a89 100644 --- a/libraries/fc/src/log/logger_config.cpp +++ b/libraries/fc/src/log/logger_config.cpp @@ -81,11 +81,11 @@ namespace fc { auto lgr = log_config::get().logger_map[cfg.loggers[i].name]; // TODO: finish configure logger here... - if( cfg.loggers[i].parent.valid() ) { + if( cfg.loggers[i].parent.has_value() ) { lgr.set_parent( log_config::get().logger_map[*cfg.loggers[i].parent] ); } lgr.set_name(cfg.loggers[i].name); - if( cfg.loggers[i].level.valid() ) lgr.set_log_level( *cfg.loggers[i].level ); + if( cfg.loggers[i].level.has_value() ) lgr.set_log_level( *cfg.loggers[i].level ); for( auto a = cfg.loggers[i].appenders.begin(); a != cfg.loggers[i].appenders.end(); ++a ){ diff --git a/libraries/fc/src/network/gntp.cpp b/libraries/fc/src/network/gntp.cpp index 89c17354f58..0c522d31378 100644 --- a/libraries/fc/src/network/gntp.cpp +++ b/libraries/fc/src/network/gntp.cpp @@ -45,19 +45,19 @@ namespace fc class gntp_notifier_impl { public: - gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const optional& password = optional()); + gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const std::optional& password = std::optional()); // there's no API to change these right now, it will always notify localhost at the default GNTP port std::string hostname; uint16_t port; - optional password; + std::optional password; std::string application_name; gntp_icon_ptr application_icon; gntp_notification_type_list notification_types; // list of all notification types we're registered to send - optional endpoint; // cache the last endpoint we've connected to + std::optional endpoint; // cache the last endpoint we've connected to bool connection_failed; // true after we've tried to connect and failed bool is_registered; // true after we've registered @@ -66,7 +66,7 @@ namespace fc }; gntp_notifier_impl::gntp_notifier_impl(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const optional& password /* = optional() */) : + const std::optional& password /* = std::optional() */) : hostname(host_to_notify), port(port), password(password), @@ -94,14 +94,14 @@ namespace fc ("error_report", er.to_detail_string())); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = optional(); + endpoint = std::optional(); } catch (...) { ilog("Failed to connect to GNTP service using an endpoint that previously worked"); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = optional(); + endpoint = std::optional(); } } if (!connected) @@ -165,7 +165,7 @@ namespace fc } gntp_notifier::gntp_notifier(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const optional& password /* = optional() */) : + const std::optional& password /* = std::optional() */) : my(new detail::gntp_notifier_impl(host_to_notify, port, password)) { } @@ -243,7 +243,7 @@ namespace fc } } gntp_guid gntp_notifier::send_notification(std::string name, std::string title, std::string text, - const gntp_icon_ptr& icon, optional coalescingId /* = optional() */) + const gntp_icon_ptr& icon, std::optional coalescingId /* = std::optional() */) { if (my->connection_failed) return gntp_guid(); diff --git a/libraries/fc/src/network/http/http_client.cpp b/libraries/fc/src/network/http/http_client.cpp index a943b9cc0b4..cf1e07a0417 100644 --- a/libraries/fc/src/network/http/http_client.cpp +++ b/libraries/fc/src/network/http/http_client.cpp @@ -85,7 +85,7 @@ class http_client_impl { } }); - optional f_result; + std::optional f_result; f(f_result); _ioc.restart(); @@ -118,7 +118,7 @@ class http_client_impl { tcp::resolver local_resolver(_ioc); bool cancelled = false; - auto res = sync_do_with_deadline(s, deadline, [&local_resolver, &cancelled, &s, &host, &port](optional& final_ec){ + auto res = sync_do_with_deadline(s, deadline, [&local_resolver, &cancelled, &s, &host, &port](std::optional& final_ec){ local_resolver.async_resolve(host, port, [&cancelled, &s, &final_ec](const error_code& ec, tcp::resolver::results_type resolved ){ if (ec) { final_ec.emplace(ec); @@ -141,7 +141,7 @@ class http_client_impl { template error_code sync_write_with_timeout(SyncReadStream& s, http::request& req, const deadline_type& deadline ) { - return sync_do_with_deadline(s, deadline, [&s, &req](optional& final_ec){ + return sync_do_with_deadline(s, deadline, [&s, &req](std::optional& final_ec){ http::async_write(s, req, [&final_ec]( const error_code& ec, std::size_t ) { final_ec.emplace(ec); }); @@ -150,7 +150,7 @@ class http_client_impl { template error_code sync_read_with_timeout(SyncReadStream& s, boost::beast::flat_buffer& buffer, http::response& res, const deadline_type& deadline ) { - return sync_do_with_deadline(s, deadline, [&s, &buffer, &res](optional& final_ec){ + return sync_do_with_deadline(s, deadline, [&s, &buffer, &res](std::optional& final_ec){ http::async_read(s, buffer, res, [&final_ec]( const error_code& ec, std::size_t ) { final_ec.emplace(ec); }); @@ -158,7 +158,7 @@ class http_client_impl { } host_key url_to_host_key( const url& dest ) { - FC_ASSERT(dest.host(), "Provided URL has no host"); + FC_ASSERT(dest.host().has_value(), "Provided URL has no host"); uint16_t port = 80; if (dest.port()) { port = *dest.port(); @@ -213,7 +213,7 @@ class http_client_impl { error_code ec = sync_connect_with_timeout(ssl_socket->next_layer(), *dest.host(), dest.port() ? std::to_string(*dest.port()) : "443", deadline); if (!ec) { - ec = sync_do_with_deadline(ssl_socket->next_layer(), deadline, [&ssl_socket](optional& final_ec) { + ec = sync_do_with_deadline(ssl_socket->next_layer(), deadline, [&ssl_socket](std::optional& final_ec) { ssl_socket->async_handshake(ssl::stream_base::client, [&final_ec](const error_code& ec) { final_ec.emplace(ec); }); @@ -316,7 +316,7 @@ class http_client_impl { variant post_sync(const url& dest, const variant& payload, const fc::time_point& _deadline) { static const deadline_type epoch(boost::gregorian::date(1970, 1, 1)); auto deadline = epoch + boost::posix_time::microseconds(_deadline.time_since_epoch().count()); - FC_ASSERT(dest.host(), "No host set on URL"); + FC_ASSERT(dest.host().has_value(), "No host set on URL"); string path = dest.path() ? dest.path()->generic_string() : "/"; if (dest.query()) { @@ -426,7 +426,7 @@ class http_client_impl { if(socket_file.empty()) FC_THROW_EXCEPTION( parse_error_exception, "couldn't discover socket path"); url_path = "/" / url_path; - return _unix_url_paths.emplace(full_url, fc::url("unix", socket_file.string(), ostring(), ostring(), url_path.string(), ostring(), ovariant_object(), fc::optional())).first->second; + return _unix_url_paths.emplace(full_url, fc::url("unix", socket_file.string(), ostring(), ostring(), url_path.string(), ostring(), ovariant_object(), std::optional())).first->second; } #endif diff --git a/libraries/fc/src/network/ntp.cpp b/libraries/fc/src/network/ntp.cpp index 539407195d9..00aeadf878f 100644 --- a/libraries/fc/src/network/ntp.cpp +++ b/libraries/fc/src/network/ntp.cpp @@ -243,11 +243,11 @@ namespace fc my->_ntp_thread.async( [=](){ my->request_now(); } ).get(); } - optional ntp::get_time()const + std::optional ntp::get_time()const { if( my->_last_ntp_delta_initialized ) return fc::time_point::now() + fc::microseconds(my->_last_ntp_delta_microseconds); - return optional(); + return std::optional(); } } //namespace fc diff --git a/libraries/fc/src/network/url.cpp b/libraries/fc/src/network/url.cpp index 069f94f7a34..29c24797457 100644 --- a/libraries/fc/src/network/url.cpp +++ b/libraries/fc/src/network/url.cpp @@ -60,7 +60,7 @@ namespace fc _path = fc::path( "/" ) / _lpath; #endif std::getline( ss, _largs ); - if( _args.valid() && _args->size() ) + if( _args.has_value() && _args->size() ) { // TODO: args = fc::move(_args); _query = fc::move(_largs); @@ -74,7 +74,7 @@ namespace fc opath _path; ostring _query; ovariant_object _args; - fc::optional _port; + std::optional _port; }; } @@ -91,17 +91,17 @@ namespace fc { std::stringstream ss; ss<_proto<<"://"; - if( my->_user.valid() ) { + if( my->_user.has_value() ) { ss << *my->_user; - if( my->_pass.valid() ) { + if( my->_pass.has_value() ) { ss<<":"<<*my->_pass; } ss<<"@"; } - if( my->_host.valid() ) ss<<*my->_host; - if( my->_port.valid() ) ss<<":"<<*my->_port; - if( my->_path.valid() ) ss<_path->generic_string(); - if( my->_query.valid() ) ss<<"?"<<*my->_query; + if( my->_host.has_value() ) ss<<*my->_host; + if( my->_port.has_value() ) ss<<":"<<*my->_port; + if( my->_path.has_value() ) ss<_path->generic_string(); + if( my->_query.has_value() ) ss<<"?"<<*my->_query; // if( my->_args ) ss<<"?"<<*my->_args; return ss.str(); } @@ -132,7 +132,7 @@ namespace fc } url::url( const string& proto, const ostring& host, const ostring& user, const ostring& pass, - const opath& path, const ostring& query, const ovariant_object& args, const fc::optional& port) + const opath& path, const ostring& query, const ovariant_object& args, const std::optional& port) :my( std::make_shared() ) { my->_proto = proto; @@ -191,7 +191,7 @@ namespace fc { return my->_args; } - fc::optional url::port()const + std::optional url::port()const { return my->_port; } diff --git a/libraries/fc/src/rpc/websocket_api.cpp b/libraries/fc/src/rpc/websocket_api.cpp index 60ef7062b48..8539fc7cf87 100644 --- a/libraries/fc/src/rpc/websocket_api.cpp +++ b/libraries/fc/src/rpc/websocket_api.cpp @@ -77,7 +77,7 @@ void websocket_api_connection::send_notice( uint64_t callback_id, variants args /* = variants() */ ) { - fc::rpc::request req{ optional(), "notice", {callback_id, std::move(args)}}; + fc::rpc::request req{ std::optional(), "notice", {callback_id, std::move(args)}}; _connection.send_message( fc::json::to_string(req) ); } diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index 852554fa35b..186068b2270 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -108,8 +108,8 @@ void history_pack_big_bytes(ST& ds, const eosio::chain::bytes& v) { } template -void history_pack_big_bytes(ST& ds, const fc::optional& v) { - fc::raw::pack(ds, v.valid()); +void history_pack_big_bytes(ST& ds, const std::optional& v) { + fc::raw::pack(ds, v.has_value()); if (v) history_pack_big_bytes(ds, *v); } @@ -319,7 +319,7 @@ ST& operator<<(ST& ds, const history_serial_wrapper& template ST& operator<<(ST& ds, const history_serial_wrapper& obj) { fc::raw::pack(ds, fc::unsigned_int(1)); - fc::raw::pack(ds, as_type>(obj.obj.proposed_schedule_block_num)); + fc::raw::pack(ds, as_type>(obj.obj.proposed_schedule_block_num)); fc::raw::pack(ds, make_history_serial_wrapper( obj.db, as_type(obj.obj.proposed_schedule))); fc::raw::pack(ds, make_history_serial_wrapper(obj.db, as_type(obj.obj.configuration))); @@ -541,10 +541,10 @@ ST& operator<<(ST& ds, const history_serial_wrapper return ds; } -inline fc::optional cap_error_code(const fc::optional& error_code) { - fc::optional result; +inline std::optional cap_error_code(const std::optional& error_code) { + std::optional result; - if (!error_code) + if (!error_code.has_value()) return result; const uint64_t upper_limit = static_cast(eosio::chain::system_error_code::generic_system_error); @@ -579,16 +579,16 @@ ST& operator<<(ST& ds, const history_context_wrapper>(obj.obj.account_ram_deltas)); history_serialize_container(ds, obj.db, as_type>(obj.obj.account_disk_deltas)); - fc::optional e; + std::optional e; if (obj.obj.except) { if (debug_mode) e = obj.obj.except->to_string(); else e = "Y"; } - fc::raw::pack(ds, as_type>(e)); + fc::raw::pack(ds, as_type>(e)); fc::raw::pack(ds, - as_type>(debug_mode ? obj.obj.error_code : cap_error_code(obj.obj.error_code))); + as_type>(debug_mode ? obj.obj.error_code : cap_error_code(obj.obj.error_code))); fc::raw::pack(ds, as_type(obj.obj.return_value)); return ds; } @@ -626,15 +626,15 @@ ST& operator<<( ds, make_history_serial_wrapper(obj.db, as_type(*trace.account_ram_delta))); } - fc::optional e; + std::optional e; if (trace.except) { if (debug_mode) e = trace.except->to_string(); else e = "Y"; } - fc::raw::pack(ds, as_type>(e)); - fc::raw::pack(ds, as_type>(debug_mode ? trace.error_code : cap_error_code(trace.error_code))); + fc::raw::pack(ds, as_type>(e)); + fc::raw::pack(ds, as_type>(debug_mode ? trace.error_code : cap_error_code(trace.error_code))); fc::raw::pack(ds, bool(trace.failed_dtrx_trace)); if (trace.failed_dtrx_trace) { @@ -661,7 +661,7 @@ ST& operator<<( fc::raw::pack(ds, as_type(trx.max_cpu_usage_ms)); fc::raw::pack(ds, as_type(trx.delay_sec)); fc::raw::pack(ds, as_type(trx.transaction_extensions)); - fc::raw::pack(ds, as_type>({})); + fc::raw::pack(ds, as_type>({})); } return ds; diff --git a/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp b/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp index 54b0e0be988..45b5e870281 100644 --- a/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp +++ b/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp @@ -12,7 +12,7 @@ using chain::transaction_id_type; struct transaction_trace_cache { std::map cached_traces; - fc::optional onblock_trace; + std::optional onblock_trace; void add_transaction(const transaction_trace_ptr& trace, const packed_transaction_ptr& transaction); diff --git a/libraries/state_history/include/eosio/state_history/types.hpp b/libraries/state_history/include/eosio/state_history/types.hpp index febf55260b5..b45b9fe2500 100644 --- a/libraries/state_history/include/eosio/state_history/types.hpp +++ b/libraries/state_history/include/eosio/state_history/types.hpp @@ -105,11 +105,11 @@ struct get_blocks_ack_request_v0 { struct get_blocks_result_v0 { block_position head; block_position last_irreversible; - fc::optional this_block; - fc::optional prev_block; - fc::optional block; - fc::optional traces; - fc::optional deltas; + std::optional this_block; + std::optional prev_block; + std::optional block; + std::optional traces; + std::optional deltas; }; using state_request = fc::static_variant; @@ -151,21 +151,21 @@ struct action { struct action_trace_v0 { fc::unsigned_int action_ordinal = {}; fc::unsigned_int creator_action_ordinal = {}; - fc::optional receipt = {}; + std::optional receipt = {}; uint64_t receiver = {}; action act = {}; bool context_free = {}; int64_t elapsed = {}; std::string console = {}; std::vector account_ram_deltas = {}; - fc::optional except = {}; - fc::optional error_code = {}; + std::optional except = {}; + std::optional error_code = {}; }; struct action_trace_v1 { fc::unsigned_int action_ordinal = {}; fc::unsigned_int creator_action_ordinal = {}; - fc::optional receipt = {}; + std::optional receipt = {}; uint64_t receiver = {}; action act = {}; bool context_free = {}; @@ -173,8 +173,8 @@ struct action_trace_v1 { std::string console = {}; std::vector account_ram_deltas = {}; std::vector account_disk_deltas = {}; - fc::optional except = {}; - fc::optional error_code = {}; + std::optional except = {}; + std::optional error_code = {}; bytes return_value = {}; }; @@ -201,7 +201,7 @@ struct partial_transaction_v1 { uint8_t max_cpu_usage_ms = {}; fc::unsigned_int delay_sec = {}; std::vector transaction_extensions = {}; - fc::optional prunable_data = {}; + std::optional prunable_data = {}; }; using partial_transaction = fc::static_variant; @@ -218,14 +218,14 @@ struct transaction_trace_v0 { uint64_t net_usage = {}; bool scheduled = {}; std::vector action_traces = {}; - fc::optional account_ram_delta = {}; - fc::optional except = {}; - fc::optional error_code = {}; + std::optional account_ram_delta = {}; + std::optional except = {}; + std::optional error_code = {}; - // semantically, this should be optional; + // semantically, this should be std::optional; // it is represented as vector because optional cannot be used for incomplete type std::vector failed_dtrx_trace = {}; - fc::optional partial = {}; + std::optional partial = {}; }; using transaction_trace = fc::static_variant; @@ -238,9 +238,9 @@ using optional_signed_block = std::variant this_block; - fc::optional prev_block; - optional_signed_block block; // packed as fc::optional> + std::optional this_block; + std::optional prev_block; + optional_signed_block block; // packed as std::optional> opaque> traces; opaque> deltas; }; diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index e2e5ce1789d..8f8a8818f70 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -163,13 +163,13 @@ namespace eosio { namespace testing { void execute_setup_policy(const setup_policy policy); void close(); - void open( protocol_feature_set&& pfs, fc::optional expected_chain_id, const std::function& lambda ); + void open( protocol_feature_set&& pfs, std::optional expected_chain_id, const std::function& lambda ); void open( protocol_feature_set&& pfs, const snapshot_reader_ptr& snapshot ); void open( protocol_feature_set&& pfs, const genesis_state& genesis ); - void open( protocol_feature_set&& pfs, fc::optional expected_chain_id = {} ); + void open( protocol_feature_set&& pfs, std::optional expected_chain_id = {} ); void open( const snapshot_reader_ptr& snapshot ); void open( const genesis_state& genesis ); - void open( fc::optional expected_chain_id = {} ); + void open( std::optional expected_chain_id = {} ); bool is_same_chain( base_tester& other ); virtual signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) = 0; @@ -335,14 +335,14 @@ namespace eosio { namespace testing { static action_result wasm_assert_code( uint64_t error_code ) { return "assertion failure with error code: " + std::to_string(error_code); } auto get_resolver() { - return [this]( const account_name& name ) -> optional { + return [this]( const account_name& name ) -> std::optional { try { const auto& accnt = control->db().get( name ); abi_def abi; if( abi_serializer::to_abi( accnt.abi, abi )) { return abi_serializer( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) ); } - return optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS( error, "Failed to find or parse ABI for ${name}", ("name", name)) }; } diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index f26aa33d88e..e5f92b163db 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -110,14 +110,14 @@ namespace eosio { namespace testing { protocol_feature_set make_protocol_feature_set(const subjective_restriction_map& custom_subjective_restrictions) { protocol_feature_set pfs; - map< builtin_protocol_feature_t, optional > visited_builtins; + map< builtin_protocol_feature_t, std::optional > visited_builtins; std::function add_builtins = [&pfs, &visited_builtins, &add_builtins, &custom_subjective_restrictions] ( builtin_protocol_feature_t codename ) -> digest_type { - auto res = visited_builtins.emplace( codename, optional() ); + auto res = visited_builtins.emplace( codename, std::optional() ); if( !res.second ) { - EOS_ASSERT( res.first->second, protocol_feature_exception, + EOS_ASSERT( res.first->second.has_value(), protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies" ); return *res.first->second; @@ -194,7 +194,7 @@ namespace eosio { namespace testing { auto schedule_preactivate_protocol_feature = [&]() { auto preactivate_feature_digest = pfm.get_builtin_digest(builtin_protocol_feature_t::preactivate_feature); - FC_ASSERT( preactivate_feature_digest, "PREACTIVATE_FEATURE not found" ); + FC_ASSERT( preactivate_feature_digest.has_value(), "PREACTIVATE_FEATURE not found" ); schedule_protocol_features_wo_preactivation( { *preactivate_feature_digest } ); }; @@ -265,14 +265,14 @@ namespace eosio { namespace testing { open( make_protocol_feature_set(), genesis ); } - void base_tester::open( fc::optional expected_chain_id ) { + void base_tester::open( std::optional expected_chain_id ) { open( make_protocol_feature_set(), expected_chain_id ); } - void base_tester::open( protocol_feature_set&& pfs, fc::optional expected_chain_id, const std::function& lambda ) { - if( !expected_chain_id ) { + void base_tester::open( protocol_feature_set&& pfs, std::optional expected_chain_id, const std::function& lambda ) { + if( !expected_chain_id.has_value() ) { expected_chain_id = controller::extract_chain_id_from_db( cfg.state_dir ); - if( !expected_chain_id ) { + if( !expected_chain_id.has_value() ) { if( fc::is_regular_file( cfg.blog.log_dir / "blocks.log" ) ) { expected_chain_id = block_log::extract_chain_id( cfg.blog.log_dir ); } else { @@ -313,7 +313,7 @@ namespace eosio { namespace testing { }); } - void base_tester::open( protocol_feature_set&& pfs, fc::optional expected_chain_id ) { + void base_tester::open( protocol_feature_set&& pfs, std::optional expected_chain_id ) { open(std::move(pfs), expected_chain_id, [&control=this->control]() { control->startup( [](){}, []() { return false; } ); }); @@ -1168,7 +1168,7 @@ namespace eosio { namespace testing { [&pfm, &pfs, current_block_num, current_block_time, &preactivation_set, &preactivations, &add_digests] ( const digest_type& feature_digest ) { const auto& pf = pfs.get_protocol_feature( feature_digest ); - FC_ASSERT( pf.builtin_feature, "called add_digests on a non-builtin protocol feature" ); + FC_ASSERT( pf.builtin_feature.has_value(), "called add_digests on a non-builtin protocol feature" ); if( !pf.enabled || pf.earliest_allowed_activation_time > current_block_time || pfm.is_builtin_activated( *pf.builtin_feature, current_block_num ) ) return; @@ -1184,7 +1184,7 @@ namespace eosio { namespace testing { for( const auto& f : builtin_protocol_feature_codenames ) { auto digest = pfs.get_builtin_digest( f.first ); - if( !digest ) continue; + if( !digest.has_value() ) continue; add_digests( *digest ); } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 9f23453cca5..ca9f7391f9b 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -148,15 +148,14 @@ class chain_plugin_impl { bool accept_transactions = false; bool api_accept_transactions = true; - - fc::optional fork_db; - fc::optional chain_config; - fc::optional chain; - fc::optional genesis; + std::optional fork_db; + std::optional chain_config; + std::optional chain; + std::optional genesis; //txn_msg_rate_limits rate_limits; - fc::optional wasm_runtime; + std::optional wasm_runtime; fc::microseconds abi_serializer_max_time_us; - fc::optional snapshot_path; + std::optional snapshot_path; // retained references to channels for easy publication @@ -179,12 +178,12 @@ class chain_plugin_impl { methods::get_last_irreversible_block_number::method_type::handle get_last_irreversible_block_number_provider; // scoped connections for chain controller - fc::optional pre_accepted_block_connection; - fc::optional accepted_block_header_connection; - fc::optional accepted_block_connection; - fc::optional irreversible_block_connection; - fc::optional accepted_transaction_connection; - fc::optional applied_transaction_connection; + std::optional pre_accepted_block_connection; + std::optional accepted_block_header_connection; + std::optional accepted_block_connection; + std::optional irreversible_block_connection; + std::optional accepted_transaction_connection; + std::optional applied_transaction_connection; }; @@ -428,7 +427,7 @@ void clear_chainbase_files( const fc::path& p ) { fc::remove( p / "shared_memory.meta" ); } -optional read_builtin_protocol_feature( const fc::path& p ) { +std::optional read_builtin_protocol_feature( const fc::path& p ) { try { return fc::json::from_file( p ); } catch( const fc::exception& e ) { @@ -500,7 +499,7 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul map found_builtin_protocol_features; map > builtin_protocol_features_to_add; // The bool in the pair is set to true if the builtin protocol feature has already been visited to add - map< builtin_protocol_feature_t, optional > visited_builtins; + map< builtin_protocol_feature_t, std::optional > visited_builtins; // Read all builtin protocol features if( directory_exists ) { @@ -511,7 +510,7 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul auto f = read_builtin_protocol_feature( file_path ); - if( !f ) continue; + if( !f.has_value() ) continue; auto res = found_builtin_protocol_features.emplace( f->get_codename(), file_path ); @@ -590,9 +589,9 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul std::function add_missing_builtins = [&pfs, &visited_builtins, &output_protocol_feature, &log_recognized_protocol_feature, &add_missing_builtins, populate_missing_builtins] ( builtin_protocol_feature_t codename ) -> digest_type { - auto res = visited_builtins.emplace( codename, optional() ); + auto res = visited_builtins.emplace( codename, std::optional() ); if( !res.second ) { - EOS_ASSERT( res.first->second, protocol_feature_exception, + EOS_ASSERT( res.first->second.has_value(), protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies" ); return *res.first->second; @@ -817,11 +816,11 @@ void chain_plugin::plugin_initialize(const variables_map& options) { my->chain_config->terminate_at_block = options.at( "terminate-at-block" ).as(); if( options.count( "extract-genesis-json" ) || options.at( "print-genesis-json" ).as()) { - fc::optional gs; + std::optional gs; if( fc::exists( my->blocks_dir / "blocks.log" )) { gs = block_log::extract_genesis_state( my->blocks_dir ); - EOS_ASSERT( gs, + EOS_ASSERT( gs.has_value(), plugin_config_exception, "Block log at '${path}' does not contain a genesis state, it only has the chain-id.", ("path", (my->blocks_dir / "blocks.log").generic_string()) @@ -892,7 +891,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { } else if( options.at( "fix-reversible-blocks" ).as()) { if( !recover_reversible_blocks( my->chain_config->blog.log_dir / config::reversible_blocks_dir_name, my->chain_config->reversible_cache_size, - optional(), + std::optional(), options.at( "truncate-at-block" ).as())) { ilog( "Reversible blocks database verified to not be corrupted. Now exiting..." ); } else { @@ -916,7 +915,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { wlog("The --import-reversible-blocks option should be used by itself."); } - fc::optional chain_id; + std::optional chain_id; if (options.count( "snapshot" )) { my->snapshot_path = options.at( "snapshot" ).as(); EOS_ASSERT( fc::exists(*my->snapshot_path), plugin_config_exception, @@ -967,8 +966,8 @@ void chain_plugin::plugin_initialize(const variables_map& options) { chain_id = controller::extract_chain_id_from_db( my->chain_config->state_dir ); - fc::optional block_log_genesis; - fc::optional block_log_chain_id; + std::optional block_log_genesis; + std::optional block_log_chain_id; if( fc::is_regular_file( my->blocks_dir / "blocks.log" ) ) { block_log_genesis = block_log::extract_genesis_state( my->blocks_dir ); @@ -1053,14 +1052,14 @@ void chain_plugin::plugin_initialize(const variables_map& options) { "--genesis-timestamp is only valid if also passed in with --genesis-json"); } - if( !chain_id ) { + if( !chain_id.has_value() ) { if( my->genesis ) { // Uninitialized state database and genesis state extracted from block log chain_id = my->genesis->compute_chain_id(); } else { // Uninitialized state database and no genesis state provided - EOS_ASSERT( !block_log_chain_id, plugin_config_exception, + EOS_ASSERT( !block_log_chain_id.has_value(), plugin_config_exception, "Genesis state is necessary to initialize fresh blockchain state but genesis state could not be " "found in the blocks log. Please either load from snapshot or find a blocks log that starts " "from genesis." @@ -1296,7 +1295,7 @@ void chain_plugin::accept_transaction(const chain::packed_transaction_ptr& trx, } bool chain_plugin::recover_reversible_blocks( const fc::path& db_dir, uint32_t cache_size, - optional new_db_dir, uint32_t truncate_at_block ) { + std::optional new_db_dir, uint32_t truncate_at_block ) { try { chainbase::database reversible( db_dir, database::read_only); // Test if dirty // If it reaches here, then the reversible database is not dirty @@ -1345,7 +1344,7 @@ bool chain_plugin::recover_reversible_blocks( const fc::path& db_dir, uint32_t c ilog( "Reconstructing '${reversible_dir}' from backed up reversible directory", ("reversible_dir", reversible_dir) ); - optional old_reversible; + std::optional old_reversible; try { old_reversible = chainbase::database( backup_dir, database::read_only, 0, true ); @@ -1939,7 +1938,7 @@ vector read_only::get_currency_balance( const read_only::get_currency_bal EOS_ASSERT( cursor.get_symbol().valid(), chain::asset_type_exception, "Invalid asset"); - if( !p.symbol || boost::iequals(cursor.symbol_name(), *p.symbol) ) { + if( !p.symbol.has_value() || boost::iequals(cursor.symbol_name(), *p.symbol) ) { results.emplace_back(cursor); } @@ -2078,7 +2077,7 @@ read_only::get_producer_schedule_result read_only::get_producer_schedule( const template struct resolver_factory { static auto make(const Api* api, abi_serializer::yield_function_t yield) { - return [api, yield{std::move(yield)}](const account_name &name) -> optional { + return [api, yield{std::move(yield)}](const account_name &name) -> std::optional { const auto* accnt = api->db.db().template find(name); if (accnt != nullptr) { abi_def abi; @@ -2087,7 +2086,7 @@ struct resolver_factory { } } - return optional(); + return std::optional(); }; } }; @@ -2173,7 +2172,7 @@ read_only::get_scheduled_transactions( const read_only::get_scheduled_transactio fc::variant read_only::get_block(const read_only::get_block_params& params) const { signed_block_ptr block; - optional block_num; + std::optional block_num; EOS_ASSERT( !params.block_num_or_id.empty() && params.block_num_or_id.size() <= 64, chain::block_id_type_exception, @@ -2184,7 +2183,7 @@ fc::variant read_only::get_block(const read_only::get_block_params& params) cons block_num = fc::to_uint64(params.block_num_or_id); } catch( ... ) {} - if( block_num.valid() ) { + if( block_num.has_value() ) { block = db.fetch_block_by_number( *block_num ); } else { try { @@ -2239,13 +2238,13 @@ fc::variant read_only::get_block_info(const read_only::get_block_info_params& pa fc::variant read_only::get_block_header_state(const get_block_header_state_params& params) const { block_state_ptr b; - optional block_num; + std::optional block_num; std::exception_ptr e; try { block_num = fc::to_uint64(params.block_num_or_id); } catch( ... ) {} - if( block_num.valid() ) { + if( block_num.has_value() ) { b = db.fetch_block_state_by_number(*block_num); } else { try { @@ -2504,7 +2503,7 @@ read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params& result.abi_hash = fc::sha256::hash( accnt_obj.abi.data(), accnt_obj.abi.size() ); if( accnt_metadata_obj.code_hash != digest_type() ) result.code_hash = accnt_metadata_obj.code_hash; - if( !params.abi_hash || *params.abi_hash != result.abi_hash ) + if( !params.abi_hash.has_value() || *params.abi_hash != result.abi_hash ) result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}}; return result; @@ -2532,11 +2531,11 @@ read_only::get_account_results read_only::get_account( const get_account_params& uint32_t greylist_limit = db.is_resource_greylisted(result.account_name) ? 1 : config::maximum_elastic_resource_multiplier; const block_timestamp_type current_usage_time (db.head_block_time()); result.net_limit.set( rm.get_account_net_limit_ex( result.account_name, greylist_limit, current_usage_time).first ); - if ( result.net_limit.last_usage_update_time.valid() && (result.net_limit.last_usage_update_time->slot == 0) ) { // account has no action yet + if ( result.net_limit.last_usage_update_time.has_value() && (result.net_limit.last_usage_update_time->slot == 0) ) { // account has no action yet result.net_limit.last_usage_update_time = accnt_obj.creation_date; } result.cpu_limit.set( rm.get_account_cpu_limit_ex( result.account_name, greylist_limit, current_usage_time).first ); - if ( result.cpu_limit.last_usage_update_time.valid() && (result.cpu_limit.last_usage_update_time->slot == 0) ) { // account has no action yet + if ( result.cpu_limit.last_usage_update_time.has_value() && (result.cpu_limit.last_usage_update_time->slot == 0) ) { // account has no action yet result.cpu_limit.last_usage_update_time = accnt_obj.creation_date; } result.ram_usage = rm.get_account_ram_usage( result.account_name ); @@ -2570,7 +2569,7 @@ read_only::get_account_results read_only::get_account( const get_account_params& auto core_symbol = extract_core_symbol(); - if (params.expected_core_symbol.valid()) + if (params.expected_core_symbol.has_value()) core_symbol = *(params.expected_core_symbol); const auto* t_id = d.find(boost::make_tuple( token_code, params.account_name, N(accounts) )); diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 3cd158f5aa3..b9bc6d9913e 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -30,7 +30,6 @@ namespace eosio { using chain::public_key_type; using chain::transaction; using chain::transaction_id_type; - using fc::optional; using boost::container::flat_set; using chain::asset; using chain::symbol; @@ -110,16 +109,16 @@ class read_only { uint64_t block_net_limit = 0; //string recent_slots; //double participation_rate = 0; - optional server_version_string; - optional fork_db_head_block_num; - optional fork_db_head_block_id; - optional server_full_version_string; + std::optional server_version_string; + std::optional fork_db_head_block_num; + std::optional fork_db_head_block_id; + std::optional server_full_version_string; }; get_info_results get_info(const get_info_params&) const; struct get_activated_protocol_features_params { - optional lower_bound; - optional upper_bound; + std::optional lower_bound; + std::optional upper_bound; uint32_t limit = 10; bool search_by_block_num = false; bool reverse = false; @@ -127,7 +126,7 @@ class read_only { struct get_activated_protocol_features_results { fc::variants activated_protocol_features; - optional more; + std::optional more; }; get_activated_protocol_features_results get_activated_protocol_features( const get_activated_protocol_features_params& params )const; @@ -141,8 +140,8 @@ class read_only { int64_t used = 0; int64_t available = 0; int64_t max = 0; - optional last_usage_update_time; // optional for backward nodeos support - optional current_used; // optional for backward nodeos support + std::optional last_usage_update_time; // optional for backward nodeos support + std::optional current_used; // optional for backward nodeos support void set( const chain::resource_limits::account_resource_limit& arl) { used = arl.used; @@ -162,7 +161,7 @@ class read_only { fc::time_point last_code_update; fc::time_point created; - optional core_liquid_balance; + std::optional core_liquid_balance; int64_t ram_quota = 0; int64_t net_weight = 0; @@ -183,7 +182,7 @@ class read_only { struct get_account_params { name account_name; - optional expected_core_symbol; + std::optional expected_core_symbol; }; get_account_results get_account( const get_account_params& params )const; @@ -193,7 +192,7 @@ class read_only { string wast; string wasm; fc::sha256 code_hash; - optional abi; + std::optional abi; }; struct get_code_params { @@ -212,7 +211,7 @@ class read_only { struct get_abi_results { name account_name; - optional abi; + std::optional abi; }; struct get_abi_params { @@ -231,14 +230,14 @@ class read_only { struct get_raw_abi_params { name account_name; - optional abi_hash; + std::optional abi_hash; }; struct get_raw_abi_results { name account_name; fc::sha256 code_hash; fc::sha256 abi_hash; - optional abi; + std::optional abi; }; @@ -319,8 +318,8 @@ class read_only { string key_type; // type of key specified by index_position string index_position; // 1 - primary (first), 2 - secondary index (in order defined by multi_index), 3 - third index, etc string encode_type{"dec"}; //dec, hex , default=dec - optional reverse; - optional show_payer; // show RAM pyer + std::optional reverse; + std::optional show_payer; // show RAM pyer }; struct get_table_rows_result { @@ -337,7 +336,7 @@ class read_only { string lower_bound; // lower bound of scope, optional string upper_bound; // upper bound of scope, optional uint32_t limit = 10; - optional reverse; + std::optional reverse; }; struct get_table_by_scope_result_row { name code; @@ -356,7 +355,7 @@ class read_only { struct get_currency_balance_params { name code; name account; - optional symbol; + std::optional symbol; }; vector get_currency_balance( const get_currency_balance_params& params )const; @@ -734,7 +733,7 @@ class chain_plugin : public plugin { static bool recover_reversible_blocks( const fc::path& db_dir, uint32_t cache_size, - optional new_db_dir = optional(), + std::optional new_db_dir = std::optional(), uint32_t truncate_at_block = 0 ); diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 540aba79917..356d9ac6983 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -141,7 +141,7 @@ namespace eosio { std::set filter_on; std::set filter_out; chain_plugin* chain_plug = nullptr; - fc::optional applied_transaction_connection; + std::optional applied_transaction_connection; bool filter(const action_trace& act) { bool pass_on = false; @@ -278,11 +278,11 @@ namespace eosio { } void on_applied_transaction( const transaction_trace_ptr& trace ) { - if( !trace->receipt || (trace->receipt->status != transaction_receipt_header::executed && + if( !trace->receipt.has_value() || (trace->receipt->status != transaction_receipt_header::executed && trace->receipt->status != transaction_receipt_header::soft_fail) ) return; for( const auto& atrace : trace->action_traces ) { - if( !atrace.receipt ) continue; + if( !atrace.receipt.has_value() ) continue; on_action_trace( atrace ); } } @@ -468,7 +468,7 @@ namespace eosio { bool in_history = (itr != idx.end() && txn_id_matched(itr->trx_id) ); - if( !in_history && !p.block_num_hint ) { + if( !in_history && !p.block_num_hint.has_value() ) { EOS_THROW(tx_not_found, "Transaction ${id} not found in history and no block hint was given", ("id",p.id)); } diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index 0bbeda361be..6a1472e46e1 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -10,7 +10,6 @@ namespace eosio { using std::shared_ptr; using namespace appbase; using chain::name; - using fc::optional; using chain::uint128_t; typedef shared_ptr history_ptr; @@ -28,8 +27,8 @@ class read_only { struct get_actions_params { chain::account_name account_name; - optional pos; /// a absolute sequence positon -1 is the end/last action - optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) + std::optional pos; /// a absolute sequence positon -1 is the end/last action + std::optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) }; struct ordered_action_result { @@ -43,7 +42,7 @@ class read_only { struct get_actions_result { vector actions; uint32_t last_irreversible_block; - optional time_limit_exceeded_error; + std::optional time_limit_exceeded_error; }; @@ -52,7 +51,7 @@ class read_only { struct get_transaction_params { string id; - optional block_num_hint; + std::optional block_num_hint; }; struct get_transaction_result { diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index b0272fce406..bda9977692b 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -183,7 +183,7 @@ namespace eosio { public: // key -> priority, url_handler map url_handlers; - optional listen_endpoint; + std::optional listen_endpoint; string access_control_allow_origin; string access_control_allow_headers; string access_control_max_age; @@ -193,12 +193,12 @@ namespace eosio { websocket_server_type server; uint16_t thread_pool_size = 2; - optional thread_pool; + std::optional thread_pool; std::atomic bytes_in_flight{0}; size_t max_bytes_in_flight = 0; fc::microseconds max_response_time{30*1000}; - optional https_listen_endpoint; + std::optional https_listen_endpoint; string https_cert_chain; string https_key; https_ecdh_curve_t https_ecdh_curve = SECP384R1; @@ -206,7 +206,7 @@ namespace eosio { websocket_server_tls_type https_server; #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS - optional unix_endpoint; + std::optional unix_endpoint; websocket_local_server_type unix_server; #endif diff --git a/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp b/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp index b7b3516e18f..ee8823ddfa8 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp @@ -29,7 +29,7 @@ namespace eosio { string connect( const string& endpoint ); string disconnect( const string& endpoint ); - optional status( const string& endpoint )const; + std::optional status( const string& endpoint )const; vector connections()const; private: diff --git a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp index 85e1420aa50..ac06b276cfa 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp @@ -136,7 +136,7 @@ namespace eosio { }; struct trx_message_v1 { - fc::optional trx_id; // only provided for large trx as trade-off for small trxs not worth it + std::optional trx_id; // only provided for large trx as trade-off for small trxs not worth it std::shared_ptr trx; }; diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 58fc3fa0d8f..a01be768edc 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -270,7 +270,7 @@ namespace eosio { compat::channels::transaction_ack::channel_type::handle incoming_transaction_ack_subscription; uint16_t thread_pool_size = 2; - optional thread_pool; + std::optional thread_pool; private: mutable std::mutex chain_info_mtx; // protects chain_* @@ -551,7 +551,7 @@ namespace eosio { void update_endpoints(); - optional peer_requested; // this peer is requesting info from us + std::optional peer_requested; // this peer is requesting info from us std::atomic socket_open{false}; @@ -588,7 +588,7 @@ namespace eosio { std::atomic no_retry{no_reason}; mutable std::mutex conn_mtx; //< mtx for last_req .. local_endpoint_port - optional last_req; + std::optional last_req; handshake_message last_handshake_recv; handshake_message last_handshake_sent; block_id_type fork_head; @@ -935,7 +935,7 @@ namespace eosio { bool has_last_req = false; { std::lock_guard g_conn( self->conn_mtx ); - has_last_req = !!self->last_req; + has_last_req = self->last_req.has_value(); self->last_handshake_recv = handshake_message(); self->last_handshake_sent = handshake_message(); self->last_close = fc::time_point::now(); @@ -1013,7 +1013,7 @@ namespace eosio { } void connection::blk_send_branch_impl( uint32_t msg_head_num, uint32_t lib_num, uint32_t head_num ) { - if( !peer_requested ) { + if( !peer_requested.has_value() ) { auto last = msg_head_num != 0 ? msg_head_num : lib_num; peer_requested = peer_sync_state( last+1, head_num, last ); } else { @@ -1174,7 +1174,7 @@ namespace eosio { } bool connection::enqueue_sync_block() { - if( !peer_requested ) { + if( !peer_requested.has_value() ) { return false; } else { fc_dlog( logger, "enqueue sync block ${num}", ("num", peer_requested->last + 1) ); @@ -1277,7 +1277,7 @@ namespace eosio { } else { if( !send_buffer_v0 ) { const auto v0 = sb->to_signed_block_v0(); - if( !v0 ) return send_buffer_v0; + if( !v0.has_value() ) return send_buffer_v0; send_buffer_v0 = create_send_buffer( *v0 ); } return send_buffer_v0; @@ -1333,7 +1333,7 @@ namespace eosio { static std::shared_ptr> create_send_buffer( const packed_transaction_ptr& trx ) { static_assert( trx_message_v1_which == net_message::position() ); - fc::optional trx_id; + std::optional trx_id; if( trx->get_estimated_size() > 1024 ) { // simple guess on threshold fc_dlog( logger, "including trx id, est size: ${es}", ("es", trx->get_estimated_size()) ); trx_id = trx->id(); @@ -2184,7 +2184,7 @@ namespace eosio { block_id_type bid; { std::lock_guard g_c_conn( c->conn_mtx ); - if( !c->last_req ) { + if( !c->last_req.has_value() ) { return; } fc_wlog( logger, "failed to fetch from ${p}", ("p", c->peer_address()) ); @@ -2631,7 +2631,7 @@ namespace eosio { unsigned_int which{}; fc::raw::unpack( ds, which ); if( which == trx_message_v1_which ) { - fc::optional trx_id; + std::optional trx_id; fc::raw::unpack( ds, trx_id ); if( trx_id ) { if (trx_in_progress_sz > def_max_trx_in_progress_size) { @@ -2648,19 +2648,18 @@ namespace eosio { std::shared_ptr trx; fc::raw::unpack( ds, trx ); ptr = std::move( trx ); - - if (ptr && trx_id && *trx_id != ptr->id()) { + + if (ptr && trx_id.has_value() && *trx_id != ptr->id()) { my_impl->producer_plug->log_failed_transaction(*trx_id, "Provided trx_id does not match provided packed_transaction"); EOS_ASSERT(false, transaction_id_type_exception, "Provided trx_id does not match provided packed_transaction" ); } - if( !trx_id ) { + if( !trx_id.has_value() ) { if (trx_in_progress_sz > def_max_trx_in_progress_size) { report_dropping_trx(ptr->id(), trx_in_progress_sz); return true; } - have_trx = my_impl->dispatcher->have_txn( ptr->id() ); } node_transaction_state nts = {ptr->id(), ptr->expiration(), 0, connection_id}; @@ -3069,7 +3068,7 @@ namespace eosio { fc_dlog( logger, "bad packed_transaction : ${m}", ("m", result.get()->what()) ); } else { const transaction_trace_ptr& trace = result.get(); - if( !trace->except ) { + if( !trace->except.has_value() ) { fc_dlog( logger, "chain accepted transaction, bcast ${id}", ("id", trace->id) ); } else { fc_elog( logger, "bad packed_transaction : ${m}", ("m", trace->except->what())); @@ -3785,12 +3784,12 @@ namespace eosio { return "no known connection for host"; } - optional net_plugin::status( const string& host )const { + std::optional net_plugin::status( const string& host )const { std::shared_lock g( my->connections_mtx ); auto con = my->find_connection( host ); if( con ) return con->get_status(); - return optional(); + return std::optional(); } vector net_plugin::connections()const { diff --git a/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp b/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp index 740eabae446..e58f4caaa12 100644 --- a/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp +++ b/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp @@ -14,23 +14,23 @@ class producer_plugin : public appbase::plugin { APPBASE_PLUGIN_REQUIRES((chain_plugin)(signature_provider_plugin)) struct runtime_options { - fc::optional max_transaction_time; - fc::optional max_irreversible_block_age; - fc::optional produce_time_offset_us; - fc::optional last_block_time_offset_us; - fc::optional max_scheduled_transaction_time_per_block_ms; - fc::optional subjective_cpu_leeway_us; - fc::optional incoming_defer_ratio; - fc::optional greylist_limit; + std::optional max_transaction_time; + std::optional max_irreversible_block_age; + std::optional produce_time_offset_us; + std::optional last_block_time_offset_us; + std::optional max_scheduled_transaction_time_per_block_ms; + std::optional subjective_cpu_leeway_us; + std::optional incoming_defer_ratio; + std::optional greylist_limit; }; struct whitelist_blacklist { - fc::optional< flat_set > actor_whitelist; - fc::optional< flat_set > actor_blacklist; - fc::optional< flat_set > contract_whitelist; - fc::optional< flat_set > contract_blacklist; - fc::optional< flat_set< std::pair > > action_blacklist; - fc::optional< flat_set > key_blacklist; + std::optional< flat_set > actor_whitelist; + std::optional< flat_set > actor_blacklist; + std::optional< flat_set > contract_whitelist; + std::optional< flat_set > contract_blacklist; + std::optional< flat_set< std::pair > > action_blacklist; + std::optional< flat_set > key_blacklist; }; struct greylist_params { @@ -57,15 +57,15 @@ class producer_plugin : public appbase::plugin { }; struct get_account_ram_corrections_params { - optional lower_bound; - optional upper_bound; + std::optional lower_bound; + std::optional upper_bound; uint32_t limit = 10; bool reverse = false; }; struct get_account_ram_corrections_result { std::vector rows; - optional more; + std::optional more; }; template diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 52528e94437..85db02c0b39 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -180,7 +180,7 @@ class producer_plugin_impl : public std::enable_shared_from_this calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const; + std::optional calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const; void schedule_production_loop(); void schedule_maybe_produce_block( bool exhausted ); void produce_block(); @@ -204,7 +204,7 @@ class producer_plugin_impl : public std::enable_shared_from_this _producer_watermarks; pending_block_mode _pending_block_mode = pending_block_mode::speculating; unapplied_transaction_queue _unapplied_transactions; - fc::optional _thread_pool; + std::optional _thread_pool; std::atomic _max_transaction_time_ms; // modified by app thread, read by net_plugin thread pool fc::microseconds _max_irreversible_block_age_us; @@ -231,9 +231,9 @@ class producer_plugin_impl : public std::enable_shared_from_this _accepted_block_connection; - fc::optional _accepted_block_header_connection; - fc::optional _irreversible_block_connection; + std::optional _accepted_block_connection; + std::optional _accepted_block_header_connection; + std::optional _irreversible_block_connection; /* * HACK ALERT @@ -585,8 +585,8 @@ class producer_plugin_impl : public std::enable_shared_from_this& weak_this, optional wake_up_time); - optional calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const; + void schedule_delayed_production_loop(const std::weak_ptr& weak_this, std::optional wake_up_time); + std::optional calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const; }; @@ -1011,7 +1011,7 @@ producer_plugin::runtime_options producer_plugin::get_runtime_options() const { my->_max_scheduled_transaction_time_per_block_ms, my->chain_plug->chain().get_subjective_cpu_leeway() ? my->chain_plug->chain().get_subjective_cpu_leeway()->count() : - fc::optional(), + std::optional(), my->_incoming_defer_ratio, my->chain_plug->chain().get_greylist_limit() }; @@ -1056,12 +1056,12 @@ producer_plugin::whitelist_blacklist producer_plugin::get_whitelist_blacklist() void producer_plugin::set_whitelist_blacklist(const producer_plugin::whitelist_blacklist& params) { chain::controller& chain = my->chain_plug->chain(); - if(params.actor_whitelist.valid()) chain.set_actor_whitelist(*params.actor_whitelist); - if(params.actor_blacklist.valid()) chain.set_actor_blacklist(*params.actor_blacklist); - if(params.contract_whitelist.valid()) chain.set_contract_whitelist(*params.contract_whitelist); - if(params.contract_blacklist.valid()) chain.set_contract_blacklist(*params.contract_blacklist); - if(params.action_blacklist.valid()) chain.set_action_blacklist(*params.action_blacklist); - if(params.key_blacklist.valid()) chain.set_key_blacklist(*params.key_blacklist); + if(params.actor_whitelist.has_value()) chain.set_actor_whitelist(*params.actor_whitelist); + if(params.actor_blacklist.has_value()) chain.set_actor_blacklist(*params.actor_blacklist); + if(params.contract_whitelist.has_value()) chain.set_contract_whitelist(*params.contract_whitelist); + if(params.contract_blacklist.has_value()) chain.set_contract_blacklist(*params.contract_blacklist); + if(params.action_blacklist.has_value()) chain.set_action_blacklist(*params.action_blacklist); + if(params.key_blacklist.has_value()) chain.set_key_blacklist(*params.key_blacklist); } producer_plugin::integrity_hash_information producer_plugin::get_integrity_hash() const { @@ -1273,7 +1273,7 @@ producer_plugin::get_account_ram_corrections( const get_account_ram_corrections_ return result; } -optional producer_plugin_impl::calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const { +std::optional producer_plugin_impl::calculate_next_block_time(const account_name& producer_name, const block_timestamp_type& current_block_time) const { chain::controller& chain = chain_plug->chain(); const auto& hbs = chain.head_block_state(); const auto& active_schedule = hbs->active_schedule.producers; @@ -1282,7 +1282,7 @@ optional producer_plugin_impl::calculate_next_block_time(const a auto itr = std::find_if(active_schedule.begin(), active_schedule.end(), [&](const auto& asp){ return asp.producer_name == producer_name; }); if (itr == active_schedule.end()) { // this producer is not in the active producer set - return optional(); + return std::optional(); } size_t producer_index = itr - active_schedule.begin(); @@ -1925,9 +1925,9 @@ void producer_plugin_impl::schedule_maybe_produce_block( bool exhausted ) { } ) ); } -optional producer_plugin_impl::calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const { +std::optional producer_plugin_impl::calculate_producer_wake_up_time( const block_timestamp_type& ref_block_time ) const { // if we have any producers then we should at least set a timer for our next available slot - optional wake_up_time; + std::optional wake_up_time; for (const auto& p : _producers) { auto next_producer_block_time = calculate_next_block_time(p, ref_block_time); if (next_producer_block_time) { @@ -1942,14 +1942,14 @@ optional producer_plugin_impl::calculate_producer_wake_up_time( } } } - if( !wake_up_time ) { + if( !wake_up_time.has_value() ) { fc_dlog(_log, "Not Scheduling Speculative/Production, no local producers had valid wake up times"); } return wake_up_time; } -void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr& weak_this, optional wake_up_time) { +void producer_plugin_impl::schedule_delayed_production_loop(const std::weak_ptr& weak_this, std::optional wake_up_time) { if (wake_up_time) { fc_dlog(_log, "Scheduling Speculative/Production Change at ${time}", ("time", wake_up_time)); static const boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); @@ -1988,7 +1988,7 @@ static auto make_debug_time_logger() { }); } -static auto maybe_make_debug_time_logger() -> fc::optional { +static auto maybe_make_debug_time_logger() -> std::optional { if (_log.is_enabled( fc::log_level::debug ) ){ return make_debug_time_logger(); } else { diff --git a/plugins/signature_provider_plugin/signature_provider_plugin.cpp b/plugins/signature_provider_plugin/signature_provider_plugin.cpp index de39d4d5bb5..7dfa3dab647 100644 --- a/plugins/signature_provider_plugin/signature_provider_plugin.cpp +++ b/plugins/signature_provider_plugin/signature_provider_plugin.cpp @@ -47,7 +47,7 @@ class signature_provider_plugin_impl { if(boost::algorithm::starts_with(url_str, "unix://")) //send the entire string after unix:// to http_plugin. It'll auto-detect which part // is the unix socket path, and which part is the url to hit on the server - keosd_url = fc::url("unix", url_str.substr(7), fc::ostring(), fc::ostring(), fc::ostring(), fc::ostring(), fc::ovariant_object(), fc::optional()); + keosd_url = fc::url("unix", url_str.substr(7), fc::ostring(), fc::ostring(), fc::ostring(), fc::ostring(), fc::ovariant_object(), std::optional()); else keosd_url = fc::url(url_str); diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index 9253a19a920..17a47179f41 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -42,12 +42,12 @@ auto catch_and_log(F f) { struct state_history_plugin_impl : std::enable_shared_from_this { chain_plugin* chain_plug = nullptr; - fc::optional trace_log; - fc::optional chain_state_log; + std::optional trace_log; + std::optional chain_state_log; bool stopping = false; - fc::optional applied_transaction_connection; - fc::optional block_start_connection; - fc::optional accepted_block_connection; + std::optional applied_transaction_connection; + std::optional block_start_connection; + std::optional accepted_block_connection; string endpoint_address = "0.0.0.0"; uint16_t endpoint_port = 8080; std::unique_ptr acceptor; @@ -85,7 +85,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this> send_queue; - fc::optional current_request; + std::optional current_request; bool need_to_send_update = false; session(std::shared_ptr plugin) @@ -178,7 +178,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thisget_block_id(cp.block_num); - if (!id || *id != cp.block_id) + if (!id.has_value() || *id != cp.block_id) req.start_block_num = std::min(req.start_block_num, cp.block_num); if (!id) { @@ -195,7 +195,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) + if (!send_queue.empty() || !current_request.has_value() || !current_request->max_messages_in_flight) return; auto& chain = plugin->chain_plug->chain(); result.last_irreversible = {chain.last_irreversible_block_num(), chain.last_irreversible_block_id()}; @@ -241,7 +241,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) + if (!send_queue.empty() || !current_request.has_value() || !current_request->max_messages_in_flight) return; get_blocks_result_v1 result; result.head = {block_state->block_num, block_state->id}; @@ -251,7 +251,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) return; auto& chain = plugin->chain_plug->chain(); diff --git a/plugins/test_control_plugin/test_control_plugin.cpp b/plugins/test_control_plugin/test_control_plugin.cpp index 3ec82e722b9..b922971380a 100644 --- a/plugins/test_control_plugin/test_control_plugin.cpp +++ b/plugins/test_control_plugin/test_control_plugin.cpp @@ -1,5 +1,4 @@ #include -#include #include namespace fc { class variant; } @@ -21,8 +20,8 @@ class test_control_plugin_impl { void applied_irreversible_block(const chain::block_state_ptr& bsp); void process_next_block_state(const chain::block_state_ptr& bsp); - fc::optional _accepted_block_connection; - fc::optional _irreversible_block_connection; + std::optional _accepted_block_connection; + std::optional _irreversible_block_connection; chain::controller& _chain; account_name _producer; int32_t _where_in_sequence; diff --git a/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp b/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp index 02da39fccc6..74b7124ceae 100644 --- a/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp +++ b/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp @@ -120,7 +120,7 @@ class chain_extraction_impl_type { StoreProvider store; exception_handler except_handler; std::map cached_traces; - fc::optional onblock_trace; + std::optional onblock_trace; }; diff --git a/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp b/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp index 3e66b2c82bf..fc1319b8c64 100644 --- a/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp +++ b/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp @@ -37,7 +37,7 @@ namespace eosio::trace_api { */ fc::variant get_block_trace( uint32_t block_height, const yield_function& yield = {}) { auto data = logfile_provider.get_block(block_height, yield); - if (!data) { + if (!data.has_value()) { return {}; } diff --git a/plugins/trace_api_plugin/store_provider.cpp b/plugins/trace_api_plugin/store_provider.cpp index a540db24dd7..29f494df954 100644 --- a/plugins/trace_api_plugin/store_provider.cpp +++ b/plugins/trace_api_plugin/store_provider.cpp @@ -77,7 +77,7 @@ namespace eosio::trace_api { return get_block_t{}; } std::optional entry = read_data_log(block_height, *trace_offset); - if (!entry) { + if (!entry.has_value()) { return get_block_t{}; } return std::make_tuple( entry.value(), irreversible ); diff --git a/plugins/trace_api_plugin/test/test_trace_file.cpp b/plugins/trace_api_plugin/test/test_trace_file.cpp index c1f6fee077a..826945cb177 100644 --- a/plugins/trace_api_plugin/test/test_trace_file.cpp +++ b/plugins/trace_api_plugin/test/test_trace_file.cpp @@ -765,11 +765,11 @@ BOOST_AUTO_TEST_SUITE(slice_tests) BOOST_REQUIRE(first_offset < offset); std::optional bt_data = sp.read_data_log(block_nums[0], block_offsets[0]); - BOOST_REQUIRE(bt_data); + BOOST_REQUIRE(bt_data.has_value()); BOOST_REQUIRE_EQUAL(*bt_data, bt); bt_data = sp.read_data_log(block_nums[1], block_offsets[1]); - BOOST_REQUIRE(bt_data); + BOOST_REQUIRE(bt_data.has_value()); BOOST_REQUIRE_EQUAL(*bt_data, bt2); block_nums.clear(); @@ -817,7 +817,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(block1); + BOOST_REQUIRE(block1.has_value()); BOOST_REQUIRE(std::get<1>(*block1)); const auto block1_bt = std::get<0>(*block1); BOOST_REQUIRE_EQUAL(block1_bt, bt); @@ -828,7 +828,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(block2); + BOOST_REQUIRE(block2.has_value()); BOOST_REQUIRE(!std::get<1>(*block2)); const auto block2_bt = std::get<0>(*block2); BOOST_REQUIRE_EQUAL(block2_bt, bt2); @@ -850,7 +850,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(!block2); + BOOST_REQUIRE(!block2.has_value()); } BOOST_AUTO_TEST_SUITE_END() diff --git a/plugins/trace_api_plugin/trace_api_plugin.cpp b/plugins/trace_api_plugin/trace_api_plugin.cpp index 0fffa1d5eec..af284b5129e 100644 --- a/plugins/trace_api_plugin/trace_api_plugin.cpp +++ b/plugins/trace_api_plugin/trace_api_plugin.cpp @@ -356,10 +356,10 @@ struct trace_api_plugin_impl { using chain_extraction_t = chain_extraction_impl_type>; std::shared_ptr extraction; - fc::optional applied_transaction_connection; - fc::optional block_start_connection; - fc::optional accepted_block_connection; - fc::optional irreversible_block_connection; + std::optional applied_transaction_connection; + std::optional block_start_connection; + std::optional accepted_block_connection; + std::optional irreversible_block_connection; }; trace_api_plugin::trace_api_plugin() diff --git a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp index d559d8b0184..ed7a047de27 100644 --- a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp +++ b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp @@ -97,7 +97,7 @@ struct txn_test_gen_plugin_impl { uint64_t _txcount = 0; uint16_t thread_pool_size; - fc::optional thread_pool; + std::optional thread_pool; std::shared_ptr timer; name newaccountA; name newaccountB; diff --git a/plugins/wallet_plugin/include/eosio/wallet_plugin/se_wallet.hpp b/plugins/wallet_plugin/include/eosio/wallet_plugin/se_wallet.hpp index 9e33b194a37..62329d6af3d 100644 --- a/plugins/wallet_plugin/include/eosio/wallet_plugin/se_wallet.hpp +++ b/plugins/wallet_plugin/include/eosio/wallet_plugin/se_wallet.hpp @@ -32,7 +32,7 @@ class se_wallet final : public wallet_api { string create_key(string key_type) override; bool remove_key(string key) override; - fc::optional try_sign_digest(const digest_type digest, const public_key_type public_key) override; + std::optional try_sign_digest(const digest_type digest, const public_key_type public_key) override; private: std::unique_ptr my; diff --git a/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet.hpp b/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet.hpp index 92f2c0e2276..f1468cdb3ab 100644 --- a/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet.hpp +++ b/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet.hpp @@ -177,7 +177,7 @@ class soft_wallet final : public wallet_api /* Attempts to sign a digest via the given public_key */ - fc::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) override; + std::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) override; std::shared_ptr my; void encrypt_keys(); diff --git a/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet_api.hpp b/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet_api.hpp index bdca3ee93e1..4810898c9c1 100644 --- a/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet_api.hpp +++ b/plugins/wallet_plugin/include/eosio/wallet_plugin/wallet_api.hpp @@ -97,7 +97,7 @@ class wallet_api /** Returns a signature given the digest and public_key, if this wallet can sign via that public key */ - virtual fc::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) = 0; + virtual std::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) = 0; }; }} diff --git a/plugins/wallet_plugin/include/eosio/wallet_plugin/yubihsm_wallet.hpp b/plugins/wallet_plugin/include/eosio/wallet_plugin/yubihsm_wallet.hpp index 49caa9c184b..abafbe8478c 100644 --- a/plugins/wallet_plugin/include/eosio/wallet_plugin/yubihsm_wallet.hpp +++ b/plugins/wallet_plugin/include/eosio/wallet_plugin/yubihsm_wallet.hpp @@ -32,7 +32,7 @@ class yubihsm_wallet final : public wallet_api { string create_key(string key_type) override; bool remove_key(string key) override; - fc::optional try_sign_digest(const digest_type digest, const public_key_type public_key) override; + std::optional try_sign_digest(const digest_type digest, const public_key_type public_key) override; private: std::unique_ptr my; diff --git a/plugins/wallet_plugin/se_wallet.cpp b/plugins/wallet_plugin/se_wallet.cpp index aa46fb2a4b1..83361e021d8 100644 --- a/plugins/wallet_plugin/se_wallet.cpp +++ b/plugins/wallet_plugin/se_wallet.cpp @@ -95,14 +95,14 @@ bool se_wallet::remove_key(string key) { FC_THROW_EXCEPTION(chain::wallet_exception, "Given key to delete not found in Secure Enclave wallet"); } -fc::optional se_wallet::try_sign_digest(const digest_type digest, const public_key_type public_key) { +std::optional se_wallet::try_sign_digest(const digest_type digest, const public_key_type public_key) { auto se_keys = secure_enclave::get_all_keys(); for(auto it = se_keys.begin(); it != se_keys.end(); ++it) if(it->public_key() == public_key) return it->sign(digest); - return fc::optional{}; + return std::optional{}; } }} diff --git a/plugins/wallet_plugin/wallet.cpp b/plugins/wallet_plugin/wallet.cpp index 60cb494d3e2..09a0028e217 100644 --- a/plugins/wallet_plugin/wallet.cpp +++ b/plugins/wallet_plugin/wallet.cpp @@ -115,18 +115,18 @@ class soft_wallet_impl string get_wallet_filename() const { return _wallet_filename; } - fc::optional try_get_private_key(const public_key_type& id)const + std::optional try_get_private_key(const public_key_type& id)const { auto it = _keys.find(id); if( it != _keys.end() ) return it->second; - return fc::optional(); + return std::optional(); } - fc::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) { + std::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) { auto it = _keys.find(public_key); if( it == _keys.end() ) - return fc::optional{}; + return std::optional{}; return it->second.sign(digest); } @@ -396,7 +396,7 @@ private_key_type soft_wallet::get_private_key( public_key_type pubkey )const return my->get_private_key( pubkey ); } -fc::optional soft_wallet::try_sign_digest( const digest_type digest, const public_key_type public_key ) { +std::optional soft_wallet::try_sign_digest( const digest_type digest, const public_key_type public_key ) { return my->try_sign_digest(digest, public_key); } diff --git a/plugins/wallet_plugin/wallet_manager.cpp b/plugins/wallet_plugin/wallet_manager.cpp index 0b3bbc6c696..6eaa8a75025 100644 --- a/plugins/wallet_plugin/wallet_manager.cpp +++ b/plugins/wallet_plugin/wallet_manager.cpp @@ -233,7 +233,7 @@ wallet_manager::sign_transaction(const chain::signed_transaction& txn, const fla bool found = false; for (const auto& i : wallets) { if (!i.second->is_locked()) { - fc::optional sig = i.second->try_sign_digest(stxn.sig_digest(id, stxn.context_free_data), pk); + std::optional sig = i.second->try_sign_digest(stxn.sig_digest(id, stxn.context_free_data), pk); if (sig) { stxn.signatures.push_back(*sig); found = true; @@ -256,7 +256,7 @@ wallet_manager::sign_digest(const chain::digest_type& digest, const public_key_t try { for (const auto& i : wallets) { if (!i.second->is_locked()) { - fc::optional sig = i.second->try_sign_digest(digest, key); + std::optional sig = i.second->try_sign_digest(digest, key); if (sig) return *sig; } diff --git a/plugins/wallet_plugin/yubihsm_wallet.cpp b/plugins/wallet_plugin/yubihsm_wallet.cpp index 0ff2d83116f..c51e19c913d 100644 --- a/plugins/wallet_plugin/yubihsm_wallet.cpp +++ b/plugins/wallet_plugin/yubihsm_wallet.cpp @@ -133,10 +133,10 @@ struct yubihsm_wallet_impl { }); } - fc::optional try_sign_digest(const digest_type d, const public_key_type public_key) { + std::optional try_sign_digest(const digest_type d, const public_key_type public_key) { auto it = _keys.find(public_key); if(it == _keys.end()) - return fc::optional{}; + return std::optional{}; size_t der_sig_sz = 128; uint8_t der_sig[der_sig_sz]; @@ -261,7 +261,7 @@ bool yubihsm_wallet::remove_key(string key) { return true; } -fc::optional yubihsm_wallet::try_sign_digest(const digest_type digest, const public_key_type public_key) { +std::optional yubihsm_wallet::try_sign_digest(const digest_type digest, const public_key_type public_key) { return my->try_sign_digest(digest, public_key); } diff --git a/programs/cleos/httpc.cpp b/programs/cleos/httpc.cpp index 6a83a0aa7a2..3aac54628dd 100644 --- a/programs/cleos/httpc.cpp +++ b/programs/cleos/httpc.cpp @@ -149,7 +149,7 @@ namespace eosio { namespace client { namespace http { // non error results are guaranteed to return a non-empty range vector resolved_addresses; resolved_addresses.reserve(result.size()); - optional resolved_port; + std::optional resolved_port; bool is_loopback = true; for(const auto& r : result) { diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 2142aea3dd1..cddd7371b8c 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -347,14 +347,14 @@ chain::action generate_nonce_action() { } //resolver for ABI serializer to decode actions in proposed transaction in multisig contract -auto abi_serializer_resolver = [](const name& account) -> fc::optional { - static unordered_map > abi_cache; +auto abi_serializer_resolver = [](const name& account) -> std::optional { + static unordered_map > abi_cache; auto it = abi_cache.find( account ); if ( it == abi_cache.end() ) { const auto raw_abi_result = call(get_raw_abi_func, fc::mutable_variant_object("account_name", account)); const auto raw_abi_blob = raw_abi_result["abi"].as_blob().data; - fc::optional abis; + std::optional abis; if (raw_abi_blob.size() != 0) { abis.emplace(fc::raw::unpack(raw_abi_blob), abi_serializer::create_yield_function( abi_serializer_max_time )); } else { @@ -368,8 +368,8 @@ auto abi_serializer_resolver = [](const name& account) -> fc::optionalsecond; }; -auto abi_serializer_resolver_empty = [](const name& account) -> fc::optional { - return fc::optional(); +auto abi_serializer_resolver_empty = [](const name& account) -> std::optional { + return std::optional(); }; void prompt_for_wallet_password(string& pw, const string& name) { @@ -522,7 +522,7 @@ void print_action( const fc::variant& at ) { bytes variant_to_bin( const account_name& account, const action_name& action, const fc::variant& action_args_var ) { auto abis = abi_serializer_resolver( account ); - FC_ASSERT( abis.valid(), "No ABI found for ${contract}", ("contract", account)); + FC_ASSERT( abis.has_value(), "No ABI found for ${contract}", ("contract", account)); auto action_type = abis->get_action_type( action ); FC_ASSERT( !action_type.empty(), "Unknown action ${action} in contract ${contract}", ("action", action)( "contract", account )); @@ -531,7 +531,7 @@ bytes variant_to_bin( const account_name& account, const action_name& action, co fc::variant bin_to_variant( const account_name& account, const action_name& action, const bytes& action_args) { auto abis = abi_serializer_resolver( account ); - FC_ASSERT( abis.valid(), "No ABI found for ${contract}", ("contract", account)); + FC_ASSERT( abis.has_value(), "No ABI found for ${contract}", ("contract", account)); auto action_type = abis->get_action_type( action ); FC_ASSERT( !action_type.empty(), "Unknown action ${action} in contract ${contract}", ("action", action)( "contract", account )); @@ -603,7 +603,7 @@ void print_result( const fc::variant& result ) { try { cerr << " us\n"; if( status == "failed" ) { - auto soft_except = processed["except"].as>(); + auto soft_except = processed["except"].as>(); if( soft_except ) { edump((soft_except->to_detail_string())); } @@ -2213,7 +2213,7 @@ void get_account( const string& accountName, const string& coresym, bool json_fo asset staked; asset unstaking; - if( res.core_liquid_balance.valid() ) { + if( res.core_liquid_balance.has_value() ) { unstaking = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for unstaking asset. staked = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for staked asset. } @@ -2433,7 +2433,7 @@ void get_account( const string& accountName, const string& coresym, bool json_fo } } - if( res.core_liquid_balance.valid() ) { + if( res.core_liquid_balance.has_value() ) { std::cout << res.core_liquid_balance->get_symbol().name() << " balances: " << std::endl; std::cout << indent << std::left << std::setw(11) << "liquid:" << std::right << std::setw(18) << *res.core_liquid_balance << std::endl; @@ -2669,7 +2669,7 @@ int main( int argc, char** argv ) { } EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Invalid transaction format: '${data}'", ("data", fc::json::to_string(trx_var, fc::time_point::maximum()))) - fc::optional chain_id; + std::optional chain_id; if( str_chain_id.size() == 0 ) { ilog( "grabbing chain_id from ${n}", ("n", node_executable_name) ); @@ -2705,13 +2705,13 @@ int main( int argc, char** argv ) { getBlock->callback([&blockArg, &get_bhs, &get_binfo] { EOSC_ASSERT( !(get_bhs && get_binfo), "ERROR: Either --header-state or --info can be set" ); if (get_binfo) { - fc::optional block_num; + std::optional block_num; try { block_num = fc::to_int64(blockArg); } catch (...) { // error is handled in assertion below } - EOSC_ASSERT( block_num.valid() && (*block_num > 0), "Invalid block num: ${block_num}", ("block_num", blockArg) ); + EOSC_ASSERT( block_num.has_value() && (*block_num > 0), "Invalid block num: ${block_num}", ("block_num", blockArg) ); const auto arg = fc::variant_object("block_num", static_cast(*block_num)); std::cout << fc::json::to_pretty_string(call(get_block_info_func, arg)) << std::endl; } else { @@ -3496,7 +3496,7 @@ int main( int argc, char** argv ) { } EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Invalid transaction format: '${data}'", ("data", fc::json::to_string(trx_var, fc::time_point::maximum()))) - fc::optional chain_id; + std::optional chain_id; if( str_chain_id.size() == 0 ) { ilog( "grabbing chain_id from ${n}", ("n", node_executable_name) ); diff --git a/programs/eosio-blocklog/main.cpp b/programs/eosio-blocklog/main.cpp index 49b41710261..c0dea933bd5 100644 --- a/programs/eosio-blocklog/main.cpp +++ b/programs/eosio-blocklog/main.cpp @@ -84,7 +84,7 @@ void blocklog::read_log() { first_block = block_logger.first_block_num(); } - optional reversible_blocks; + std::optional reversible_blocks; try { ilog("opening reversible db"); reversible_blocks.emplace(blocks_dir / config::reversible_blocks_dir_name, chainbase::database::read_only, config::default_reversible_cache_size); @@ -128,7 +128,7 @@ void blocklog::read_log() { auto print_block = [&](auto& next) { abi_serializer::to_variant(*next, pretty_output, - []( account_name n ) { return optional(); }, + []( account_name n ) { return std::optional(); }, abi_serializer::create_yield_function( deadline )); const auto block_id = next->calculate_id(); const uint32_t ref_block_prefix = block_id._hash[1]; diff --git a/programs/eosio-launcher/main.cpp b/programs/eosio-launcher/main.cpp index 819feaf0d0e..111cb246176 100644 --- a/programs/eosio-launcher/main.cpp +++ b/programs/eosio-launcher/main.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -423,8 +422,8 @@ struct launcher_def { producer_set_def producer_set; string start_temp; string start_script; - fc::optional max_block_cpu_usage; - fc::optional max_transaction_cpu_usage; + std::optional max_block_cpu_usage; + std::optional max_transaction_cpu_usage; eosio::chain::genesis_state genesis_from_file; void assign_name (eosd_def &node, bool is_bios); diff --git a/programs/eosio-tester/main.cpp b/programs/eosio-tester/main.cpp index f89352e7488..eb47c23ef3f 100644 --- a/programs/eosio-tester/main.cpp +++ b/programs/eosio-tester/main.cpp @@ -135,13 +135,13 @@ struct intrinsic_context { protocol_feature_set make_protocol_feature_set() { protocol_feature_set pfs; - std::map> visited_builtins; + std::map> visited_builtins; std::function add_builtins = [&pfs, &visited_builtins, &add_builtins](builtin_protocol_feature_t codename) -> digest_type { - auto res = visited_builtins.emplace(codename, optional()); + auto res = visited_builtins.emplace(codename, std::optional()); if (!res.second) { - EOS_ASSERT(res.first->second, protocol_feature_exception, + EOS_ASSERT(res.first->second.has_value(), protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies"); return *res.first->second; } @@ -182,10 +182,10 @@ struct test_chain { fc::temp_directory dir; std::unique_ptr cfg; std::unique_ptr control; - fc::optional applied_transaction_connection; - fc::optional accepted_block_connection; + std::optional applied_transaction_connection; + std::optional accepted_block_connection; eosio::state_history::transaction_trace_cache trace_cache; - fc::optional prev_block; + std::optional prev_block; std::map> history; std::unique_ptr intr_ctx; std::set refs; diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index 10e456cddc1..12797cb1111 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -45,19 +45,19 @@ BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, TESTER ) try { set_abi( N(asserter), contracts::asserter_abi().data() ); produce_blocks(1); - auto resolver = [&,this]( const account_name& name ) -> optional { + auto resolver = [&,this]( const account_name& name ) -> std::optional { try { const auto& accnt = this->control->db().get( name ); abi_def abi; if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS(error, "resolver failed at chain_plugin_tests::abi_invalid_type"); }; // abi should be resolved - BOOST_REQUIRE_EQUAL(true, resolver(N(asserter)).valid()); + BOOST_REQUIRE_EQUAL(true, resolver(N(asserter)).has_value()); // make an action using the valid contract & abi variant pretty_trx = mutable_variant_object() diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index 4e6e1f7d8ac..8b19594aceb 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -62,7 +62,7 @@ void verify_round_trip_conversion( const abi_serializer& abis, const type_name& auto get_resolver(const abi_def& abi = abi_def()) { - return [&abi](const account_name &name) -> optional { + return [&abi](const account_name &name) -> std::optional { return abi_serializer(eosio_contract_abi(abi), abi_serializer::create_yield_function( max_serialization_time )); }; } diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 6c2a5b36853..f1695ca3f3f 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -568,7 +568,7 @@ BOOST_AUTO_TEST_CASE(ram_billing_in_notify_tests) { try { chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); const auto& pfm = chain.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value); // testapi requires this - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); chain.preactivate_protocol_features( {*d} ); chain.produce_blocks(2); @@ -1570,7 +1570,7 @@ BOOST_AUTO_TEST_CASE(more_deferred_transaction_tests) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); chain.preactivate_protocol_features( {*d} ); chain.produce_block(); @@ -3080,25 +3080,25 @@ BOOST_FIXTURE_TEST_CASE(eosio_assert_code_tests, TESTER) { try { auto trace = CALL_TEST_FUNCTION_NO_THROW( *this, "test_action", "test_assert_code", fc::raw::pack((uint64_t)42) ); BOOST_REQUIRE( trace ); - BOOST_REQUIRE( trace->except ); + BOOST_REQUIRE( trace->except.has_value() ); BOOST_REQUIRE( trace->error_code ); BOOST_REQUIRE_EQUAL( *trace->error_code, 42 ); BOOST_REQUIRE_EQUAL( trace->action_traces.size(), 1 ); - BOOST_REQUIRE( trace->action_traces[0].except ); + BOOST_REQUIRE( trace->action_traces[0].except.has_value() ); BOOST_REQUIRE( trace->action_traces[0].error_code ); BOOST_REQUIRE_EQUAL( *trace->action_traces[0].error_code, 42 ); produce_block(); auto omsg1 = abis.get_error_message(1); - BOOST_REQUIRE_EQUAL( omsg1.valid(), true ); + BOOST_REQUIRE_EQUAL( omsg1.has_value(), true ); BOOST_CHECK_EQUAL( *omsg1, "standard error message" ); auto omsg2 = abis.get_error_message(2); - BOOST_CHECK_EQUAL( omsg2.valid(), false ); + BOOST_CHECK_EQUAL( omsg2.has_value(), false ); auto omsg3 = abis.get_error_message(42); - BOOST_REQUIRE_EQUAL( omsg3.valid(), true ); + BOOST_REQUIRE_EQUAL( omsg3.has_value(), true ); BOOST_CHECK_EQUAL( *omsg3, "The answer to life, the universe, and everything." ); produce_block(); @@ -3108,11 +3108,11 @@ BOOST_FIXTURE_TEST_CASE(eosio_assert_code_tests, TESTER) { try { fc::raw::pack( static_cast(system_error_code::generic_system_error) ) ); BOOST_REQUIRE( trace2 ); - BOOST_REQUIRE( trace2->except ); + BOOST_REQUIRE( trace2->except.has_value() ); BOOST_REQUIRE( trace2->error_code ); BOOST_REQUIRE_EQUAL( *trace2->error_code, static_cast(system_error_code::contract_restricted_error_code) ); BOOST_REQUIRE_EQUAL( trace2->action_traces.size(), 1 ); - BOOST_REQUIRE( trace2->action_traces[0].except ); + BOOST_REQUIRE( trace2->action_traces[0].except.has_value() ); BOOST_REQUIRE( trace2->action_traces[0].error_code ); BOOST_REQUIRE_EQUAL( *trace2->action_traces[0].error_code, static_cast(system_error_code::contract_restricted_error_code) ); @@ -3188,7 +3188,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[0].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[0].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[0].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[0].return_value), unsigned_int(1) ); BOOST_REQUIRE(pad(atrace[0].receipt->act_digest, atrace[0].act, atrace[0].return_value)); int start_gseq = atrace[0].receipt->global_sequence; @@ -3199,7 +3199,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[1].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[1].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[1].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[1].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[1].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[1].return_value), "bob" ); BOOST_REQUIRE(pad(atrace[1].receipt->act_digest, atrace[1].act, atrace[1].return_value)); BOOST_REQUIRE_EQUAL(atrace[1].receipt->global_sequence, start_gseq + 1); @@ -3210,7 +3210,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[2].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[2].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[2].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[2].return_value), name("five") ); BOOST_REQUIRE(pad(atrace[2].receipt->act_digest, atrace[2].act, atrace[2].return_value)); BOOST_REQUIRE_EQUAL(atrace[2].receipt->global_sequence, start_gseq + 4); @@ -3221,7 +3221,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[3].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.name, TEST_METHOD("test_action", "test_action_ordinal3")); - BOOST_REQUIRE_EQUAL(atrace[3].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[3].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[3].return_value), unsigned_int(9) ); BOOST_REQUIRE(pad(atrace[3].receipt->act_digest, atrace[3].act, atrace[3].return_value)); BOOST_REQUIRE_EQUAL(atrace[3].receipt->global_sequence, start_gseq + 8); @@ -3232,7 +3232,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[4].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[4].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[4].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[4].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[4].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[4].return_value), "charlie" ); BOOST_REQUIRE(pad(atrace[4].receipt->act_digest, atrace[4].act, atrace[4].return_value)); BOOST_REQUIRE_EQUAL(atrace[4].receipt->global_sequence, start_gseq + 2); @@ -3243,7 +3243,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[5].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.account, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.name, TEST_METHOD("test_action", "test_action_ordinal_foo")); - BOOST_REQUIRE_EQUAL(atrace[5].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[5].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[5].return_value), 13.23 ); BOOST_REQUIRE(pad(atrace[5].receipt->act_digest, atrace[5].act, atrace[5].return_value)); BOOST_REQUIRE_EQUAL(atrace[5].receipt->global_sequence, start_gseq + 9); @@ -3254,7 +3254,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[6].receiver, N(david)); BOOST_REQUIRE_EQUAL(atrace[6].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[6].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[6].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[6].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[6].return_value), "david" ); BOOST_REQUIRE(pad(atrace[6].receipt->act_digest, atrace[6].act, atrace[6].return_value)); BOOST_REQUIRE_EQUAL(atrace[6].receipt->global_sequence, start_gseq + 3); @@ -3265,7 +3265,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[7].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.account, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.name, TEST_METHOD("test_action", "test_action_ordinal_bar")); - BOOST_REQUIRE_EQUAL(atrace[7].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[7].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[7].return_value), 11.42f ); BOOST_REQUIRE(pad(atrace[7].receipt->act_digest, atrace[7].act, atrace[7].return_value)); BOOST_REQUIRE_EQUAL(atrace[7].receipt->global_sequence, start_gseq + 10); @@ -3276,7 +3276,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[8].receiver, N(david)); BOOST_REQUIRE_EQUAL(atrace[8].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[8].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[8].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[8].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[8].return_value), true ); BOOST_REQUIRE(pad(atrace[8].receipt->act_digest, atrace[8].act, atrace[8].return_value)); BOOST_REQUIRE_EQUAL(atrace[8].receipt->global_sequence, start_gseq + 5); @@ -3287,7 +3287,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[9].receiver, N(erin)); BOOST_REQUIRE_EQUAL(atrace[9].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[9].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[9].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[9].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[9].return_value), signed_int(7) ); BOOST_REQUIRE(pad(atrace[9].receipt->act_digest, atrace[9].act, atrace[9].return_value)); BOOST_REQUIRE_EQUAL(atrace[9].receipt->global_sequence, start_gseq + 6); @@ -3298,7 +3298,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_test, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[10].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[10].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[10].act.name, TEST_METHOD("test_action", "test_action_ordinal4")); - BOOST_REQUIRE_EQUAL(atrace[10].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[10].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(atrace[10].return_value.size(), 0 ); BOOST_REQUIRE_EQUAL(atrace[10].receipt->global_sequence, start_gseq + 7); } FC_LOG_AND_RETHROW() } @@ -3346,8 +3346,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest1, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[0].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[0].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[0].except.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[0].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[0].except.has_value(), true); BOOST_REQUIRE_EQUAL(atrace[0].except->code(), 3050003); // not executed @@ -3357,8 +3357,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest1, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[1].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[1].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[1].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[1].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[1].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[1].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[1].except.has_value(), false); // not executed BOOST_REQUIRE_EQUAL((int)atrace[2].action_ordinal, 3); @@ -3367,8 +3367,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest1, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[2].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[2].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[2].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[2].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[2].except.has_value(), false); } FC_LOG_AND_RETHROW() } @@ -3414,9 +3414,9 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[0].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[0].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[0].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[0].return_value), unsigned_int(1) ); - BOOST_REQUIRE_EQUAL(atrace[0].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[0].except.has_value(), false); int start_gseq = atrace[0].receipt->global_sequence; // executed @@ -3426,7 +3426,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[1].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[1].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[1].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[1].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[1].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[1].return_value), "bob" ); BOOST_REQUIRE_EQUAL(atrace[1].receipt->global_sequence, start_gseq + 1); @@ -3437,8 +3437,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[2].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[2].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[2].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[2].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[2].except.has_value(), false); // not executed BOOST_REQUIRE_EQUAL((int)atrace[3].action_ordinal, 4); @@ -3447,8 +3447,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[3].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.name, TEST_METHOD("test_action", "test_action_ordinal3")); - BOOST_REQUIRE_EQUAL(atrace[3].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[3].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[3].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[3].except.has_value(), false); // hey exception is here BOOST_REQUIRE_EQUAL((int)atrace[4].action_ordinal, 5); @@ -3457,8 +3457,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[4].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[4].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[4].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[4].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[4].except.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[4].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[4].except.has_value(), true); BOOST_REQUIRE_EQUAL(atrace[4].except->code(), 3050003); // not executed @@ -3468,8 +3468,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[5].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.account, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.name, TEST_METHOD("test_action", "test_action_ordinal_foo")); - BOOST_REQUIRE_EQUAL(atrace[5].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[5].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[5].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[5].except.has_value(), false); // not executed BOOST_REQUIRE_EQUAL((int)atrace[6].action_ordinal, 7); @@ -3478,8 +3478,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[6].receiver, N(david)); BOOST_REQUIRE_EQUAL(atrace[6].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[6].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[6].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[6].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[6].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[6].except.has_value(), false); // not executed BOOST_REQUIRE_EQUAL((int)atrace[7].action_ordinal, 8); @@ -3488,8 +3488,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest2, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[7].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.account, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.name, TEST_METHOD("test_action", "test_action_ordinal_bar")); - BOOST_REQUIRE_EQUAL(atrace[7].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[7].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[7].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[7].except.has_value(), false); } FC_LOG_AND_RETHROW() } @@ -3535,9 +3535,9 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[0].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[0].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[0].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[0].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[0].return_value), unsigned_int(1) ); - BOOST_REQUIRE_EQUAL(atrace[0].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[0].except.has_value(), false); int start_gseq = atrace[0].receipt->global_sequence; // executed @@ -3547,7 +3547,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[1].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[1].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[1].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[1].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[1].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[1].return_value), "bob" ); BOOST_REQUIRE_EQUAL(atrace[1].receipt->global_sequence, start_gseq + 1); @@ -3558,7 +3558,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[2].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[2].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[2].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[2].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[2].return_value), name("five") ); BOOST_REQUIRE_EQUAL(atrace[2].receipt->global_sequence, start_gseq + 4); @@ -3569,8 +3569,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[3].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[3].act.name, TEST_METHOD("test_action", "test_action_ordinal3")); - BOOST_REQUIRE_EQUAL(atrace[3].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[3].except.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[3].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[3].except.has_value(), true); BOOST_REQUIRE_EQUAL(atrace[3].except->code(), 3050003); // executed @@ -3580,7 +3580,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[4].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[4].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[4].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[4].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[4].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[4].return_value), "charlie" ); BOOST_REQUIRE_EQUAL(atrace[4].receipt->global_sequence, start_gseq + 2); @@ -3591,8 +3591,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[5].receiver, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.account, N(bob)); BOOST_REQUIRE_EQUAL(atrace[5].act.name, TEST_METHOD("test_action", "test_action_ordinal_foo")); - BOOST_REQUIRE_EQUAL(atrace[5].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[5].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[5].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[5].except.has_value(), false); // executed BOOST_REQUIRE_EQUAL((int)atrace[6].action_ordinal, 7); @@ -3601,7 +3601,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[6].receiver, N(david)); BOOST_REQUIRE_EQUAL(atrace[6].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[6].act.name, TEST_METHOD("test_action", "test_action_ordinal1")); - BOOST_REQUIRE_EQUAL(atrace[6].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[6].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[6].return_value), "david" ); BOOST_REQUIRE_EQUAL(atrace[6].receipt->global_sequence, start_gseq + 3); @@ -3612,8 +3612,8 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[7].receiver, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.account, N(charlie)); BOOST_REQUIRE_EQUAL(atrace[7].act.name, TEST_METHOD("test_action", "test_action_ordinal_bar")); - BOOST_REQUIRE_EQUAL(atrace[7].receipt.valid(), false); - BOOST_REQUIRE_EQUAL(atrace[7].except.valid(), false); + BOOST_REQUIRE_EQUAL(atrace[7].receipt.has_value(), false); + BOOST_REQUIRE_EQUAL(atrace[7].except.has_value(), false); // executed BOOST_REQUIRE_EQUAL((int)atrace[8].action_ordinal, 9); @@ -3622,7 +3622,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[8].receiver, N(david)); BOOST_REQUIRE_EQUAL(atrace[8].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[8].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[8].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[8].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[8].return_value), true ); BOOST_REQUIRE_EQUAL(atrace[8].receipt->global_sequence, start_gseq + 5); @@ -3633,7 +3633,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[9].receiver, N(erin)); BOOST_REQUIRE_EQUAL(atrace[9].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[9].act.name, TEST_METHOD("test_action", "test_action_ordinal2")); - BOOST_REQUIRE_EQUAL(atrace[9].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[9].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(fc::raw::unpack(atrace[9].return_value), signed_int(7) ); BOOST_REQUIRE_EQUAL(atrace[9].receipt->global_sequence, start_gseq + 6); @@ -3644,7 +3644,7 @@ BOOST_FIXTURE_TEST_CASE(action_ordinal_failtest3, TESTER) { try { BOOST_REQUIRE_EQUAL(atrace[10].receiver, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[10].act.account, N(testapi)); BOOST_REQUIRE_EQUAL(atrace[10].act.name, TEST_METHOD("test_action", "test_action_ordinal4")); - BOOST_REQUIRE_EQUAL(atrace[10].receipt.valid(), true); + BOOST_REQUIRE_EQUAL(atrace[10].receipt.has_value(), true); BOOST_REQUIRE_EQUAL(atrace[10].return_value.size(), 0 ); BOOST_REQUIRE_EQUAL(atrace[10].receipt->global_sequence, start_gseq + 7); diff --git a/unittests/chain_tests.cpp b/unittests/chain_tests.cpp index f68f70c59a1..0a049e42556 100644 --- a/unittests/chain_tests.cpp +++ b/unittests/chain_tests.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( replace_producer_keys ) try { BOOST_REQUIRE(old_version == new_version); const auto& gpo = tester.control->db().get(); - BOOST_REQUIRE(!gpo.proposed_schedule_block_num); + BOOST_REQUIRE(!gpo.proposed_schedule_block_num.has_value()); BOOST_REQUIRE(gpo.proposed_schedule.version == 0); BOOST_REQUIRE(gpo.proposed_schedule.producers.empty()); diff --git a/unittests/delay_tests.cpp b/unittests/delay_tests.cpp index c0b0fb3bab4..b0b23895d01 100644 --- a/unittests/delay_tests.cpp +++ b/unittests/delay_tests.cpp @@ -76,7 +76,7 @@ BOOST_FIXTURE_TEST_CASE( delay_error_create_account, validating_tester) { try { auto billed_cpu_time_us = control->get_global_properties().configuration.min_transaction_cpu_usage; auto dtrace = control->push_scheduled_transaction(scheduled_trxs.front(), fc::time_point::maximum(), billed_cpu_time_us, true); - BOOST_REQUIRE_EQUAL(dtrace->except.valid(), true); + BOOST_REQUIRE_EQUAL(dtrace->except.has_value(), true); BOOST_REQUIRE_EQUAL(dtrace->except->code(), missing_auth_exception::code_value); } FC_LOG_AND_RETHROW() } diff --git a/unittests/forked_tests.cpp b/unittests/forked_tests.cpp index 92215809216..eaba26d3ce1 100644 --- a/unittests/forked_tests.cpp +++ b/unittests/forked_tests.cpp @@ -762,8 +762,8 @@ BOOST_AUTO_TEST_CASE( push_block_returns_forked_transactions ) try { BOOST_CHECK_EQUAL( transaction_receipt_header::executed, traces.at(2)->receipt->status ); // test4 failed because it was tapos to a forked out block BOOST_CHECK_EQUAL( trace4->id, traces.at(3)->id ); - BOOST_CHECK( !traces.at(3)->receipt ); - BOOST_CHECK( !!traces.at(3)->except ); + BOOST_CHECK( !traces.at(3)->receipt.has_value() ); + BOOST_CHECK( traces.at(3)->except.has_value() ); // verify unapplied transactions ran BOOST_REQUIRE_EQUAL( c.control->get_account( N(test1) ).name, N(test1) ); diff --git a/unittests/misc_tests.cpp b/unittests/misc_tests.cpp index 80f810eb475..b0d72be0052 100644 --- a/unittests/misc_tests.cpp +++ b/unittests/misc_tests.cpp @@ -1063,7 +1063,7 @@ BOOST_AUTO_TEST_CASE(pruned_block_test) { deserialized.pack(out, packed_transaction::cf_compression_type::none); BOOST_TEST(out.tellp() <= buffer.size()); - BOOST_TEST(!deserialized.to_signed_block_v0()); + BOOST_TEST(!deserialized.to_signed_block_v0().has_value()); } BOOST_AUTO_TEST_CASE(reflector_init_test) { diff --git a/unittests/producer_schedule_tests.cpp b/unittests/producer_schedule_tests.cpp index 32655b3fbc8..9e81b756668 100644 --- a/unittests/producer_schedule_tests.cpp +++ b/unittests/producer_schedule_tests.cpp @@ -216,7 +216,7 @@ BOOST_FIXTURE_TEST_CASE( producer_schedule_promotion_test, TESTER ) try { }; //wdump((fc::json::to_pretty_string(res))); wlog("set producer schedule to [alice,bob]"); - BOOST_REQUIRE_EQUAL( true, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch1, *control->proposed_producers() ) ); BOOST_CHECK_EQUAL( control->pending_producers().version, 0u ); produce_block(); // Starts new block which promotes the proposed schedule to pending @@ -236,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE( producer_schedule_promotion_test, TESTER ) try { producer_authority{N(carol), block_signing_authority_v0{1, {{get_public_key(N(carol), "active"),1}}}} }; wlog("set producer schedule to [alice,bob,carol]"); - BOOST_REQUIRE_EQUAL( true, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch2, *control->proposed_producers() ) ); produce_block(); @@ -281,7 +281,7 @@ BOOST_FIXTURE_TEST_CASE( producer_schedule_reduction, tester ) try { producer_authority{N(carol), block_signing_authority_v0{ 1, {{get_public_key(N(carol), "active"),1}}}} }; wlog("set producer schedule to [alice,bob,carol]"); - BOOST_REQUIRE_EQUAL( true, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch1, *control->proposed_producers() ) ); BOOST_CHECK_EQUAL( control->pending_producers().version, 0u ); produce_block(); // Starts new block which promotes the proposed schedule to pending @@ -300,7 +300,7 @@ BOOST_FIXTURE_TEST_CASE( producer_schedule_reduction, tester ) try { producer_authority{N(bob), block_signing_authority_v0{ 1, {{ get_public_key(N(bob), "active"),1}}}} }; wlog("set producer schedule to [alice,bob]"); - BOOST_REQUIRE_EQUAL( true, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch2, *control->proposed_producers() ) ); produce_blocks(48); @@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { producer_authority{N(bob), block_signing_authority_v0{ 1, {{ get_public_key(N(bob), "active"),1}}}} }; wlog("set producer schedule to [alice,bob]"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch1, *c.control->proposed_producers() ) ); BOOST_CHECK_EQUAL( c.control->pending_producers().producers.size(), 0u ); @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { res = c.set_producers_legacy( {} ); wlog("set producer schedule to []"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( c.control->proposed_producers()->producers.size(), 0u ); BOOST_CHECK_EQUAL( c.control->proposed_producers()->version, 2u ); @@ -371,7 +371,7 @@ BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { // Empty producer schedule does get promoted from proposed to pending c.produce_block(); BOOST_CHECK_EQUAL( c.control->pending_producers().version, 2u ); - BOOST_CHECK_EQUAL( false, c.control->proposed_producers().valid() ); + BOOST_CHECK_EQUAL( false, c.control->proposed_producers().has_value() ); // However it should not get promoted from pending to active c.produce_blocks(24); @@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { producer_authority{N(carol), block_signing_authority_v0{ 1, {{get_public_key(N(carol), "active"),1}}}} }; wlog("set producer schedule to [alice,bob,carol]"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch2, *c.control->proposed_producers() ) ); BOOST_CHECK_EQUAL( c.control->proposed_producers()->version, 2u ); @@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE( producer_watermark_test ) try { producer_authority{N(carol), block_signing_authority_v0{ 1, {{c.get_public_key(N(carol), "active"),1}}}} }; wlog("set producer schedule to [alice,bob,carol]"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch1, *c.control->proposed_producers() ) ); BOOST_CHECK_EQUAL( c.control->pending_producers().version, 0u ); c.produce_block(); // Starts new block which promotes the proposed schedule to pending @@ -443,7 +443,7 @@ BOOST_AUTO_TEST_CASE( producer_watermark_test ) try { producer_authority{N(bob), block_signing_authority_v0{ 1, {{c.get_public_key(N(bob), "active"),1}}}} }; wlog("set producer schedule to [alice,bob]"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch2, *c.control->proposed_producers() ) ); produce_until_transition( c, N(bob), N(carol) ); @@ -467,7 +467,7 @@ BOOST_AUTO_TEST_CASE( producer_watermark_test ) try { res = c.set_producers( {N(alice),N(bob),N(carol)} ); wlog("set producer schedule to [alice,bob,carol]"); - BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, c.control->proposed_producers().has_value() ); BOOST_CHECK_EQUAL( true, compare_schedules( sch1, *c.control->proposed_producers() ) ); produce_until_transition( c, N(bob), N(alice) ); @@ -574,7 +574,7 @@ BOOST_FIXTURE_TEST_CASE( satisfiable_msig_test, TESTER ) try { fc_exception_message_is( "producer schedule includes an unsatisfiable authority for alice" ) ); - BOOST_REQUIRE_EQUAL( false, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( false, control->proposed_producers().has_value() ); } FC_LOG_AND_RETHROW() @@ -593,7 +593,7 @@ BOOST_FIXTURE_TEST_CASE( duplicate_producers_test, TESTER ) try { fc_exception_message_is( "duplicate producer name in producer schedule" ) ); - BOOST_REQUIRE_EQUAL( false, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( false, control->proposed_producers().has_value() ); } FC_LOG_AND_RETHROW() @@ -611,7 +611,7 @@ BOOST_FIXTURE_TEST_CASE( duplicate_keys_test, TESTER ) try { fc_exception_message_is( "producer schedule includes a duplicated key for alice" ) ); - BOOST_REQUIRE_EQUAL( false, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( false, control->proposed_producers().has_value() ); // ensure that multiple producers are allowed to share keys vector sch2 = { @@ -620,7 +620,7 @@ BOOST_FIXTURE_TEST_CASE( duplicate_keys_test, TESTER ) try { }; set_producer_schedule( sch2 ); - BOOST_REQUIRE_EQUAL( true, control->proposed_producers().valid() ); + BOOST_REQUIRE_EQUAL( true, control->proposed_producers().has_value() ); } FC_LOG_AND_RETHROW() BOOST_AUTO_TEST_CASE( large_authority_overflow_test ) try { diff --git a/unittests/protocol_feature_tests.cpp b/unittests/protocol_feature_tests.cpp index 0137b8d9a6b..c32290f7f29 100644 --- a/unittests/protocol_feature_tests.cpp +++ b/unittests/protocol_feature_tests.cpp @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( activate_preactivate_feature ) try { auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::preactivate_feature ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); // Activate PREACTIVATE_FEATURE. c.schedule_protocol_features_wo_preactivation({ *d }); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( activate_and_restart ) try { auto pfs = pfm.get_protocol_feature_set(); // make copy of protocol feature set auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::preactivate_feature ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::preactivate_feature ) ); @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE( double_preactivation ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.push_action( config::system_account_name, N(activate), config::system_account_name, fc::mutable_variant_object()("feature_digest", *d), 10 ); @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE( double_activation ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::only_link_to_existing_permission ) ); @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE( require_preactivation_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::only_link_to_existing_permission ) ); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE( only_link_to_existing_permission_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.create_accounts( {N(alice), N(bob), N(charlie)} ); @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE( subjective_restrictions_test ) try { auto get_builtin_digest = [&pfm]( builtin_protocol_feature_t codename ) -> digest_type { auto res = pfm.get_builtin_digest( codename ); - BOOST_REQUIRE( res ); + BOOST_REQUIRE( res.has_value() ); return *res; }; @@ -456,7 +456,7 @@ BOOST_AUTO_TEST_CASE( replace_deferred_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -577,9 +577,9 @@ BOOST_AUTO_TEST_CASE( no_duplicate_deferred_id_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d1 = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d1 ); + BOOST_REQUIRE( d1.has_value() ); auto d2 = pfm.get_builtin_digest( builtin_protocol_feature_t::no_duplicate_deferred_id ); - BOOST_REQUIRE( d2 ); + BOOST_REQUIRE( d2.has_value() ); c.push_action( N(test), N(defercall), N(alice), fc::mutable_variant_object() ("payer", "alice") @@ -724,7 +724,7 @@ BOOST_AUTO_TEST_CASE( fix_linkauth_restriction ) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::fix_linkauth_restriction ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); chain.preactivate_protocol_features( {*d} ); chain.produce_block(); @@ -756,7 +756,7 @@ BOOST_AUTO_TEST_CASE( disallow_empty_producer_schedule_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::disallow_empty_producer_schedule ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); // Before activation, it is allowed to set empty producer schedule c.set_producers_legacy( {} ); @@ -783,7 +783,7 @@ BOOST_AUTO_TEST_CASE( restrict_action_to_self_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::restrict_action_to_self ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.create_accounts( {N(testacc), N(acctonotify), N(alice)} ); c.set_code( N(testacc), contracts::restrict_action_test_wasm() ); @@ -904,7 +904,7 @@ BOOST_AUTO_TEST_CASE( only_bill_to_first_authorizer ) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_bill_first_authorizer ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); chain.preactivate_protocol_features( {*d} ); chain.produce_blocks(); @@ -964,7 +964,7 @@ BOOST_AUTO_TEST_CASE( forward_setcode_test ) { try { // Activate FORWARD_SETCODE protocol feature and then return contract on eosio back to what it was. const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::forward_setcode ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.set_before_producer_authority_bios_contract(); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -1019,7 +1019,7 @@ BOOST_AUTO_TEST_CASE( get_sender_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::get_sender ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -1221,7 +1221,7 @@ BOOST_AUTO_TEST_CASE( ram_restrictions_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::ram_restrictions ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); // Activate RAM_RESTRICTIONS protocol feature (this would also disable the subjective mitigation). c.preactivate_protocol_features( {*d} ); @@ -1329,7 +1329,7 @@ BOOST_AUTO_TEST_CASE( webauthn_producer ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::webauthn_key ); - BOOST_REQUIRE( d ); + BOOST_REQUIRE( d.has_value() ); c.create_account(N(waprod)); c.produce_block(); @@ -1352,7 +1352,7 @@ BOOST_AUTO_TEST_CASE( webauthn_create_account ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); signed_transaction trx; c.set_transaction_headers(trx); @@ -1380,7 +1380,7 @@ BOOST_AUTO_TEST_CASE( webauthn_update_account_auth ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.create_account(N(billy)); c.produce_block(); @@ -1431,7 +1431,7 @@ BOOST_AUTO_TEST_CASE( webauthn_recover_key ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.create_account(N(bob)); c.set_code(N(bob), webauthn_recover_key_wast); @@ -1479,7 +1479,7 @@ BOOST_AUTO_TEST_CASE( webauthn_assert_recover_key ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.create_account(N(bob)); c.set_code(N(bob), webauthn_assert_recover_key_wast); @@ -1525,7 +1525,7 @@ BOOST_AUTO_TEST_CASE( set_proposed_producers_ex_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); const auto& alice_account = account_name("alice"); c.create_accounts( {alice_account} ); @@ -1560,7 +1560,7 @@ BOOST_AUTO_TEST_CASE( producer_schedule_change_extension_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.produce_blocks(2); @@ -1677,7 +1677,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_legacy_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.produce_blocks(2); @@ -1689,7 +1689,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_legacy_test ) { try { // ensure the last legacy block contains a new_producers auto last_legacy_block = c.produce_block(); - BOOST_REQUIRE_EQUAL(last_legacy_block->new_producers.valid(), true); + BOOST_REQUIRE_EQUAL(last_legacy_block->new_producers.has_value(), true); // promote to active schedule c.produce_block(); @@ -1708,7 +1708,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_extension_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); c.produce_blocks(2); @@ -1723,7 +1723,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_extension_test ) { try { // ensure the first possible new block contains a producer_schedule_change_extension auto first_new_block = c.produce_block(); - BOOST_REQUIRE_EQUAL(first_new_block->new_producers.valid(), false); + BOOST_REQUIRE_EQUAL(first_new_block->new_producers.has_value(), false); BOOST_REQUIRE_EQUAL(first_new_block->header_extensions.size(), 1); BOOST_REQUIRE_EQUAL(first_new_block->header_extensions.at(0).first, producer_schedule_change_extension::extension_id()); @@ -1759,7 +1759,7 @@ BOOST_AUTO_TEST_CASE( set_action_return_value_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value); - BOOST_REQUIRE(d); + BOOST_REQUIRE(d.has_value()); const auto& alice_account = account_name("alice"); c.create_accounts( {alice_account} ); diff --git a/unittests/resource_limits_test.cpp b/unittests/resource_limits_test.cpp index 6db20c2ab72..256b716fd17 100644 --- a/unittests/resource_limits_test.cpp +++ b/unittests/resource_limits_test.cpp @@ -353,7 +353,7 @@ BOOST_AUTO_TEST_SUITE(resource_limits_test) constexpr int64_t unlimited = -1; - using get_account_limit_ex_func = std::function(const resource_limits_manager*, const account_name&, uint32_t, const fc::optional&)>; + using get_account_limit_ex_func = std::function(const resource_limits_manager*, const account_name&, uint32_t, const std::optional&)>; auto test_get_account_limit_ex = [this](const account_name& test_account, const uint32_t window, get_account_limit_ex_func get_account_limit_ex) { constexpr uint32_t delta_slot = 100; diff --git a/unittests/restart_chain_tests.cpp b/unittests/restart_chain_tests.cpp index 6349efcb149..2f6f3abd69e 100644 --- a/unittests/restart_chain_tests.cpp +++ b/unittests/restart_chain_tests.cpp @@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(test_restart_with_different_chain_id) { genesis_state genesis; genesis.initial_timestamp = fc::time_point::from_iso_string("2020-01-01T00:00:01.000"); genesis.initial_key = eosio::testing::base_tester::get_public_key(config::system_account_name, "active"); - fc::optional chain_id = genesis.compute_chain_id(); + std::optional chain_id = genesis.compute_chain_id(); BOOST_REQUIRE_EXCEPTION(other.open(chain_id), chain_id_type_exception, fc_exception_message_starts_with("chain ID in state ")); } diff --git a/unittests/state_history_tests.cpp b/unittests/state_history_tests.cpp index cf64d4c3eec..9f2d2f40dd8 100644 --- a/unittests/state_history_tests.cpp +++ b/unittests/state_history_tests.cpp @@ -32,7 +32,7 @@ prunable_data_type::prunable_data_t get_prunable_data_from_traces(std::vectorcontains()); auto trace_v0 = cfd_trace_itr->get(); - BOOST_REQUIRE(trace_v0.partial); + BOOST_REQUIRE(trace_v0.partial.has_value()); BOOST_REQUIRE(trace_v0.partial->contains()); return trace_v0.partial->get().prunable_data->prunable_data; } @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(test_state_result_abi) { transaction_trace_cache trace_cache; std::map history; - fc::optional prev_block; + std::optional prev_block; chain.control->applied_transaction.connect( [&](std::tuple t) { @@ -352,7 +352,7 @@ BOOST_AUTO_TEST_CASE(test_state_result_abi) { std::vector traces; state_history::trace_converter::unpack(strm, traces); message.traces = traces; - message.deltas = fc::raw::pack(state_history::create_deltas(control->db(), !prev_block)); + message.deltas = fc::raw::pack(state_history::create_deltas(control->db(), !prev_block.has_value())); prev_block = message.this_block; history[control->head_block_num()] = fc::raw::pack(state_history::state_result{message}); diff --git a/unittests/wasm_tests.cpp b/unittests/wasm_tests.cpp index dbc2abad57f..03fa1343293 100644 --- a/unittests/wasm_tests.cpp +++ b/unittests/wasm_tests.cpp @@ -178,14 +178,14 @@ BOOST_FIXTURE_TEST_CASE( abi_from_variant, TESTER ) try { set_abi(N(asserter), contracts::asserter_abi().data()); produce_blocks(1); - auto resolver = [&,this]( const account_name& name ) -> fc::optional { + auto resolver = [&,this]( const account_name& name ) -> std::optional { try { const auto& accnt = this->control->db().get( name ); abi_def abi; if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return fc::optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS(error, "Failed to find or parse ABI for ${name}", ("name", name)) }; diff --git a/unittests/whitelist_blacklist_tests.cpp b/unittests/whitelist_blacklist_tests.cpp index 06cebb3dbfb..467b5605a41 100644 --- a/unittests/whitelist_blacklist_tests.cpp +++ b/unittests/whitelist_blacklist_tests.cpp @@ -26,7 +26,7 @@ class whitelist_blacklist_tester { whitelist_blacklist_tester() {} void init( bool bootstrap = true ) { - FC_ASSERT( !chain, "chain is already up" ); + FC_ASSERT( !chain.has_value(), "chain is already up" ); chain.emplace(tempdir, [&](controller::config& cfg) { cfg.sender_bypass_whiteblacklist = sender_bypass_whiteblacklist; @@ -57,7 +57,7 @@ class whitelist_blacklist_tester { } void shutdown() { - FC_ASSERT( chain.valid(), "chain is not up" ); + FC_ASSERT( chain.has_value(), "chain is not up" ); last_produced_block = chain->get_last_produced_block_map(); wdump((last_produced_block)); chain.reset(); @@ -76,7 +76,7 @@ class whitelist_blacklist_tester { private: fc::temp_directory tempdir; // Must come before chain public: - fc::optional chain; + std::optional chain; flat_set sender_bypass_whiteblacklist; flat_set actor_whitelist; flat_set actor_blacklist; From 16269360b0f76a09fdd814c632b3d0c30ab31d44 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 16 Jun 2020 15:31:17 -0400 Subject: [PATCH 02/17] Remove fc/optional.hpp --- libraries/fc/include/fc/optional.hpp | 276 --------------------------- 1 file changed, 276 deletions(-) delete mode 100644 libraries/fc/include/fc/optional.hpp diff --git a/libraries/fc/include/fc/optional.hpp b/libraries/fc/include/fc/optional.hpp deleted file mode 100644 index 520bbde418d..00000000000 --- a/libraries/fc/include/fc/optional.hpp +++ /dev/null @@ -1,276 +0,0 @@ -#pragma once -#include -#include - - -namespace fc { -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4521) /* multiple copy ctors */ -# pragma warning(disable:4522) /* multiple assignment operators */ -#endif - bool assert_optional(bool is_valid ); // defined in exception.cpp - - /** - * @brief provides stack-based nullable value similar to boost::optional - * - * Simply including boost::optional adds 35,000 lines to each object file, using - * fc::optional adds less than 400. - */ - template - class optional - { - public: - typedef T value_type; - typedef typename std::aligned_storage::type storage_type; - - optional():_valid(false){} - ~optional(){ reset(); } - - optional( optional& o ) - :_valid(false) - { - if( o._valid ) new (ptr()) T( *o ); - _valid = o._valid; - } - - optional( const optional& o ) - :_valid(false) - { - if( o._valid ) new (ptr()) T( *o ); - _valid = o._valid; - } - - optional( optional&& o ) - :_valid(false) - { - if( o._valid ) new (ptr()) T( fc::move(*o) ); - _valid = o._valid; - o.reset(); - } - - template - optional( const optional& o ) - :_valid(false) - { - if( o._valid ) new (ptr()) T( *o ); - _valid = o._valid; - } - - template - optional( optional& o ) - :_valid(false) - { - if( o._valid ) - { - new (ptr()) T( *o ); - } - _valid = o._valid; - } - - template - optional( optional&& o ) - :_valid(false) - { - if( o._valid ) new (ptr()) T( fc::move(*o) ); - _valid = o._valid; - o.reset(); - } - - template - optional( U&& u ) - :_valid(true) - { - new ((char*)ptr()) T( fc::forward(u) ); - } - - template - optional& operator=( U&& u ) - { - reset(); - new (ptr()) T( fc::forward(u) ); - _valid = true; - return *this; - } - - template - void emplace(Args&& ... args) { - if (_valid) { - reset(); - } - - new ((char*)ptr()) T( fc::forward(args)... ); - _valid = true; - } - - template - optional& operator=( optional& o ) { - if (this != &o) { - if( _valid && o._valid ) { - ref() = *o; - } else if( !_valid && o._valid ) { - new (ptr()) T( *o ); - _valid = true; - } else if (_valid) { - reset(); - } - } - return *this; - } - template - optional& operator=( const optional& o ) { - if (this != &o) { - if( _valid && o._valid ) { - ref() = *o; - } else if( !_valid && o._valid ) { - new (ptr()) T( *o ); - _valid = true; - } else if (_valid) { - reset(); - } - } - return *this; - } - - optional& operator=( optional& o ) { - if (this != &o) { - if( _valid && o._valid ) { - ref() = *o; - } else if( !_valid && o._valid ) { - new (ptr()) T( *o ); - _valid = true; - } else if (_valid) { - reset(); - } - } - return *this; - } - - optional& operator=( const optional& o ) { - if (this != &o) { - if( _valid && o._valid ) { - ref() = *o; - } else if( !_valid && o._valid ) { - new (ptr()) T( *o ); - _valid = true; - } else if (_valid) { - reset(); - } - } - return *this; - } - - template - optional& operator=( optional&& o ) - { - if (this != &o) - { - if( _valid && o._valid ) - { - ref() = fc::move(*o); - o.reset(); - } else if ( !_valid && o._valid ) { - *this = fc::move(*o); - } else if (_valid) { - reset(); - } - } - return *this; - } - - optional& operator=( optional&& o ) - { - if (this != &o) - { - if( _valid && o._valid ) - { - ref() = fc::move(*o); - o.reset(); - } else if ( !_valid && o._valid ) { - *this = fc::move(*o); - } else if (_valid) { - reset(); - } - } - return *this; - } - - bool valid()const { return _valid; } - bool operator!()const { return !_valid; } - - // this operation is not safe and can result in unintential - // casts and comparisons, use valid() or !! - explicit operator bool()const { return _valid; } - - T& operator*() { assert(_valid); return ref(); } - const T& operator*()const { assert(_valid); return ref(); } - - T* operator->() - { - assert(_valid); - return ptr(); - } - const T* operator->()const - { - assert(_valid); - return ptr(); - } - - optional& operator=(std::nullptr_t) - { - reset(); - return *this; - } - - friend bool operator < ( const optional a, optional b ) - { - if( a.valid() && b.valid() ) return *a < *b; - return a.valid() < b.valid(); - } - friend bool operator == ( const optional a, optional b ) - { - if( a.valid() && b.valid() ) return *a == *b; - return a.valid() == b.valid(); - } - - void reset() - { - if( _valid ) - { - ref().~T(); // cal destructor - } - _valid = false; - } - private: - template friend class optional; - T& ref() { return *ptr(); } - const T& ref()const { return *ptr(); } - T* ptr() { return reinterpret_cast(&_value); } - const T* ptr()const { return reinterpret_cast(&_value); } - - bool _valid; - storage_type _value; - }; - - template - bool operator == ( const optional& left, const optional& right ) { - return (!left == !right) || (!!left && *left == *right); - } - template - bool operator == ( const optional& left, const U& u ) { - return !!left && *left == u; - } - template - bool operator != ( const optional& left, const optional& right ) { - return (!left != !right) || (!!left && *left != *right); - } - template - bool operator != ( const optional& left, const U& u ) { - return !left || *left != u; - } - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -} // namespace fc From fb39a8e51c1498ee93fa92e6d837a0a27075bc94 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 16 Jun 2020 20:08:19 -0400 Subject: [PATCH 03/17] Additional migration fixups. --- libraries/chain/block_log.cpp | 2 +- libraries/chain/include/eosio/chain/authority_checker.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 6cef49b1683..f4dd632cd5b 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -657,7 +657,7 @@ namespace eosio { namespace chain { buffer = pack(b, segment_compression); } else { auto block_ptr = b.to_signed_block_v0(); - EOS_ASSERT(block_ptr, block_log_append_fail, "Unable to convert block to legacy format"); + EOS_ASSERT(block_ptr.has_value(), block_log_append_fail, "Unable to convert block to legacy format"); EOS_ASSERT(segment_compression == packed_transaction::cf_compression_type::none, block_log_append_fail, "the compression must be \"none\" for legacy format"); buffer = fc::raw::pack(*block_ptr); diff --git a/libraries/chain/include/eosio/chain/authority_checker.hpp b/libraries/chain/include/eosio/chain/authority_checker.hpp index 16a3f954090..6b380f68196 100644 --- a/libraries/chain/include/eosio/chain/authority_checker.hpp +++ b/libraries/chain/include/eosio/chain/authority_checker.hpp @@ -220,7 +220,7 @@ namespace detail { uint32_t operator()(const permission_level_weight& permission) { auto status = authority_checker::permission_status_in_cache( cached_permissions, permission.permission ); - if( !status ) { + if( !status.has_value() ) { if( recursion_depth < checker.recursion_depth_limit ) { bool r = false; typename permission_cache_type::iterator itr = cached_permissions.end(); From cd1f8b6f1e2bd22a6ae47ff91e7e7c6251ca91d9 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Wed, 17 Jun 2020 09:50:10 -0400 Subject: [PATCH 04/17] Made std::optional to fc::variant conversion explicit --- libraries/fc/include/fc/variant.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc/include/fc/variant.hpp b/libraries/fc/include/fc/variant.hpp index 9c372e3c8be..f261076da90 100644 --- a/libraries/fc/include/fc/variant.hpp +++ b/libraries/fc/include/fc/variant.hpp @@ -348,7 +348,7 @@ namespace fc } template - variant( const std::optional& v ) + explicit variant( const std::optional& v ) { memset( this, 0, sizeof(*this) ); if( v.has_value() ) *this = variant(*v); From 28874251c4affebe1a83b068697cb01b320e71e1 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Wed, 17 Jun 2020 20:18:02 -0400 Subject: [PATCH 05/17] Remove many uses of has_value() on std::optional. --- plugins/state_history_plugin/state_history_plugin.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index 17a47179f41..fcd1a518283 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -178,7 +178,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thisget_block_id(cp.block_num); - if (!id.has_value() || *id != cp.block_id) + if (!id || *id != cp.block_id) req.start_block_num = std::min(req.start_block_num, cp.block_num); if (!id) { @@ -205,7 +205,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) + if (!send_queue.empty() || !current_request || !current_request->max_messages_in_flight) return; auto& chain = plugin->chain_plug->chain(); result.last_irreversible = {chain.last_irreversible_block_num(), chain.last_irreversible_block_id()}; @@ -241,7 +241,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) + if (!send_queue.empty() || !current_request || !current_request->max_messages_in_flight) return; get_blocks_result_v1 result; result.head = {block_state->block_num, block_state->id}; @@ -251,7 +251,7 @@ struct state_history_plugin_impl : std::enable_shared_from_thismax_messages_in_flight) return; auto& chain = plugin->chain_plug->chain(); From 749cea8cf39bf5e6447e2b5aadb7bc84f0153f10 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Wed, 17 Jun 2020 13:04:26 -0400 Subject: [PATCH 06/17] Remove many uses of has_value() on std::optional. --- libraries/chain/authorization_manager.cpp | 6 +-- libraries/chain/block_log.cpp | 2 +- libraries/chain/controller.cpp | 46 ++++++++-------- .../include/eosio/chain/abi_serializer.hpp | 4 +- .../include/eosio/chain/authority_checker.hpp | 2 +- libraries/chain/resource_limits.cpp | 4 +- libraries/fc/include/fc/io/raw.hpp | 4 +- libraries/fc/include/fc/reflect/variant.hpp | 2 +- libraries/fc/include/fc/variant.hpp | 2 +- libraries/fc/src/filesystem.cpp | 4 +- libraries/fc/src/log/gelf_appender.cpp | 4 +- libraries/fc/src/log/logger_config.cpp | 4 +- libraries/fc/src/network/http/http_client.cpp | 4 +- libraries/fc/src/network/url.cpp | 14 ++--- libraries/rodeos/embedded_rodeos.cpp | 2 +- libraries/rodeos/include/eosio/key_value.hpp | 2 +- .../eosio/state_history/serialization.hpp | 4 +- libraries/testing/tester.cpp | 12 ++--- plugins/chain_plugin/chain_plugin.cpp | 24 ++++----- plugins/history_plugin/history_plugin.cpp | 6 +-- plugins/net_plugin/net_plugin.cpp | 16 +++--- plugins/producer_plugin/producer_plugin.cpp | 14 ++--- .../eosio/trace_api/request_handler.hpp | 2 +- plugins/trace_api_plugin/store_provider.cpp | 2 +- .../trace_api_plugin/test/test_trace_file.cpp | 10 ++-- programs/cleos/main.cpp | 10 ++-- programs/eosio-tester/main.cpp | 2 +- unittests/api_tests.cpp | 12 ++--- unittests/chain_tests.cpp | 2 +- unittests/forked_tests.cpp | 4 +- unittests/misc_tests.cpp | 2 +- unittests/protocol_feature_tests.cpp | 54 +++++++++---------- unittests/state_history_tests.cpp | 4 +- unittests/whitelist_blacklist_tests.cpp | 4 +- 34 files changed, 145 insertions(+), 145 deletions(-) diff --git a/libraries/chain/authorization_manager.cpp b/libraries/chain/authorization_manager.cpp index 135aed6ed14..ebdbb11a158 100644 --- a/libraries/chain/authorization_manager.cpp +++ b/libraries/chain/authorization_manager.cpp @@ -319,7 +319,7 @@ namespace eosio { namespace chain { try { std::optional linked_permission = lookup_linked_permission(authorizer_account, scope, act_name); - if( !linked_permission.has_value() ) + if( !linked_permission ) return config::active_name; if( *linked_permission == config::eosio_any_name ) @@ -397,7 +397,7 @@ namespace eosio { namespace chain { const auto linked_permission_name = lookup_minimum_permission(link.account, link.code, link.type); - if( !linked_permission_name.has_value() ) // if action is linked to eosio.any permission + if( !linked_permission_name ) // if action is linked to eosio.any permission return; EOS_ASSERT( get_permission(auth).satisfies( get_permission({link.account, *linked_permission_name}), @@ -418,7 +418,7 @@ namespace eosio { namespace chain { "the owner of the linked permission needs to be the actor of the declared authorization" ); const auto unlinked_permission_name = lookup_linked_permission(unlink.account, unlink.code, unlink.type); - EOS_ASSERT( unlinked_permission_name.has_value(), transaction_exception, + EOS_ASSERT( unlinked_permission_name, transaction_exception, "cannot unlink non-existent permission link of account '${account}' for actions matching '${code}::${action}'", ("account", unlink.account)("code", unlink.code)("action", unlink.type) ); diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index f4dd632cd5b..6cef49b1683 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -657,7 +657,7 @@ namespace eosio { namespace chain { buffer = pack(b, segment_compression); } else { auto block_ptr = b.to_signed_block_v0(); - EOS_ASSERT(block_ptr.has_value(), block_log_append_fail, "Unable to convert block to legacy format"); + EOS_ASSERT(block_ptr, block_log_append_fail, "Unable to convert block to legacy format"); EOS_ASSERT(segment_compression == packed_transaction::cf_compression_type::none, block_log_append_fail, "the compression must be \"none\" for legacy format"); buffer = fc::raw::pack(*block_ptr); diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index c8b040e677c..adb54f67541 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -962,7 +962,7 @@ struct controller_impl { if (std::clamp(header.version, v2::minimum_version, v2::maximum_version) == header.version ) { std::optional genesis = extract_legacy_genesis_state(*snapshot, header.version); - EOS_ASSERT( genesis.has_value(), snapshot_exception, + EOS_ASSERT( genesis, snapshot_exception, "Snapshot indicates chain_snapshot_header version 2, but does not contain a genesis_state. " "It must be corrupted."); snapshot->read_section([&db=this->db,gs_chain_id=genesis->compute_chain_id()]( auto §ion ) { @@ -1509,7 +1509,7 @@ struct controller_impl { try { const transaction& trn = trx->packed_trx()->get_transaction(); if( trx->implicit ) { - EOS_ASSERT( !explicit_net_usage_words.has_value(), transaction_exception, "NET usage cannot be explicitly set for implicit transactions" ); + EOS_ASSERT( !explicit_net_usage_words, transaction_exception, "NET usage cannot be explicitly set for implicit transactions" ); trx_context.init_for_implicit_trx(); trx_context.enforce_whiteblacklist = false; } else { @@ -1597,7 +1597,7 @@ struct controller_impl { controller::block_status s, const std::optional& producer_block_id ) { - EOS_ASSERT( !pending.has_value(), block_validate_exception, "pending block already exists" ); + EOS_ASSERT( !pending, block_validate_exception, "pending block already exists" ); if (auto dm_logger = get_deep_mind_logger()) { // The head block represents the block just before this one that is about to start, so add 1 to get this block num @@ -1696,13 +1696,13 @@ struct controller_impl { const auto& gpo = self.get_global_properties(); - if( gpo.proposed_schedule_block_num.has_value() && // if there is a proposed schedule that was proposed in a block ... + if( gpo.proposed_schedule_block_num && // if there is a proposed schedule that was proposed in a block ... ( *gpo.proposed_schedule_block_num <= pbhs.dpos_irreversible_blocknum ) && // ... that has now become irreversible ... pbhs.prev_pending_schedule.schedule.producers.size() == 0 // ... and there was room for a new pending schedule prior to any possible promotion ) { // Promote proposed schedule to pending schedule. - if( !replay_head_time.has_value() ) { + if( !replay_head_time ) { ilog( "promoting proposed schedule (set in block ${proposed_num}) to pending; current block: ${n} lib: ${lib} schedule: ${schedule} ", ("proposed_num", *gpo.proposed_schedule_block_num)("n", pbhs.block_num) ("lib", pbhs.dpos_irreversible_blocknum) @@ -1751,7 +1751,7 @@ struct controller_impl { void finalize_block() { - EOS_ASSERT( pending.has_value(), block_validate_exception, "it is not valid to finalize when there is no pending block"); + EOS_ASSERT( pending, block_validate_exception, "it is not valid to finalize when there is no pending block"); EOS_ASSERT( pending->_block_stage.contains(), block_validate_exception, "already called finalize_block"); try { @@ -1833,7 +1833,7 @@ struct controller_impl { EOS_ASSERT( bsp == head, fork_database_exception, "committed block did not become the new head in fork database"); } - if( !replay_head_time.has_value() && read_mode != db_read_mode::IRREVERSIBLE ) { + if( !replay_head_time && read_mode != db_read_mode::IRREVERSIBLE ) { reversible_blocks.create( [&]( auto& ubo ) { ubo.blocknum = bsp->block_num; ubo.set_block( bsp->block ); @@ -2067,7 +2067,7 @@ struct controller_impl { const forked_branch_callback& forked_branch_cb, const trx_meta_cache_lookup& trx_lookup ) { controller::block_status s = controller::block_status::complete; - EOS_ASSERT(!pending.has_value(), block_validate_exception, "it is not valid to push a block when there is a pending block"); + EOS_ASSERT(!pending, block_validate_exception, "it is not valid to push a block when there is a pending block"); auto reset_prod_light_validation = fc::make_scoped_exit([old_value=trusted_producer_light_validation, this]() { trusted_producer_light_validation = old_value; @@ -2105,7 +2105,7 @@ struct controller_impl { self.validate_db_available_size(); self.validate_reversible_available_size(); - EOS_ASSERT(!pending.has_value(), block_validate_exception, "it is not valid to push a block when there is a pending block"); + EOS_ASSERT(!pending, block_validate_exception, "it is not valid to push a block when there is a pending block"); try { EOS_ASSERT( b, block_validate_exception, "trying to push empty block" ); @@ -2705,7 +2705,7 @@ void controller::start_block( block_timestamp_type when, uint16_t confirm_block_ { validate_db_available_size(); - EOS_ASSERT( !my->pending.has_value(), block_validate_exception, "pending block already exists" ); + EOS_ASSERT( !my->pending, block_validate_exception, "pending block already exists" ); vector new_protocol_feature_activations; @@ -2898,7 +2898,7 @@ account_name controller::fork_db_pending_head_block_producer()const { } time_point controller::pending_block_time()const { - EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->header.timestamp; @@ -2907,7 +2907,7 @@ time_point controller::pending_block_time()const { } account_name controller::pending_block_producer()const { - EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->header.producer; @@ -2916,7 +2916,7 @@ account_name controller::pending_block_producer()const { } const block_signing_authority& controller::pending_block_signing_authority()const { - EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); if( my->pending->_block_stage.contains() ) return my->pending->_block_stage.get()._block_state->valid_block_signing_authority; @@ -2925,12 +2925,12 @@ const block_signing_authority& controller::pending_block_signing_authority()cons } std::optional controller::pending_producer_block_id()const { - EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); return my->pending->_producer_block_id; } const deque& controller::get_pending_trx_receipts()const { - EOS_ASSERT( my->pending.has_value(), block_validate_exception, "no pending block" ); + EOS_ASSERT( my->pending, block_validate_exception, "no pending block" ); return my->pending->get_trx_receipts(); } @@ -3030,7 +3030,7 @@ sha256 controller::calculate_integrity_hash()const { try { } FC_LOG_AND_RETHROW() } void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) const { - EOS_ASSERT( !my->pending.has_value(), block_validate_exception, "cannot take a consistent snapshot with a pending block" ); + EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" ); return my->add_to_snapshot(snapshot); } @@ -3042,7 +3042,7 @@ int64_t controller::set_proposed_producers( vector producers return -1; } - if( gpo.proposed_schedule_block_num.has_value() ) { + if( gpo.proposed_schedule_block_num ) { if( *gpo.proposed_schedule_block_num != cur_block_num ) return -1; // there is already a proposed schedule set in a previous block, wait for it to become pending @@ -3086,7 +3086,7 @@ int64_t controller::set_proposed_producers( vector producers } const producer_authority_schedule& controller::active_producers()const { - if( !(my->pending.has_value()) ) + if( !(my->pending) ) return my->head->active_schedule; if( my->pending->_block_stage.contains() ) @@ -3096,7 +3096,7 @@ const producer_authority_schedule& controller::active_producers()const { } const producer_authority_schedule& controller::pending_producers()const { - if( !(my->pending.has_value()) ) + if( !(my->pending) ) return my->head->pending_schedule.schedule; if( my->pending->_block_stage.contains() ) @@ -3119,14 +3119,14 @@ const producer_authority_schedule& controller::pending_producers()const { std::optional controller::proposed_producers()const { const auto& gpo = get_global_properties(); - if( !gpo.proposed_schedule_block_num.has_value() ) + if( !gpo.proposed_schedule_block_num ) return std::optional(); return producer_authority_schedule::from_shared(gpo.proposed_schedule); } bool controller::light_validation_allowed() const { - if (!my->pending.has_value() || my->in_trx_requiring_checks) { + if (!my->pending || my->in_trx_requiring_checks) { return false; } @@ -3235,7 +3235,7 @@ bool controller::is_building_block()const { } bool controller::is_producing_block()const { - if( !my->pending.has_value() ) return false; + if( !my->pending ) return false; return (my->pending->_block_status == block_status::incomplete); } @@ -3401,7 +3401,7 @@ std::optional controller::convert_exception_to_error_code( const fc::e if( e_ptr == nullptr ) return {}; - if( !e_ptr->error_code.has_value() ) return static_cast(system_error_code::generic_system_error); + if( !e_ptr->error_code ) return static_cast(system_error_code::generic_system_error); return e_ptr->error_code; } diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index d5844f7e4b3..e08dfdaa538 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -442,7 +442,7 @@ namespace impl { try { auto abi = resolver(act.account); - if (abi.has_value()) { + if (abi) { auto type = abi->get_action_type(act.name); if (!type.empty()) { try { @@ -812,7 +812,7 @@ namespace impl { valid_empty_data = act.data.empty(); } else if ( data.is_object() ) { auto abi = resolver(act.account); - if (abi.has_value()) { + if (abi) { auto type = abi->get_action_type(act.name); if (!type.empty()) { variant_to_binary_context _ctx(*abi, ctx, type); diff --git a/libraries/chain/include/eosio/chain/authority_checker.hpp b/libraries/chain/include/eosio/chain/authority_checker.hpp index 6b380f68196..16a3f954090 100644 --- a/libraries/chain/include/eosio/chain/authority_checker.hpp +++ b/libraries/chain/include/eosio/chain/authority_checker.hpp @@ -220,7 +220,7 @@ namespace detail { uint32_t operator()(const permission_level_weight& permission) { auto status = authority_checker::permission_status_in_cache( cached_permissions, permission.permission ); - if( !status.has_value() ) { + if( !status ) { if( recursion_depth < checker.recursion_depth_limit ) { bool r = false; typename permission_cache_type::iterator itr = cached_permissions.end(); diff --git a/libraries/chain/resource_limits.cpp b/libraries/chain/resource_limits.cpp index 4b0ec69db90..3c8bcc90fb9 100644 --- a/libraries/chain/resource_limits.cpp +++ b/libraries/chain/resource_limits.cpp @@ -492,7 +492,7 @@ resource_limits_manager::get_account_cpu_limit_ex( const account_name& name, uin arl.max = impl::downgrade_cast(max_user_use_in_window); arl.last_usage_update_time = block_timestamp_type(usage.cpu_usage.last_ordinal); arl.current_used = arl.used; - if ( current_time.has_value() ) { + if ( current_time ) { if (current_time->slot > usage.cpu_usage.last_ordinal) { auto history_usage = usage.cpu_usage; history_usage.add(0, current_time->slot, window_size); @@ -553,7 +553,7 @@ resource_limits_manager::get_account_net_limit_ex( const account_name& name, uin arl.max = impl::downgrade_cast(max_user_use_in_window); arl.last_usage_update_time = block_timestamp_type(usage.net_usage.last_ordinal); arl.current_used = arl.used; - if ( current_time.has_value() ) { + if ( current_time ) { if (current_time->slot > usage.net_usage.last_ordinal) { auto history_usage = usage.net_usage; history_usage.add(0, current_time->slot, window_size); diff --git a/libraries/fc/include/fc/io/raw.hpp b/libraries/fc/include/fc/io/raw.hpp index 834e720d164..41a4dc1de05 100644 --- a/libraries/fc/include/fc/io/raw.hpp +++ b/libraries/fc/include/fc/io/raw.hpp @@ -268,8 +268,8 @@ namespace fc { // optional template void pack( Stream& s, const std::optional& v ) { - fc::raw::pack( s, v.has_value() ); - if( v.has_value() ) fc::raw::pack( s, *v ); + fc::raw::pack( s, v ); + if( v ) fc::raw::pack( s, *v ); } template diff --git a/libraries/fc/include/fc/reflect/variant.hpp b/libraries/fc/include/fc/reflect/variant.hpp index c3089b4cb14..15b4e309b1f 100644 --- a/libraries/fc/include/fc/reflect/variant.hpp +++ b/libraries/fc/include/fc/reflect/variant.hpp @@ -27,7 +27,7 @@ namespace fc template void add( mutable_variant_object& vo, const char* name, const std::optional& v )const { - if( v.has_value() ) + if( v ) vo(name,*v); } template diff --git a/libraries/fc/include/fc/variant.hpp b/libraries/fc/include/fc/variant.hpp index f261076da90..aecec202616 100644 --- a/libraries/fc/include/fc/variant.hpp +++ b/libraries/fc/include/fc/variant.hpp @@ -351,7 +351,7 @@ namespace fc explicit variant( const std::optional& v ) { memset( this, 0, sizeof(*this) ); - if( v.has_value() ) *this = variant(*v); + if( v ) *this = variant(*v); } template diff --git a/libraries/fc/src/filesystem.cpp b/libraries/fc/src/filesystem.cpp index a32cbae20e8..1b8df2018cf 100644 --- a/libraries/fc/src/filesystem.cpp +++ b/libraries/fc/src/filesystem.cpp @@ -421,7 +421,7 @@ namespace fc { const fc::path& temp_file_base::path() const { - if (!_path.has_value()) + if (!_path) { FC_THROW( "Temporary directory has been released." ); } @@ -430,7 +430,7 @@ namespace fc { void temp_file_base::remove() { - if (_path.has_value()) + if (_path) { try { diff --git a/libraries/fc/src/log/gelf_appender.cpp b/libraries/fc/src/log/gelf_appender.cpp index 74e2e4b444a..cc180773b53 100644 --- a/libraries/fc/src/log/gelf_appender.cpp +++ b/libraries/fc/src/log/gelf_appender.cpp @@ -60,7 +60,7 @@ namespace fc catch (...) { } - if (!my->gelf_endpoint.has_value()) + if (!my->gelf_endpoint) { // couldn't parse as a numeric ip address, try resolving as a DNS name. // This can yield, so don't do it in the catch block above @@ -100,7 +100,7 @@ namespace fc void gelf_appender::log(const log_message& message) { - if (!my->gelf_endpoint.has_value()) + if (!my->gelf_endpoint) return; log_context context = message.get_context(); diff --git a/libraries/fc/src/log/logger_config.cpp b/libraries/fc/src/log/logger_config.cpp index 4d2ef776a89..58690967160 100644 --- a/libraries/fc/src/log/logger_config.cpp +++ b/libraries/fc/src/log/logger_config.cpp @@ -81,11 +81,11 @@ namespace fc { auto lgr = log_config::get().logger_map[cfg.loggers[i].name]; // TODO: finish configure logger here... - if( cfg.loggers[i].parent.has_value() ) { + if( cfg.loggers[i].parent ) { lgr.set_parent( log_config::get().logger_map[*cfg.loggers[i].parent] ); } lgr.set_name(cfg.loggers[i].name); - if( cfg.loggers[i].level.has_value() ) lgr.set_log_level( *cfg.loggers[i].level ); + if( cfg.loggers[i].level ) lgr.set_log_level( *cfg.loggers[i].level ); for( auto a = cfg.loggers[i].appenders.begin(); a != cfg.loggers[i].appenders.end(); ++a ){ diff --git a/libraries/fc/src/network/http/http_client.cpp b/libraries/fc/src/network/http/http_client.cpp index cf1e07a0417..0718ef30ae5 100644 --- a/libraries/fc/src/network/http/http_client.cpp +++ b/libraries/fc/src/network/http/http_client.cpp @@ -158,7 +158,7 @@ class http_client_impl { } host_key url_to_host_key( const url& dest ) { - FC_ASSERT(dest.host().has_value(), "Provided URL has no host"); + FC_ASSERT(dest.host(), "Provided URL has no host"); uint16_t port = 80; if (dest.port()) { port = *dest.port(); @@ -316,7 +316,7 @@ class http_client_impl { variant post_sync(const url& dest, const variant& payload, const fc::time_point& _deadline) { static const deadline_type epoch(boost::gregorian::date(1970, 1, 1)); auto deadline = epoch + boost::posix_time::microseconds(_deadline.time_since_epoch().count()); - FC_ASSERT(dest.host().has_value(), "No host set on URL"); + FC_ASSERT(dest.host(), "No host set on URL"); string path = dest.path() ? dest.path()->generic_string() : "/"; if (dest.query()) { diff --git a/libraries/fc/src/network/url.cpp b/libraries/fc/src/network/url.cpp index 29c24797457..448fd263f14 100644 --- a/libraries/fc/src/network/url.cpp +++ b/libraries/fc/src/network/url.cpp @@ -60,7 +60,7 @@ namespace fc _path = fc::path( "/" ) / _lpath; #endif std::getline( ss, _largs ); - if( _args.has_value() && _args->size() ) + if( _args && _args->size() ) { // TODO: args = fc::move(_args); _query = fc::move(_largs); @@ -91,17 +91,17 @@ namespace fc { std::stringstream ss; ss<_proto<<"://"; - if( my->_user.has_value() ) { + if( my->_user ) { ss << *my->_user; - if( my->_pass.has_value() ) { + if( my->_pass ) { ss<<":"<<*my->_pass; } ss<<"@"; } - if( my->_host.has_value() ) ss<<*my->_host; - if( my->_port.has_value() ) ss<<":"<<*my->_port; - if( my->_path.has_value() ) ss<_path->generic_string(); - if( my->_query.has_value() ) ss<<"?"<<*my->_query; + if( my->_host ) ss<<*my->_host; + if( my->_port ) ss<<":"<<*my->_port; + if( my->_path ) ss<_path->generic_string(); + if( my->_query ) ss<<"?"<<*my->_query; // if( my->_args ) ss<<"?"<<*my->_args; return ss.str(); } diff --git a/libraries/rodeos/embedded_rodeos.cpp b/libraries/rodeos/embedded_rodeos.cpp index 6864fd7ff70..f5f560624d1 100644 --- a/libraries/rodeos/embedded_rodeos.cpp +++ b/libraries/rodeos/embedded_rodeos.cpp @@ -253,7 +253,7 @@ rodeos_bool rodeos_query_transaction(rodeos_error* error, rodeos_query_handler* auto thread_state = handler->state_cache.get_state(); eosio::ship_protocol::transaction_trace tt; - if (snapshot->snap.has_value()) { + if (snapshot->snap) { tt = query_send_transaction(*thread_state, snapshot->partition->contract_kv_prefix, trx, snapshot->snap->snapshot(), memory, true); } else { diff --git a/libraries/rodeos/include/eosio/key_value.hpp b/libraries/rodeos/include/eosio/key_value.hpp index 6f845e4a432..985d3adfb8a 100644 --- a/libraries/rodeos/include/eosio/key_value.hpp +++ b/libraries/rodeos/include/eosio/key_value.hpp @@ -543,7 +543,7 @@ class kv_table { T operator[](const key_type& key) const { auto opt = get(key); - eosio::check(opt.has_value(), __FILE__ ":" + std::to_string(__LINE__) + " Key not found in `[]`"); + eosio::check(opt, __FILE__ ":" + std::to_string(__LINE__) + " Key not found in `[]`"); return *opt; } diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index 186068b2270..7b86faa716d 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -109,7 +109,7 @@ void history_pack_big_bytes(ST& ds, const eosio::chain::bytes& v) { template void history_pack_big_bytes(ST& ds, const std::optional& v) { - fc::raw::pack(ds, v.has_value()); + fc::raw::pack(ds, v); if (v) history_pack_big_bytes(ds, *v); } @@ -544,7 +544,7 @@ ST& operator<<(ST& ds, const history_serial_wrapper inline std::optional cap_error_code(const std::optional& error_code) { std::optional result; - if (!error_code.has_value()) + if (!error_code) return result; const uint64_t upper_limit = static_cast(eosio::chain::system_error_code::generic_system_error); diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index e5f92b163db..9d5cede53ea 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -117,7 +117,7 @@ namespace eosio { namespace testing { ( builtin_protocol_feature_t codename ) -> digest_type { auto res = visited_builtins.emplace( codename, std::optional() ); if( !res.second ) { - EOS_ASSERT( res.first->second.has_value(), protocol_feature_exception, + EOS_ASSERT( res.first->second, protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies" ); return *res.first->second; @@ -194,7 +194,7 @@ namespace eosio { namespace testing { auto schedule_preactivate_protocol_feature = [&]() { auto preactivate_feature_digest = pfm.get_builtin_digest(builtin_protocol_feature_t::preactivate_feature); - FC_ASSERT( preactivate_feature_digest.has_value(), "PREACTIVATE_FEATURE not found" ); + FC_ASSERT( preactivate_feature_digest, "PREACTIVATE_FEATURE not found" ); schedule_protocol_features_wo_preactivation( { *preactivate_feature_digest } ); }; @@ -270,9 +270,9 @@ namespace eosio { namespace testing { } void base_tester::open( protocol_feature_set&& pfs, std::optional expected_chain_id, const std::function& lambda ) { - if( !expected_chain_id.has_value() ) { + if( !expected_chain_id ) { expected_chain_id = controller::extract_chain_id_from_db( cfg.state_dir ); - if( !expected_chain_id.has_value() ) { + if( !expected_chain_id ) { if( fc::is_regular_file( cfg.blog.log_dir / "blocks.log" ) ) { expected_chain_id = block_log::extract_chain_id( cfg.blog.log_dir ); } else { @@ -1168,7 +1168,7 @@ namespace eosio { namespace testing { [&pfm, &pfs, current_block_num, current_block_time, &preactivation_set, &preactivations, &add_digests] ( const digest_type& feature_digest ) { const auto& pf = pfs.get_protocol_feature( feature_digest ); - FC_ASSERT( pf.builtin_feature.has_value(), "called add_digests on a non-builtin protocol feature" ); + FC_ASSERT( pf.builtin_feature, "called add_digests on a non-builtin protocol feature" ); if( !pf.enabled || pf.earliest_allowed_activation_time > current_block_time || pfm.is_builtin_activated( *pf.builtin_feature, current_block_num ) ) return; @@ -1184,7 +1184,7 @@ namespace eosio { namespace testing { for( const auto& f : builtin_protocol_feature_codenames ) { auto digest = pfs.get_builtin_digest( f.first ); - if( !digest.has_value() ) continue; + if( !digest ) continue; add_digests( *digest ); } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index ca9f7391f9b..50d1a81faa1 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -510,7 +510,7 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul auto f = read_builtin_protocol_feature( file_path ); - if( !f.has_value() ) continue; + if( !f ) continue; auto res = found_builtin_protocol_features.emplace( f->get_codename(), file_path ); @@ -591,7 +591,7 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul ( builtin_protocol_feature_t codename ) -> digest_type { auto res = visited_builtins.emplace( codename, std::optional() ); if( !res.second ) { - EOS_ASSERT( res.first->second.has_value(), protocol_feature_exception, + EOS_ASSERT( res.first->second, protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies" ); return *res.first->second; @@ -820,7 +820,7 @@ void chain_plugin::plugin_initialize(const variables_map& options) { if( fc::exists( my->blocks_dir / "blocks.log" )) { gs = block_log::extract_genesis_state( my->blocks_dir ); - EOS_ASSERT( gs.has_value(), + EOS_ASSERT( gs, plugin_config_exception, "Block log at '${path}' does not contain a genesis state, it only has the chain-id.", ("path", (my->blocks_dir / "blocks.log").generic_string()) @@ -1052,14 +1052,14 @@ void chain_plugin::plugin_initialize(const variables_map& options) { "--genesis-timestamp is only valid if also passed in with --genesis-json"); } - if( !chain_id.has_value() ) { + if( !chain_id ) { if( my->genesis ) { // Uninitialized state database and genesis state extracted from block log chain_id = my->genesis->compute_chain_id(); } else { // Uninitialized state database and no genesis state provided - EOS_ASSERT( !block_log_chain_id.has_value(), plugin_config_exception, + EOS_ASSERT( !block_log_chain_id, plugin_config_exception, "Genesis state is necessary to initialize fresh blockchain state but genesis state could not be " "found in the blocks log. Please either load from snapshot or find a blocks log that starts " "from genesis." @@ -1938,7 +1938,7 @@ vector read_only::get_currency_balance( const read_only::get_currency_bal EOS_ASSERT( cursor.get_symbol().valid(), chain::asset_type_exception, "Invalid asset"); - if( !p.symbol.has_value() || boost::iequals(cursor.symbol_name(), *p.symbol) ) { + if( !p.symbol || boost::iequals(cursor.symbol_name(), *p.symbol) ) { results.emplace_back(cursor); } @@ -2183,7 +2183,7 @@ fc::variant read_only::get_block(const read_only::get_block_params& params) cons block_num = fc::to_uint64(params.block_num_or_id); } catch( ... ) {} - if( block_num.has_value() ) { + if( block_num ) { block = db.fetch_block_by_number( *block_num ); } else { try { @@ -2244,7 +2244,7 @@ fc::variant read_only::get_block_header_state(const get_block_header_state_param block_num = fc::to_uint64(params.block_num_or_id); } catch( ... ) {} - if( block_num.has_value() ) { + if( block_num ) { b = db.fetch_block_state_by_number(*block_num); } else { try { @@ -2503,7 +2503,7 @@ read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params& result.abi_hash = fc::sha256::hash( accnt_obj.abi.data(), accnt_obj.abi.size() ); if( accnt_metadata_obj.code_hash != digest_type() ) result.code_hash = accnt_metadata_obj.code_hash; - if( !params.abi_hash.has_value() || *params.abi_hash != result.abi_hash ) + if( !params.abi_hash || *params.abi_hash != result.abi_hash ) result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}}; return result; @@ -2531,11 +2531,11 @@ read_only::get_account_results read_only::get_account( const get_account_params& uint32_t greylist_limit = db.is_resource_greylisted(result.account_name) ? 1 : config::maximum_elastic_resource_multiplier; const block_timestamp_type current_usage_time (db.head_block_time()); result.net_limit.set( rm.get_account_net_limit_ex( result.account_name, greylist_limit, current_usage_time).first ); - if ( result.net_limit.last_usage_update_time.has_value() && (result.net_limit.last_usage_update_time->slot == 0) ) { // account has no action yet + if ( result.net_limit.last_usage_update_time && (result.net_limit.last_usage_update_time->slot == 0) ) { // account has no action yet result.net_limit.last_usage_update_time = accnt_obj.creation_date; } result.cpu_limit.set( rm.get_account_cpu_limit_ex( result.account_name, greylist_limit, current_usage_time).first ); - if ( result.cpu_limit.last_usage_update_time.has_value() && (result.cpu_limit.last_usage_update_time->slot == 0) ) { // account has no action yet + if ( result.cpu_limit.last_usage_update_time && (result.cpu_limit.last_usage_update_time->slot == 0) ) { // account has no action yet result.cpu_limit.last_usage_update_time = accnt_obj.creation_date; } result.ram_usage = rm.get_account_ram_usage( result.account_name ); @@ -2569,7 +2569,7 @@ read_only::get_account_results read_only::get_account( const get_account_params& auto core_symbol = extract_core_symbol(); - if (params.expected_core_symbol.has_value()) + if (params.expected_core_symbol) core_symbol = *(params.expected_core_symbol); const auto* t_id = d.find(boost::make_tuple( token_code, params.account_name, N(accounts) )); diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 356d9ac6983..d426ad04304 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -278,11 +278,11 @@ namespace eosio { } void on_applied_transaction( const transaction_trace_ptr& trace ) { - if( !trace->receipt.has_value() || (trace->receipt->status != transaction_receipt_header::executed && + if( !trace->receipt || (trace->receipt->status != transaction_receipt_header::executed && trace->receipt->status != transaction_receipt_header::soft_fail) ) return; for( const auto& atrace : trace->action_traces ) { - if( !atrace.receipt.has_value() ) continue; + if( !atrace.receipt ) continue; on_action_trace( atrace ); } } @@ -468,7 +468,7 @@ namespace eosio { bool in_history = (itr != idx.end() && txn_id_matched(itr->trx_id) ); - if( !in_history && !p.block_num_hint.has_value() ) { + if( !in_history && !p.block_num_hint ) { EOS_THROW(tx_not_found, "Transaction ${id} not found in history and no block hint was given", ("id",p.id)); } diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index a01be768edc..2f519af18ca 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -1013,7 +1013,7 @@ namespace eosio { } void connection::blk_send_branch_impl( uint32_t msg_head_num, uint32_t lib_num, uint32_t head_num ) { - if( !peer_requested.has_value() ) { + if( !peer_requested ) { auto last = msg_head_num != 0 ? msg_head_num : lib_num; peer_requested = peer_sync_state( last+1, head_num, last ); } else { @@ -1174,7 +1174,7 @@ namespace eosio { } bool connection::enqueue_sync_block() { - if( !peer_requested.has_value() ) { + if( !peer_requested ) { return false; } else { fc_dlog( logger, "enqueue sync block ${num}", ("num", peer_requested->last + 1) ); @@ -1277,7 +1277,7 @@ namespace eosio { } else { if( !send_buffer_v0 ) { const auto v0 = sb->to_signed_block_v0(); - if( !v0.has_value() ) return send_buffer_v0; + if( !v0 ) return send_buffer_v0; send_buffer_v0 = create_send_buffer( *v0 ); } return send_buffer_v0; @@ -2184,7 +2184,7 @@ namespace eosio { block_id_type bid; { std::lock_guard g_c_conn( c->conn_mtx ); - if( !c->last_req.has_value() ) { + if( !c->last_req ) { return; } fc_wlog( logger, "failed to fetch from ${p}", ("p", c->peer_address()) ); @@ -2648,14 +2648,14 @@ namespace eosio { std::shared_ptr trx; fc::raw::unpack( ds, trx ); ptr = std::move( trx ); - - if (ptr && trx_id.has_value() && *trx_id != ptr->id()) { + + if (ptr && trx_id && *trx_id != ptr->id()) { my_impl->producer_plug->log_failed_transaction(*trx_id, "Provided trx_id does not match provided packed_transaction"); EOS_ASSERT(false, transaction_id_type_exception, "Provided trx_id does not match provided packed_transaction" ); } - if( !trx_id.has_value() ) { + if( !trx_id ) { if (trx_in_progress_sz > def_max_trx_in_progress_size) { report_dropping_trx(ptr->id(), trx_in_progress_sz); return true; @@ -3068,7 +3068,7 @@ namespace eosio { fc_dlog( logger, "bad packed_transaction : ${m}", ("m", result.get()->what()) ); } else { const transaction_trace_ptr& trace = result.get(); - if( !trace->except.has_value() ) { + if( !trace->except ) { fc_dlog( logger, "chain accepted transaction, bcast ${id}", ("id", trace->id) ); } else { fc_elog( logger, "bad packed_transaction : ${m}", ("m", trace->except->what())); diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 85db02c0b39..f9df7ab9beb 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1056,12 +1056,12 @@ producer_plugin::whitelist_blacklist producer_plugin::get_whitelist_blacklist() void producer_plugin::set_whitelist_blacklist(const producer_plugin::whitelist_blacklist& params) { chain::controller& chain = my->chain_plug->chain(); - if(params.actor_whitelist.has_value()) chain.set_actor_whitelist(*params.actor_whitelist); - if(params.actor_blacklist.has_value()) chain.set_actor_blacklist(*params.actor_blacklist); - if(params.contract_whitelist.has_value()) chain.set_contract_whitelist(*params.contract_whitelist); - if(params.contract_blacklist.has_value()) chain.set_contract_blacklist(*params.contract_blacklist); - if(params.action_blacklist.has_value()) chain.set_action_blacklist(*params.action_blacklist); - if(params.key_blacklist.has_value()) chain.set_key_blacklist(*params.key_blacklist); + if(params.actor_whitelist) chain.set_actor_whitelist(*params.actor_whitelist); + if(params.actor_blacklist) chain.set_actor_blacklist(*params.actor_blacklist); + if(params.contract_whitelist) chain.set_contract_whitelist(*params.contract_whitelist); + if(params.contract_blacklist) chain.set_contract_blacklist(*params.contract_blacklist); + if(params.action_blacklist) chain.set_action_blacklist(*params.action_blacklist); + if(params.key_blacklist) chain.set_key_blacklist(*params.key_blacklist); } producer_plugin::integrity_hash_information producer_plugin::get_integrity_hash() const { @@ -1942,7 +1942,7 @@ std::optional producer_plugin_impl::calculate_producer_wake_up_t } } } - if( !wake_up_time.has_value() ) { + if( !wake_up_time ) { fc_dlog(_log, "Not Scheduling Speculative/Production, no local producers had valid wake up times"); } diff --git a/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp b/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp index fc1319b8c64..3e66b2c82bf 100644 --- a/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp +++ b/plugins/trace_api_plugin/include/eosio/trace_api/request_handler.hpp @@ -37,7 +37,7 @@ namespace eosio::trace_api { */ fc::variant get_block_trace( uint32_t block_height, const yield_function& yield = {}) { auto data = logfile_provider.get_block(block_height, yield); - if (!data.has_value()) { + if (!data) { return {}; } diff --git a/plugins/trace_api_plugin/store_provider.cpp b/plugins/trace_api_plugin/store_provider.cpp index 29f494df954..a540db24dd7 100644 --- a/plugins/trace_api_plugin/store_provider.cpp +++ b/plugins/trace_api_plugin/store_provider.cpp @@ -77,7 +77,7 @@ namespace eosio::trace_api { return get_block_t{}; } std::optional entry = read_data_log(block_height, *trace_offset); - if (!entry.has_value()) { + if (!entry) { return get_block_t{}; } return std::make_tuple( entry.value(), irreversible ); diff --git a/plugins/trace_api_plugin/test/test_trace_file.cpp b/plugins/trace_api_plugin/test/test_trace_file.cpp index 826945cb177..c1f6fee077a 100644 --- a/plugins/trace_api_plugin/test/test_trace_file.cpp +++ b/plugins/trace_api_plugin/test/test_trace_file.cpp @@ -765,11 +765,11 @@ BOOST_AUTO_TEST_SUITE(slice_tests) BOOST_REQUIRE(first_offset < offset); std::optional bt_data = sp.read_data_log(block_nums[0], block_offsets[0]); - BOOST_REQUIRE(bt_data.has_value()); + BOOST_REQUIRE(bt_data); BOOST_REQUIRE_EQUAL(*bt_data, bt); bt_data = sp.read_data_log(block_nums[1], block_offsets[1]); - BOOST_REQUIRE(bt_data.has_value()); + BOOST_REQUIRE(bt_data); BOOST_REQUIRE_EQUAL(*bt_data, bt2); block_nums.clear(); @@ -817,7 +817,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(block1.has_value()); + BOOST_REQUIRE(block1); BOOST_REQUIRE(std::get<1>(*block1)); const auto block1_bt = std::get<0>(*block1); BOOST_REQUIRE_EQUAL(block1_bt, bt); @@ -828,7 +828,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(block2.has_value()); + BOOST_REQUIRE(block2); BOOST_REQUIRE(!std::get<1>(*block2)); const auto block2_bt = std::get<0>(*block2); BOOST_REQUIRE_EQUAL(block2_bt, bt2); @@ -850,7 +850,7 @@ BOOST_AUTO_TEST_SUITE(slice_tests) throw yield_exception(""); } }); - BOOST_REQUIRE(!block2.has_value()); + BOOST_REQUIRE(!block2); } BOOST_AUTO_TEST_SUITE_END() diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index cddd7371b8c..4dbc2c9df32 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -522,7 +522,7 @@ void print_action( const fc::variant& at ) { bytes variant_to_bin( const account_name& account, const action_name& action, const fc::variant& action_args_var ) { auto abis = abi_serializer_resolver( account ); - FC_ASSERT( abis.has_value(), "No ABI found for ${contract}", ("contract", account)); + FC_ASSERT( abis, "No ABI found for ${contract}", ("contract", account)); auto action_type = abis->get_action_type( action ); FC_ASSERT( !action_type.empty(), "Unknown action ${action} in contract ${contract}", ("action", action)( "contract", account )); @@ -531,7 +531,7 @@ bytes variant_to_bin( const account_name& account, const action_name& action, co fc::variant bin_to_variant( const account_name& account, const action_name& action, const bytes& action_args) { auto abis = abi_serializer_resolver( account ); - FC_ASSERT( abis.has_value(), "No ABI found for ${contract}", ("contract", account)); + FC_ASSERT( abis, "No ABI found for ${contract}", ("contract", account)); auto action_type = abis->get_action_type( action ); FC_ASSERT( !action_type.empty(), "Unknown action ${action} in contract ${contract}", ("action", action)( "contract", account )); @@ -2213,7 +2213,7 @@ void get_account( const string& accountName, const string& coresym, bool json_fo asset staked; asset unstaking; - if( res.core_liquid_balance.has_value() ) { + if( res.core_liquid_balance ) { unstaking = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for unstaking asset. staked = asset( 0, res.core_liquid_balance->get_symbol() ); // Correct core symbol for staked asset. } @@ -2433,7 +2433,7 @@ void get_account( const string& accountName, const string& coresym, bool json_fo } } - if( res.core_liquid_balance.has_value() ) { + if( res.core_liquid_balance ) { std::cout << res.core_liquid_balance->get_symbol().name() << " balances: " << std::endl; std::cout << indent << std::left << std::setw(11) << "liquid:" << std::right << std::setw(18) << *res.core_liquid_balance << std::endl; @@ -2711,7 +2711,7 @@ int main( int argc, char** argv ) { } catch (...) { // error is handled in assertion below } - EOSC_ASSERT( block_num.has_value() && (*block_num > 0), "Invalid block num: ${block_num}", ("block_num", blockArg) ); + EOSC_ASSERT( block_num && (*block_num > 0), "Invalid block num: ${block_num}", ("block_num", blockArg) ); const auto arg = fc::variant_object("block_num", static_cast(*block_num)); std::cout << fc::json::to_pretty_string(call(get_block_info_func, arg)) << std::endl; } else { diff --git a/programs/eosio-tester/main.cpp b/programs/eosio-tester/main.cpp index eb47c23ef3f..2cab9434beb 100644 --- a/programs/eosio-tester/main.cpp +++ b/programs/eosio-tester/main.cpp @@ -141,7 +141,7 @@ protocol_feature_set make_protocol_feature_set() { [&pfs, &visited_builtins, &add_builtins](builtin_protocol_feature_t codename) -> digest_type { auto res = visited_builtins.emplace(codename, std::optional()); if (!res.second) { - EOS_ASSERT(res.first->second.has_value(), protocol_feature_exception, + EOS_ASSERT(res.first->second, protocol_feature_exception, "invariant failure: cycle found in builtin protocol feature dependencies"); return *res.first->second; } diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index f1695ca3f3f..a7d325d8eba 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -568,7 +568,7 @@ BOOST_AUTO_TEST_CASE(ram_billing_in_notify_tests) { try { chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); const auto& pfm = chain.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value); // testapi requires this - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); chain.preactivate_protocol_features( {*d} ); chain.produce_blocks(2); @@ -1570,7 +1570,7 @@ BOOST_AUTO_TEST_CASE(more_deferred_transaction_tests) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); chain.preactivate_protocol_features( {*d} ); chain.produce_block(); @@ -3080,11 +3080,11 @@ BOOST_FIXTURE_TEST_CASE(eosio_assert_code_tests, TESTER) { try { auto trace = CALL_TEST_FUNCTION_NO_THROW( *this, "test_action", "test_assert_code", fc::raw::pack((uint64_t)42) ); BOOST_REQUIRE( trace ); - BOOST_REQUIRE( trace->except.has_value() ); + BOOST_REQUIRE( trace->except ); BOOST_REQUIRE( trace->error_code ); BOOST_REQUIRE_EQUAL( *trace->error_code, 42 ); BOOST_REQUIRE_EQUAL( trace->action_traces.size(), 1 ); - BOOST_REQUIRE( trace->action_traces[0].except.has_value() ); + BOOST_REQUIRE( trace->action_traces[0].except ); BOOST_REQUIRE( trace->action_traces[0].error_code ); BOOST_REQUIRE_EQUAL( *trace->action_traces[0].error_code, 42 ); @@ -3108,11 +3108,11 @@ BOOST_FIXTURE_TEST_CASE(eosio_assert_code_tests, TESTER) { try { fc::raw::pack( static_cast(system_error_code::generic_system_error) ) ); BOOST_REQUIRE( trace2 ); - BOOST_REQUIRE( trace2->except.has_value() ); + BOOST_REQUIRE( trace2->except ); BOOST_REQUIRE( trace2->error_code ); BOOST_REQUIRE_EQUAL( *trace2->error_code, static_cast(system_error_code::contract_restricted_error_code) ); BOOST_REQUIRE_EQUAL( trace2->action_traces.size(), 1 ); - BOOST_REQUIRE( trace2->action_traces[0].except.has_value() ); + BOOST_REQUIRE( trace2->action_traces[0].except ); BOOST_REQUIRE( trace2->action_traces[0].error_code ); BOOST_REQUIRE_EQUAL( *trace2->action_traces[0].error_code, static_cast(system_error_code::contract_restricted_error_code) ); diff --git a/unittests/chain_tests.cpp b/unittests/chain_tests.cpp index 0a049e42556..f68f70c59a1 100644 --- a/unittests/chain_tests.cpp +++ b/unittests/chain_tests.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE( replace_producer_keys ) try { BOOST_REQUIRE(old_version == new_version); const auto& gpo = tester.control->db().get(); - BOOST_REQUIRE(!gpo.proposed_schedule_block_num.has_value()); + BOOST_REQUIRE(!gpo.proposed_schedule_block_num); BOOST_REQUIRE(gpo.proposed_schedule.version == 0); BOOST_REQUIRE(gpo.proposed_schedule.producers.empty()); diff --git a/unittests/forked_tests.cpp b/unittests/forked_tests.cpp index eaba26d3ce1..dea998a5f90 100644 --- a/unittests/forked_tests.cpp +++ b/unittests/forked_tests.cpp @@ -762,8 +762,8 @@ BOOST_AUTO_TEST_CASE( push_block_returns_forked_transactions ) try { BOOST_CHECK_EQUAL( transaction_receipt_header::executed, traces.at(2)->receipt->status ); // test4 failed because it was tapos to a forked out block BOOST_CHECK_EQUAL( trace4->id, traces.at(3)->id ); - BOOST_CHECK( !traces.at(3)->receipt.has_value() ); - BOOST_CHECK( traces.at(3)->except.has_value() ); + BOOST_CHECK( !traces.at(3)->receipt ); + BOOST_CHECK( traces.at(3)->except ); // verify unapplied transactions ran BOOST_REQUIRE_EQUAL( c.control->get_account( N(test1) ).name, N(test1) ); diff --git a/unittests/misc_tests.cpp b/unittests/misc_tests.cpp index b0d72be0052..80f810eb475 100644 --- a/unittests/misc_tests.cpp +++ b/unittests/misc_tests.cpp @@ -1063,7 +1063,7 @@ BOOST_AUTO_TEST_CASE(pruned_block_test) { deserialized.pack(out, packed_transaction::cf_compression_type::none); BOOST_TEST(out.tellp() <= buffer.size()); - BOOST_TEST(!deserialized.to_signed_block_v0().has_value()); + BOOST_TEST(!deserialized.to_signed_block_v0()); } BOOST_AUTO_TEST_CASE(reflector_init_test) { diff --git a/unittests/protocol_feature_tests.cpp b/unittests/protocol_feature_tests.cpp index c32290f7f29..14d7c619759 100644 --- a/unittests/protocol_feature_tests.cpp +++ b/unittests/protocol_feature_tests.cpp @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( activate_preactivate_feature ) try { auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::preactivate_feature ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); // Activate PREACTIVATE_FEATURE. c.schedule_protocol_features_wo_preactivation({ *d }); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( activate_and_restart ) try { auto pfs = pfm.get_protocol_feature_set(); // make copy of protocol feature set auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::preactivate_feature ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::preactivate_feature ) ); @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE( double_preactivation ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.push_action( config::system_account_name, N(activate), config::system_account_name, fc::mutable_variant_object()("feature_digest", *d), 10 ); @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE( double_activation ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::only_link_to_existing_permission ) ); @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE( require_preactivation_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); BOOST_CHECK( !c.control->is_builtin_activated( builtin_protocol_feature_t::only_link_to_existing_permission ) ); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE( only_link_to_existing_permission_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_link_to_existing_permission ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.create_accounts( {N(alice), N(bob), N(charlie)} ); @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE( subjective_restrictions_test ) try { auto get_builtin_digest = [&pfm]( builtin_protocol_feature_t codename ) -> digest_type { auto res = pfm.get_builtin_digest( codename ); - BOOST_REQUIRE( res.has_value() ); + BOOST_REQUIRE( res ); return *res; }; @@ -456,7 +456,7 @@ BOOST_AUTO_TEST_CASE( replace_deferred_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -577,9 +577,9 @@ BOOST_AUTO_TEST_CASE( no_duplicate_deferred_id_test ) try { const auto& pfm = c.control->get_protocol_feature_manager(); auto d1 = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred ); - BOOST_REQUIRE( d1.has_value() ); + BOOST_REQUIRE( d1 ); auto d2 = pfm.get_builtin_digest( builtin_protocol_feature_t::no_duplicate_deferred_id ); - BOOST_REQUIRE( d2.has_value() ); + BOOST_REQUIRE( d2 ); c.push_action( N(test), N(defercall), N(alice), fc::mutable_variant_object() ("payer", "alice") @@ -724,7 +724,7 @@ BOOST_AUTO_TEST_CASE( fix_linkauth_restriction ) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::fix_linkauth_restriction ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); chain.preactivate_protocol_features( {*d} ); chain.produce_block(); @@ -756,7 +756,7 @@ BOOST_AUTO_TEST_CASE( disallow_empty_producer_schedule_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::disallow_empty_producer_schedule ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); // Before activation, it is allowed to set empty producer schedule c.set_producers_legacy( {} ); @@ -783,7 +783,7 @@ BOOST_AUTO_TEST_CASE( restrict_action_to_self_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::restrict_action_to_self ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.create_accounts( {N(testacc), N(acctonotify), N(alice)} ); c.set_code( N(testacc), contracts::restrict_action_test_wasm() ); @@ -904,7 +904,7 @@ BOOST_AUTO_TEST_CASE( only_bill_to_first_authorizer ) { try { const auto& pfm = chain.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::only_bill_first_authorizer ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); chain.preactivate_protocol_features( {*d} ); chain.produce_blocks(); @@ -964,7 +964,7 @@ BOOST_AUTO_TEST_CASE( forward_setcode_test ) { try { // Activate FORWARD_SETCODE protocol feature and then return contract on eosio back to what it was. const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::forward_setcode ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.set_before_producer_authority_bios_contract(); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -1019,7 +1019,7 @@ BOOST_AUTO_TEST_CASE( get_sender_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::get_sender ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.preactivate_protocol_features( {*d} ); c.produce_block(); @@ -1221,7 +1221,7 @@ BOOST_AUTO_TEST_CASE( ram_restrictions_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::ram_restrictions ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); // Activate RAM_RESTRICTIONS protocol feature (this would also disable the subjective mitigation). c.preactivate_protocol_features( {*d} ); @@ -1329,7 +1329,7 @@ BOOST_AUTO_TEST_CASE( webauthn_producer ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::webauthn_key ); - BOOST_REQUIRE( d.has_value() ); + BOOST_REQUIRE( d ); c.create_account(N(waprod)); c.produce_block(); @@ -1352,7 +1352,7 @@ BOOST_AUTO_TEST_CASE( webauthn_create_account ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); signed_transaction trx; c.set_transaction_headers(trx); @@ -1380,7 +1380,7 @@ BOOST_AUTO_TEST_CASE( webauthn_update_account_auth ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.create_account(N(billy)); c.produce_block(); @@ -1431,7 +1431,7 @@ BOOST_AUTO_TEST_CASE( webauthn_recover_key ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.create_account(N(bob)); c.set_code(N(bob), webauthn_recover_key_wast); @@ -1479,7 +1479,7 @@ BOOST_AUTO_TEST_CASE( webauthn_assert_recover_key ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::webauthn_key); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.create_account(N(bob)); c.set_code(N(bob), webauthn_assert_recover_key_wast); @@ -1525,7 +1525,7 @@ BOOST_AUTO_TEST_CASE( set_proposed_producers_ex_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); const auto& alice_account = account_name("alice"); c.create_accounts( {alice_account} ); @@ -1560,7 +1560,7 @@ BOOST_AUTO_TEST_CASE( producer_schedule_change_extension_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.produce_blocks(2); @@ -1677,7 +1677,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_legacy_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.produce_blocks(2); @@ -1708,7 +1708,7 @@ BOOST_AUTO_TEST_CASE( wtmsig_block_signing_inflight_extension_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::wtmsig_block_signatures); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); c.produce_blocks(2); @@ -1759,7 +1759,7 @@ BOOST_AUTO_TEST_CASE( set_action_return_value_test ) { try { const auto& pfm = c.control->get_protocol_feature_manager(); const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value); - BOOST_REQUIRE(d.has_value()); + BOOST_REQUIRE(d); const auto& alice_account = account_name("alice"); c.create_accounts( {alice_account} ); diff --git a/unittests/state_history_tests.cpp b/unittests/state_history_tests.cpp index 9f2d2f40dd8..eaf36cf7af4 100644 --- a/unittests/state_history_tests.cpp +++ b/unittests/state_history_tests.cpp @@ -32,7 +32,7 @@ prunable_data_type::prunable_data_t get_prunable_data_from_traces(std::vectorcontains()); auto trace_v0 = cfd_trace_itr->get(); - BOOST_REQUIRE(trace_v0.partial.has_value()); + BOOST_REQUIRE(trace_v0.partial); BOOST_REQUIRE(trace_v0.partial->contains()); return trace_v0.partial->get().prunable_data->prunable_data; } @@ -352,7 +352,7 @@ BOOST_AUTO_TEST_CASE(test_state_result_abi) { std::vector traces; state_history::trace_converter::unpack(strm, traces); message.traces = traces; - message.deltas = fc::raw::pack(state_history::create_deltas(control->db(), !prev_block.has_value())); + message.deltas = fc::raw::pack(state_history::create_deltas(control->db(), !prev_block)); prev_block = message.this_block; history[control->head_block_num()] = fc::raw::pack(state_history::state_result{message}); diff --git a/unittests/whitelist_blacklist_tests.cpp b/unittests/whitelist_blacklist_tests.cpp index 467b5605a41..b49e4a6eb5e 100644 --- a/unittests/whitelist_blacklist_tests.cpp +++ b/unittests/whitelist_blacklist_tests.cpp @@ -26,7 +26,7 @@ class whitelist_blacklist_tester { whitelist_blacklist_tester() {} void init( bool bootstrap = true ) { - FC_ASSERT( !chain.has_value(), "chain is already up" ); + FC_ASSERT( !chain, "chain is already up" ); chain.emplace(tempdir, [&](controller::config& cfg) { cfg.sender_bypass_whiteblacklist = sender_bypass_whiteblacklist; @@ -57,7 +57,7 @@ class whitelist_blacklist_tester { } void shutdown() { - FC_ASSERT( chain.has_value(), "chain is not up" ); + FC_ASSERT( chain, "chain is not up" ); last_produced_block = chain->get_last_produced_block_map(); wdump((last_produced_block)); chain.reset(); From 3341c1bb7da35e70e6308cbc5a46c86fb960c59c Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Thu, 18 Jun 2020 13:37:19 -0400 Subject: [PATCH 07/17] Fixed infinite recursive all --- libraries/fc/include/fc/io/raw.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc/include/fc/io/raw.hpp b/libraries/fc/include/fc/io/raw.hpp index 41a4dc1de05..e206c4c6702 100644 --- a/libraries/fc/include/fc/io/raw.hpp +++ b/libraries/fc/include/fc/io/raw.hpp @@ -268,7 +268,7 @@ namespace fc { // optional template void pack( Stream& s, const std::optional& v ) { - fc::raw::pack( s, v ); + fc::raw::pack( s, v.has_value() ); if( v ) fc::raw::pack( s, *v ); } From ce0222bfa27f5bcefe91e96a8a9a1f9badb1f163 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Thu, 18 Jun 2020 16:21:56 -0400 Subject: [PATCH 08/17] Prefer std::make_optional --- libraries/chain/abi_serializer.cpp | 2 +- libraries/chain/authorization_manager.cpp | 6 +++--- libraries/chain/block_log.cpp | 4 ++-- libraries/chain/controller.cpp | 4 ++-- .../chain/include/eosio/chain/authority_checker.hpp | 2 +- libraries/chain/include/eosio/chain/controller.hpp | 2 +- libraries/fc/include/fc/variant.hpp | 2 +- libraries/fc/src/filesystem.cpp | 2 +- libraries/fc/src/network/gntp.cpp | 12 ++++++------ libraries/fc/src/network/ntp.cpp | 2 +- libraries/testing/include/eosio/testing/tester.hpp | 2 +- plugins/chain_plugin/chain_plugin.cpp | 2 +- .../include/eosio/chain_plugin/chain_plugin.hpp | 2 +- plugins/net_plugin/net_plugin.cpp | 2 +- plugins/producer_plugin/producer_plugin.cpp | 2 +- plugins/trace_api_plugin/test/test_trace_file.cpp | 2 +- plugins/wallet_plugin/se_wallet.cpp | 2 +- plugins/wallet_plugin/wallet.cpp | 4 ++-- plugins/wallet_plugin/yubihsm_wallet.cpp | 2 +- programs/cleos/main.cpp | 2 +- programs/eosio-blocklog/main.cpp | 2 +- tests/chain_plugin_tests.cpp | 2 +- unittests/wasm_tests.cpp | 2 +- 23 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index 66b60a2b2f4..7aa0950ae2e 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -608,7 +608,7 @@ namespace eosio { namespace chain { std::optional abi_serializer::get_error_message( uint64_t error_code )const { auto itr = error_messages.find( error_code ); if( itr == error_messages.end() ) - return std::optional(); + return std::make_optional(); return itr->second; } diff --git a/libraries/chain/authorization_manager.cpp b/libraries/chain/authorization_manager.cpp index ebdbb11a158..9c6f96fcb6d 100644 --- a/libraries/chain/authorization_manager.cpp +++ b/libraries/chain/authorization_manager.cpp @@ -295,9 +295,9 @@ namespace eosio { namespace chain { if (link != nullptr) { return link->required_permission; } - return std::optional(); + return std::make_optional(); - // return std::optional(); + // return std::make_optional(); } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) } @@ -323,7 +323,7 @@ namespace eosio { namespace chain { return config::active_name; if( *linked_permission == config::eosio_any_name ) - return std::optional(); + return std::make_optional(); return linked_permission; } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index 6cef49b1683..fd8240abfb0 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -297,8 +297,8 @@ namespace eosio { namespace chain { chain_id_type chain_id() const { return preamble.chain_id(); } std::optional get_genesis_state() const { - return std::visit(overloaded{[](const chain_id_type&) { return std::optional{}; }, - [](const genesis_state& state) { return std::optional{state}; }}, + return std::visit(overloaded{[](const chain_id_type&) { return std::make_optional(); }, + [](const genesis_state& state) { return std::make_optional(state); }}, preamble.chain_context); } diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index adb54f67541..292a2cacd58 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1714,7 +1714,7 @@ struct controller_impl { pending->_block_stage.get()._new_pending_producer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); db.modify( gpo, [&]( auto& gp ) { - gp.proposed_schedule_block_num = std::optional(); + gp.proposed_schedule_block_num = std::make_optional(); gp.proposed_schedule.version=0; gp.proposed_schedule.producers.clear(); }); @@ -3120,7 +3120,7 @@ const producer_authority_schedule& controller::pending_producers()const { std::optional controller::proposed_producers()const { const auto& gpo = get_global_properties(); if( !gpo.proposed_schedule_block_num ) - return std::optional(); + return std::make_optional(); return producer_authority_schedule::from_shared(gpo.proposed_schedule); } diff --git a/libraries/chain/include/eosio/chain/authority_checker.hpp b/libraries/chain/include/eosio/chain/authority_checker.hpp index 16a3f954090..de71ee29ce8 100644 --- a/libraries/chain/include/eosio/chain/authority_checker.hpp +++ b/libraries/chain/include/eosio/chain/authority_checker.hpp @@ -141,7 +141,7 @@ namespace detail { if( itr != permissions.end() ) return itr->second; - return std::optional(); + return std::make_optional(); } private: diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 298afeeece8..b86ada63983 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -346,7 +346,7 @@ namespace eosio { namespace chain { return abi_serializer( abi, yield ); } FC_CAPTURE_AND_LOG((n)) } - return std::optional(); + return std::make_optional(); } template diff --git a/libraries/fc/include/fc/variant.hpp b/libraries/fc/include/fc/variant.hpp index aecec202616..f8d3dcadb8e 100644 --- a/libraries/fc/include/fc/variant.hpp +++ b/libraries/fc/include/fc/variant.hpp @@ -391,7 +391,7 @@ namespace fc template void from_variant( const variant& var, std::optional& vo ) { - if( var.is_null() ) vo = std::optional(); + if( var.is_null() ) vo = std::make_optional(); else { vo = T(); diff --git a/libraries/fc/src/filesystem.cpp b/libraries/fc/src/filesystem.cpp index 1b8df2018cf..435a16f48c5 100644 --- a/libraries/fc/src/filesystem.cpp +++ b/libraries/fc/src/filesystem.cpp @@ -446,7 +446,7 @@ namespace fc { void temp_file_base::release() { - _path = std::optional(); + _path = std::make_optional(); } const fc::path& home_path() diff --git a/libraries/fc/src/network/gntp.cpp b/libraries/fc/src/network/gntp.cpp index 0c522d31378..60522a659cb 100644 --- a/libraries/fc/src/network/gntp.cpp +++ b/libraries/fc/src/network/gntp.cpp @@ -45,7 +45,7 @@ namespace fc class gntp_notifier_impl { public: - gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const std::optional& password = std::optional()); + gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const std::optional& password = std::make_optional()); // there's no API to change these right now, it will always notify localhost at the default GNTP port std::string hostname; @@ -66,7 +66,7 @@ namespace fc }; gntp_notifier_impl::gntp_notifier_impl(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const std::optional& password /* = std::optional() */) : + const std::optional& password /* = std::make_optional() */) : hostname(host_to_notify), port(port), password(password), @@ -94,14 +94,14 @@ namespace fc ("error_report", er.to_detail_string())); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = std::optional(); + endpoint = std::make_optional(); } catch (...) { ilog("Failed to connect to GNTP service using an endpoint that previously worked"); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = std::optional(); + endpoint = std::make_optional(); } } if (!connected) @@ -165,7 +165,7 @@ namespace fc } gntp_notifier::gntp_notifier(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const std::optional& password /* = std::optional() */) : + const std::optional& password /* = std::make_optional() */) : my(new detail::gntp_notifier_impl(host_to_notify, port, password)) { } @@ -243,7 +243,7 @@ namespace fc } } gntp_guid gntp_notifier::send_notification(std::string name, std::string title, std::string text, - const gntp_icon_ptr& icon, std::optional coalescingId /* = std::optional() */) + const gntp_icon_ptr& icon, std::optional coalescingId /* = std::make_optional() */) { if (my->connection_failed) return gntp_guid(); diff --git a/libraries/fc/src/network/ntp.cpp b/libraries/fc/src/network/ntp.cpp index 00aeadf878f..d68e5899c6c 100644 --- a/libraries/fc/src/network/ntp.cpp +++ b/libraries/fc/src/network/ntp.cpp @@ -247,7 +247,7 @@ namespace fc { if( my->_last_ntp_delta_initialized ) return fc::time_point::now() + fc::microseconds(my->_last_ntp_delta_microseconds); - return std::optional(); + return std::make_optional(); } } //namespace fc diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 8f8a8818f70..cc34d5bbdb9 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -342,7 +342,7 @@ namespace eosio { namespace testing { if( abi_serializer::to_abi( accnt.abi, abi )) { return abi_serializer( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) ); } - return std::optional(); + return std::make_optional(); } FC_RETHROW_EXCEPTIONS( error, "Failed to find or parse ABI for ${name}", ("name", name)) }; } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 50d1a81faa1..06c01e78a00 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2086,7 +2086,7 @@ struct resolver_factory { } } - return std::optional(); + return std::make_optional(); }; } }; diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index b9bc6d9913e..85ed30bc224 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -733,7 +733,7 @@ class chain_plugin : public plugin { static bool recover_reversible_blocks( const fc::path& db_dir, uint32_t cache_size, - std::optional new_db_dir = std::optional(), + std::optional new_db_dir = std::make_optional(), uint32_t truncate_at_block = 0 ); diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 2f519af18ca..89e51dfb1e7 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -3789,7 +3789,7 @@ namespace eosio { auto con = my->find_connection( host ); if( con ) return con->get_status(); - return std::optional(); + return std::make_optional(); } vector net_plugin::connections()const { diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index f9df7ab9beb..c37df6bacc1 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1282,7 +1282,7 @@ std::optional producer_plugin_impl::calculate_next_block_time(co auto itr = std::find_if(active_schedule.begin(), active_schedule.end(), [&](const auto& asp){ return asp.producer_name == producer_name; }); if (itr == active_schedule.end()) { // this producer is not in the active producer set - return std::optional(); + return std::make_optional(); } size_t producer_index = itr - active_schedule.begin(); diff --git a/plugins/trace_api_plugin/test/test_trace_file.cpp b/plugins/trace_api_plugin/test/test_trace_file.cpp index c1f6fee077a..4274ab9c7cc 100644 --- a/plugins/trace_api_plugin/test/test_trace_file.cpp +++ b/plugins/trace_api_plugin/test/test_trace_file.cpp @@ -140,7 +140,7 @@ namespace { }; struct test_store_provider : public store_provider { - test_store_provider(const bfs::path& slice_dir, uint32_t width, std::optional minimum_irreversible_history_blocks = std::optional(), std::optional minimum_uncompressed_irreversible_history_blocks = std::optional(), size_t compression_seek_point_stride = 0) + test_store_provider(const bfs::path& slice_dir, uint32_t width, std::optional minimum_irreversible_history_blocks = std::make_optional(), std::optional minimum_uncompressed_irreversible_history_blocks = std::make_optional(), size_t compression_seek_point_stride = 0) : store_provider(slice_dir, width, minimum_irreversible_history_blocks, minimum_uncompressed_irreversible_history_blocks, compression_seek_point_stride) { } using store_provider::scan_metadata_log_from; diff --git a/plugins/wallet_plugin/se_wallet.cpp b/plugins/wallet_plugin/se_wallet.cpp index 83361e021d8..a5f0d5fd2e4 100644 --- a/plugins/wallet_plugin/se_wallet.cpp +++ b/plugins/wallet_plugin/se_wallet.cpp @@ -102,7 +102,7 @@ std::optional se_wallet::try_sign_digest(const digest_type diges if(it->public_key() == public_key) return it->sign(digest); - return std::optional{}; + return std::make_optional(); } }} diff --git a/plugins/wallet_plugin/wallet.cpp b/plugins/wallet_plugin/wallet.cpp index 09a0028e217..99c2d96a693 100644 --- a/plugins/wallet_plugin/wallet.cpp +++ b/plugins/wallet_plugin/wallet.cpp @@ -120,13 +120,13 @@ class soft_wallet_impl auto it = _keys.find(id); if( it != _keys.end() ) return it->second; - return std::optional(); + return std::make_optional(); } std::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) { auto it = _keys.find(public_key); if( it == _keys.end() ) - return std::optional{}; + return std::make_optional(); return it->second.sign(digest); } diff --git a/plugins/wallet_plugin/yubihsm_wallet.cpp b/plugins/wallet_plugin/yubihsm_wallet.cpp index c51e19c913d..d9608e3419e 100644 --- a/plugins/wallet_plugin/yubihsm_wallet.cpp +++ b/plugins/wallet_plugin/yubihsm_wallet.cpp @@ -136,7 +136,7 @@ struct yubihsm_wallet_impl { std::optional try_sign_digest(const digest_type d, const public_key_type public_key) { auto it = _keys.find(public_key); if(it == _keys.end()) - return std::optional{}; + return std::make_optional(); size_t der_sig_sz = 128; uint8_t der_sig[der_sig_sz]; diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 4dbc2c9df32..6edd26da02c 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -369,7 +369,7 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional std::optional { - return std::optional(); + return std::make_optional(); }; void prompt_for_wallet_password(string& pw, const string& name) { diff --git a/programs/eosio-blocklog/main.cpp b/programs/eosio-blocklog/main.cpp index c0dea933bd5..4e3a9281ee1 100644 --- a/programs/eosio-blocklog/main.cpp +++ b/programs/eosio-blocklog/main.cpp @@ -128,7 +128,7 @@ void blocklog::read_log() { auto print_block = [&](auto& next) { abi_serializer::to_variant(*next, pretty_output, - []( account_name n ) { return std::optional(); }, + []( account_name n ) { return std::make_optional(); }, abi_serializer::create_yield_function( deadline )); const auto block_id = next->calculate_id(); const uint32_t ref_block_prefix = block_id._hash[1]; diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index 12797cb1111..f82c8537560 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -52,7 +52,7 @@ BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, TESTER ) try { if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return std::optional(); + return std::make_optional(); } FC_RETHROW_EXCEPTIONS(error, "resolver failed at chain_plugin_tests::abi_invalid_type"); }; diff --git a/unittests/wasm_tests.cpp b/unittests/wasm_tests.cpp index 03fa1343293..cfe70f0dbd8 100644 --- a/unittests/wasm_tests.cpp +++ b/unittests/wasm_tests.cpp @@ -185,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE( abi_from_variant, TESTER ) try { if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return std::optional(); + return std::make_optional(); } FC_RETHROW_EXCEPTIONS(error, "Failed to find or parse ABI for ${name}", ("name", name)) }; From 60481ddc5f419c87be33544034c9b0014b39856d Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 23 Jun 2020 14:46:53 -0400 Subject: [PATCH 09/17] Rollback overzealous use of std::make_optional --- libraries/chain/abi_serializer.cpp | 2 +- libraries/chain/authorization_manager.cpp | 6 ++---- libraries/chain/block_log.cpp | 4 ++-- libraries/chain/controller.cpp | 4 ++-- .../chain/include/eosio/chain/abi_serializer.hpp | 2 +- .../chain/include/eosio/chain/authority_checker.hpp | 2 +- libraries/chain/include/eosio/chain/controller.hpp | 2 +- libraries/fc/include/fc/variant.hpp | 4 ++-- libraries/fc/src/filesystem.cpp | 2 +- libraries/fc/src/network/gntp.cpp | 12 ++++++------ libraries/fc/src/network/ntp.cpp | 2 +- libraries/testing/include/eosio/testing/tester.hpp | 2 +- plugins/chain_plugin/chain_plugin.cpp | 2 +- .../include/eosio/chain_plugin/chain_plugin.hpp | 2 +- plugins/net_plugin/net_plugin.cpp | 2 +- plugins/producer_plugin/producer_plugin.cpp | 2 +- plugins/trace_api_plugin/test/test_trace_file.cpp | 2 +- plugins/wallet_plugin/se_wallet.cpp | 2 +- plugins/wallet_plugin/wallet.cpp | 4 ++-- plugins/wallet_plugin/yubihsm_wallet.cpp | 2 +- programs/cleos/main.cpp | 2 +- programs/eosio-blocklog/main.cpp | 2 +- tests/chain_plugin_tests.cpp | 2 +- unittests/wasm_tests.cpp | 2 +- 24 files changed, 34 insertions(+), 36 deletions(-) diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index 7aa0950ae2e..66b60a2b2f4 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -608,7 +608,7 @@ namespace eosio { namespace chain { std::optional abi_serializer::get_error_message( uint64_t error_code )const { auto itr = error_messages.find( error_code ); if( itr == error_messages.end() ) - return std::make_optional(); + return std::optional(); return itr->second; } diff --git a/libraries/chain/authorization_manager.cpp b/libraries/chain/authorization_manager.cpp index 9c6f96fcb6d..c79453388fb 100644 --- a/libraries/chain/authorization_manager.cpp +++ b/libraries/chain/authorization_manager.cpp @@ -295,9 +295,7 @@ namespace eosio { namespace chain { if (link != nullptr) { return link->required_permission; } - return std::make_optional(); - - // return std::make_optional(); + return std::optional(); } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) } @@ -323,7 +321,7 @@ namespace eosio { namespace chain { return config::active_name; if( *linked_permission == config::eosio_any_name ) - return std::make_optional(); + return std::optional(); return linked_permission; } FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name)) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index fd8240abfb0..bef236a85bd 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -297,8 +297,8 @@ namespace eosio { namespace chain { chain_id_type chain_id() const { return preamble.chain_id(); } std::optional get_genesis_state() const { - return std::visit(overloaded{[](const chain_id_type&) { return std::make_optional(); }, - [](const genesis_state& state) { return std::make_optional(state); }}, + return std::visit(overloaded{[](const chain_id_type&) { return std::optional(); }, + [](const genesis_state& state) { return std::optional(state); }}, preamble.chain_context); } diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 292a2cacd58..adb54f67541 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1714,7 +1714,7 @@ struct controller_impl { pending->_block_stage.get()._new_pending_producer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); db.modify( gpo, [&]( auto& gp ) { - gp.proposed_schedule_block_num = std::make_optional(); + gp.proposed_schedule_block_num = std::optional(); gp.proposed_schedule.version=0; gp.proposed_schedule.producers.clear(); }); @@ -3120,7 +3120,7 @@ const producer_authority_schedule& controller::pending_producers()const { std::optional controller::proposed_producers()const { const auto& gpo = get_global_properties(); if( !gpo.proposed_schedule_block_num ) - return std::make_optional(); + return std::optional(); return producer_authority_schedule::from_shared(gpo.proposed_schedule); } diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index e08dfdaa538..0fa01d46c46 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -128,7 +128,7 @@ struct abi_serializer { "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) ); EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, - "serialization time limit ${t}us exceeded", ("t", max_serialization_time) ); + "serialization time limit ${t}us exceeded", ("t", max_serialization_time) ); }; } diff --git a/libraries/chain/include/eosio/chain/authority_checker.hpp b/libraries/chain/include/eosio/chain/authority_checker.hpp index de71ee29ce8..16a3f954090 100644 --- a/libraries/chain/include/eosio/chain/authority_checker.hpp +++ b/libraries/chain/include/eosio/chain/authority_checker.hpp @@ -141,7 +141,7 @@ namespace detail { if( itr != permissions.end() ) return itr->second; - return std::make_optional(); + return std::optional(); } private: diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index b86ada63983..298afeeece8 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -346,7 +346,7 @@ namespace eosio { namespace chain { return abi_serializer( abi, yield ); } FC_CAPTURE_AND_LOG((n)) } - return std::make_optional(); + return std::optional(); } template diff --git a/libraries/fc/include/fc/variant.hpp b/libraries/fc/include/fc/variant.hpp index f8d3dcadb8e..f261076da90 100644 --- a/libraries/fc/include/fc/variant.hpp +++ b/libraries/fc/include/fc/variant.hpp @@ -351,7 +351,7 @@ namespace fc explicit variant( const std::optional& v ) { memset( this, 0, sizeof(*this) ); - if( v ) *this = variant(*v); + if( v.has_value() ) *this = variant(*v); } template @@ -391,7 +391,7 @@ namespace fc template void from_variant( const variant& var, std::optional& vo ) { - if( var.is_null() ) vo = std::make_optional(); + if( var.is_null() ) vo = std::optional(); else { vo = T(); diff --git a/libraries/fc/src/filesystem.cpp b/libraries/fc/src/filesystem.cpp index 435a16f48c5..1b8df2018cf 100644 --- a/libraries/fc/src/filesystem.cpp +++ b/libraries/fc/src/filesystem.cpp @@ -446,7 +446,7 @@ namespace fc { void temp_file_base::release() { - _path = std::make_optional(); + _path = std::optional(); } const fc::path& home_path() diff --git a/libraries/fc/src/network/gntp.cpp b/libraries/fc/src/network/gntp.cpp index 60522a659cb..0c522d31378 100644 --- a/libraries/fc/src/network/gntp.cpp +++ b/libraries/fc/src/network/gntp.cpp @@ -45,7 +45,7 @@ namespace fc class gntp_notifier_impl { public: - gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const std::optional& password = std::make_optional()); + gntp_notifier_impl(const std::string& host_to_notify = "127.0.0.1", uint16_t port = 23053, const std::optional& password = std::optional()); // there's no API to change these right now, it will always notify localhost at the default GNTP port std::string hostname; @@ -66,7 +66,7 @@ namespace fc }; gntp_notifier_impl::gntp_notifier_impl(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const std::optional& password /* = std::make_optional() */) : + const std::optional& password /* = std::optional() */) : hostname(host_to_notify), port(port), password(password), @@ -94,14 +94,14 @@ namespace fc ("error_report", er.to_detail_string())); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = std::make_optional(); + endpoint = std::optional(); } catch (...) { ilog("Failed to connect to GNTP service using an endpoint that previously worked"); sock->close(); // clear the cached endpoint and fall through to the full connection procedure - endpoint = std::make_optional(); + endpoint = std::optional(); } } if (!connected) @@ -165,7 +165,7 @@ namespace fc } gntp_notifier::gntp_notifier(const std::string& host_to_notify /* = "127.0.0.1" */, uint16_t port /* = 23053 */, - const std::optional& password /* = std::make_optional() */) : + const std::optional& password /* = std::optional() */) : my(new detail::gntp_notifier_impl(host_to_notify, port, password)) { } @@ -243,7 +243,7 @@ namespace fc } } gntp_guid gntp_notifier::send_notification(std::string name, std::string title, std::string text, - const gntp_icon_ptr& icon, std::optional coalescingId /* = std::make_optional() */) + const gntp_icon_ptr& icon, std::optional coalescingId /* = std::optional() */) { if (my->connection_failed) return gntp_guid(); diff --git a/libraries/fc/src/network/ntp.cpp b/libraries/fc/src/network/ntp.cpp index d68e5899c6c..00aeadf878f 100644 --- a/libraries/fc/src/network/ntp.cpp +++ b/libraries/fc/src/network/ntp.cpp @@ -247,7 +247,7 @@ namespace fc { if( my->_last_ntp_delta_initialized ) return fc::time_point::now() + fc::microseconds(my->_last_ntp_delta_microseconds); - return std::make_optional(); + return std::optional(); } } //namespace fc diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index cc34d5bbdb9..8f8a8818f70 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -342,7 +342,7 @@ namespace eosio { namespace testing { if( abi_serializer::to_abi( accnt.abi, abi )) { return abi_serializer( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) ); } - return std::make_optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS( error, "Failed to find or parse ABI for ${name}", ("name", name)) }; } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 06c01e78a00..50d1a81faa1 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2086,7 +2086,7 @@ struct resolver_factory { } } - return std::make_optional(); + return std::optional(); }; } }; diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index 85ed30bc224..b9bc6d9913e 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -733,7 +733,7 @@ class chain_plugin : public plugin { static bool recover_reversible_blocks( const fc::path& db_dir, uint32_t cache_size, - std::optional new_db_dir = std::make_optional(), + std::optional new_db_dir = std::optional(), uint32_t truncate_at_block = 0 ); diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 89e51dfb1e7..2f519af18ca 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -3789,7 +3789,7 @@ namespace eosio { auto con = my->find_connection( host ); if( con ) return con->get_status(); - return std::make_optional(); + return std::optional(); } vector net_plugin::connections()const { diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index c37df6bacc1..f9df7ab9beb 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -1282,7 +1282,7 @@ std::optional producer_plugin_impl::calculate_next_block_time(co auto itr = std::find_if(active_schedule.begin(), active_schedule.end(), [&](const auto& asp){ return asp.producer_name == producer_name; }); if (itr == active_schedule.end()) { // this producer is not in the active producer set - return std::make_optional(); + return std::optional(); } size_t producer_index = itr - active_schedule.begin(); diff --git a/plugins/trace_api_plugin/test/test_trace_file.cpp b/plugins/trace_api_plugin/test/test_trace_file.cpp index 4274ab9c7cc..c1f6fee077a 100644 --- a/plugins/trace_api_plugin/test/test_trace_file.cpp +++ b/plugins/trace_api_plugin/test/test_trace_file.cpp @@ -140,7 +140,7 @@ namespace { }; struct test_store_provider : public store_provider { - test_store_provider(const bfs::path& slice_dir, uint32_t width, std::optional minimum_irreversible_history_blocks = std::make_optional(), std::optional minimum_uncompressed_irreversible_history_blocks = std::make_optional(), size_t compression_seek_point_stride = 0) + test_store_provider(const bfs::path& slice_dir, uint32_t width, std::optional minimum_irreversible_history_blocks = std::optional(), std::optional minimum_uncompressed_irreversible_history_blocks = std::optional(), size_t compression_seek_point_stride = 0) : store_provider(slice_dir, width, minimum_irreversible_history_blocks, minimum_uncompressed_irreversible_history_blocks, compression_seek_point_stride) { } using store_provider::scan_metadata_log_from; diff --git a/plugins/wallet_plugin/se_wallet.cpp b/plugins/wallet_plugin/se_wallet.cpp index a5f0d5fd2e4..5867a89180f 100644 --- a/plugins/wallet_plugin/se_wallet.cpp +++ b/plugins/wallet_plugin/se_wallet.cpp @@ -102,7 +102,7 @@ std::optional se_wallet::try_sign_digest(const digest_type diges if(it->public_key() == public_key) return it->sign(digest); - return std::make_optional(); + return std::optional(); } }} diff --git a/plugins/wallet_plugin/wallet.cpp b/plugins/wallet_plugin/wallet.cpp index 99c2d96a693..a4859a584ec 100644 --- a/plugins/wallet_plugin/wallet.cpp +++ b/plugins/wallet_plugin/wallet.cpp @@ -120,13 +120,13 @@ class soft_wallet_impl auto it = _keys.find(id); if( it != _keys.end() ) return it->second; - return std::make_optional(); + return std::optional(); } std::optional try_sign_digest( const digest_type digest, const public_key_type public_key ) { auto it = _keys.find(public_key); if( it == _keys.end() ) - return std::make_optional(); + return std::optional(); return it->second.sign(digest); } diff --git a/plugins/wallet_plugin/yubihsm_wallet.cpp b/plugins/wallet_plugin/yubihsm_wallet.cpp index d9608e3419e..d2de96ae6d1 100644 --- a/plugins/wallet_plugin/yubihsm_wallet.cpp +++ b/plugins/wallet_plugin/yubihsm_wallet.cpp @@ -136,7 +136,7 @@ struct yubihsm_wallet_impl { std::optional try_sign_digest(const digest_type d, const public_key_type public_key) { auto it = _keys.find(public_key); if(it == _keys.end()) - return std::make_optional(); + return std::optional(); size_t der_sig_sz = 128; uint8_t der_sig[der_sig_sz]; diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 6edd26da02c..4dbc2c9df32 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -369,7 +369,7 @@ auto abi_serializer_resolver = [](const name& account) -> std::optional std::optional { - return std::make_optional(); + return std::optional(); }; void prompt_for_wallet_password(string& pw, const string& name) { diff --git a/programs/eosio-blocklog/main.cpp b/programs/eosio-blocklog/main.cpp index 4e3a9281ee1..c0dea933bd5 100644 --- a/programs/eosio-blocklog/main.cpp +++ b/programs/eosio-blocklog/main.cpp @@ -128,7 +128,7 @@ void blocklog::read_log() { auto print_block = [&](auto& next) { abi_serializer::to_variant(*next, pretty_output, - []( account_name n ) { return std::make_optional(); }, + []( account_name n ) { return std::optional(); }, abi_serializer::create_yield_function( deadline )); const auto block_id = next->calculate_id(); const uint32_t ref_block_prefix = block_id._hash[1]; diff --git a/tests/chain_plugin_tests.cpp b/tests/chain_plugin_tests.cpp index f82c8537560..12797cb1111 100644 --- a/tests/chain_plugin_tests.cpp +++ b/tests/chain_plugin_tests.cpp @@ -52,7 +52,7 @@ BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, TESTER ) try { if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return std::make_optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS(error, "resolver failed at chain_plugin_tests::abi_invalid_type"); }; diff --git a/unittests/wasm_tests.cpp b/unittests/wasm_tests.cpp index cfe70f0dbd8..03fa1343293 100644 --- a/unittests/wasm_tests.cpp +++ b/unittests/wasm_tests.cpp @@ -185,7 +185,7 @@ BOOST_FIXTURE_TEST_CASE( abi_from_variant, TESTER ) try { if (abi_serializer::to_abi(accnt.abi, abi)) { return abi_serializer(abi, abi_serializer::create_yield_function( abi_serializer_max_time )); } - return std::make_optional(); + return std::optional(); } FC_RETHROW_EXCEPTIONS(error, "Failed to find or parse ABI for ${name}", ("name", name)) }; From de02b53cb6ebba8f85d91616bdfbcd396c0ecbf0 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 23 Jun 2020 16:12:45 -0400 Subject: [PATCH 10/17] Rollback serialization.hpp change --- .../state_history/include/eosio/state_history/serialization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index 7b86faa716d..dc4498a19bf 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -109,7 +109,7 @@ void history_pack_big_bytes(ST& ds, const eosio::chain::bytes& v) { template void history_pack_big_bytes(ST& ds, const std::optional& v) { - fc::raw::pack(ds, v); + fc::raw::pack(ds, v.has_value()); if (v) history_pack_big_bytes(ds, *v); } From 9fc80e3e92a028d55731bd4703b133061d6aedb0 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Mon, 20 Jul 2020 11:22:06 -0400 Subject: [PATCH 11/17] Rollback change to use list initialization --- libraries/chain/block_log.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/block_log.cpp b/libraries/chain/block_log.cpp index bef236a85bd..6cef49b1683 100644 --- a/libraries/chain/block_log.cpp +++ b/libraries/chain/block_log.cpp @@ -297,8 +297,8 @@ namespace eosio { namespace chain { chain_id_type chain_id() const { return preamble.chain_id(); } std::optional get_genesis_state() const { - return std::visit(overloaded{[](const chain_id_type&) { return std::optional(); }, - [](const genesis_state& state) { return std::optional(state); }}, + return std::visit(overloaded{[](const chain_id_type&) { return std::optional{}; }, + [](const genesis_state& state) { return std::optional{state}; }}, preamble.chain_context); } From dde14b1bdf44865f04a96bc486542193cfdf7b5d Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 21 Jul 2020 12:41:46 -0400 Subject: [PATCH 12/17] Formatting corrections --- libraries/chain/authorization_manager.cpp | 12 +-- libraries/chain/controller.cpp | 66 ++++++------ .../include/eosio/chain/abi_serializer.hpp | 2 +- .../eosio/chain/authorization_manager.hpp | 12 +-- .../chain/include/eosio/chain/controller.hpp | 6 +- .../eosio/chain/global_property_object.hpp | 8 +- .../eosio/chain/protocol_feature_manager.hpp | 14 +-- .../include/eosio/chain/thread_utils.hpp | 2 +- libraries/chain/include/eosio/chain/trace.hpp | 18 ++-- .../eosio/chain/transaction_context.hpp | 10 +- libraries/fc/include/fc/log/logger_config.hpp | 4 +- libraries/fc/include/fc/network/url.hpp | 2 +- libraries/fc/src/log/gelf_appender.cpp | 4 +- libraries/fc/src/network/url.cpp | 4 +- .../state_history/transaction_trace_cache.hpp | 2 +- .../include/eosio/state_history/types.hpp | 68 ++++++------ plugins/chain_plugin/chain_plugin.cpp | 4 +- .../eosio/chain_plugin/chain_plugin.hpp | 100 +++++++++--------- .../eosio/history_plugin/history_plugin.hpp | 10 +- plugins/http_plugin/http_plugin.cpp | 24 ++--- .../include/eosio/net_plugin/net_plugin.hpp | 6 +- .../include/eosio/net_plugin/protocol.hpp | 2 +- plugins/net_plugin/net_plugin.cpp | 24 ++--- .../eosio/producer_plugin/producer_plugin.hpp | 8 +- plugins/producer_plugin/producer_plugin.cpp | 2 +- .../state_history_plugin.cpp | 12 +-- .../eosio/trace_api/chain_extraction.hpp | 2 +- .../txn_test_gen_plugin.cpp | 2 +- programs/eosio-tester/main.cpp | 6 +- unittests/state_history_tests.cpp | 2 +- unittests/whitelist_blacklist_tests.cpp | 2 +- 31 files changed, 220 insertions(+), 220 deletions(-) diff --git a/libraries/chain/authorization_manager.cpp b/libraries/chain/authorization_manager.cpp index c79453388fb..6e6f10b9a84 100644 --- a/libraries/chain/authorization_manager.cpp +++ b/libraries/chain/authorization_manager.cpp @@ -277,9 +277,9 @@ namespace eosio { namespace chain { } EOS_RETHROW_EXCEPTIONS( chain::permission_query_exception, "Failed to retrieve permission: ${level}", ("level", level) ) } std::optional authorization_manager::lookup_linked_permission( account_name authorizer_account, - account_name scope, - action_name act_name - )const + account_name scope, + action_name act_name + )const { try { // First look up a specific link for this message act_name @@ -300,9 +300,9 @@ namespace eosio { namespace chain { } std::optional authorization_manager::lookup_minimum_permission( account_name authorizer_account, - account_name scope, - action_name act_name - )const + account_name scope, + action_name act_name + )const { // Special case native actions cannot be linked to a minimum permission, so there is no need to check. if( scope == config::system_account_name ) { diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index adb54f67541..f9b876eff4d 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -119,14 +119,14 @@ struct building_block { ,_trx_mroot_or_receipt_digests( digests_t{} ) {} - pending_block_header_state _pending_block_header_state; - std::optional _new_pending_producer_schedule; - vector _new_protocol_feature_activations; - size_t _num_new_protocol_features_that_have_activated = 0; - deque _pending_trx_metas; - deque _pending_trx_receipts; // boost deque in 1.71 with 1024 elements performs better + pending_block_header_state _pending_block_header_state; + std::optional _new_pending_producer_schedule; + vector _new_protocol_feature_activations; + size_t _num_new_protocol_features_that_have_activated = 0; + deque _pending_trx_metas; + deque _pending_trx_receipts; // boost deque in 1.71 with 1024 elements performs better static_variant _trx_mroot_or_receipt_digests; - digests_t _action_receipt_digests; + digests_t _action_receipt_digests; }; struct assembled_block { @@ -157,7 +157,7 @@ struct pending_state { maybe_session _db_session; block_stage_type _block_stage; controller::block_status _block_status = controller::block_status::incomplete; - std::optional _producer_block_id; + std::optional _producer_block_id; /** @pre _block_stage cannot hold completed_block alternative */ const pending_block_header_state& get_pending_block_header_state()const { @@ -226,32 +226,32 @@ struct controller_impl { reset_new_handler() { std::set_new_handler([](){ throw std::bad_alloc(); }); } }; - reset_new_handler rnh; // placed here to allow for this to be set before constructing the other fields - controller& self; - std::function shutdown; - chainbase::database db; - chainbase::database reversible_blocks; ///< a special database to persist blocks that have successfully been applied but are still reversible - block_log blog; - std::optional pending; - block_state_ptr head; - fork_database fork_db; - wasm_interface wasmif; - resource_limits_manager resource_limits; - authorization_manager authorization; - protocol_feature_manager protocol_features; - controller::config conf; - const chain_id_type chain_id; // read by thread_pool threads, value will not be changed - std::optional replay_head_time; - db_read_mode read_mode = db_read_mode::SPECULATIVE; - bool in_trx_requiring_checks = false; ///< if true, checks that are normally skipped on replay (e.g. auth checks) cannot be skipped - std::optional subjective_cpu_leeway; - bool trusted_producer_light_validation = false; - uint32_t snapshot_head_block = 0; - named_thread_pool thread_pool; - platform_timer timer; - fc::logger* deep_mind_logger = nullptr; + reset_new_handler rnh; // placed here to allow for this to be set before constructing the other fields + controller& self; + std::function shutdown; + chainbase::database db; + chainbase::database reversible_blocks; ///< a special database to persist blocks that have successfully been applied but are still reversible + block_log blog; + std::optional pending; + block_state_ptr head; + fork_database fork_db; + wasm_interface wasmif; + resource_limits_manager resource_limits; + authorization_manager authorization; + protocol_feature_manager protocol_features; + controller::config conf; + const chain_id_type chain_id; // read by thread_pool threads, value will not be changed + std::optional replay_head_time; + db_read_mode read_mode = db_read_mode::SPECULATIVE; + bool in_trx_requiring_checks = false; ///< if true, checks that are normally skipped on replay (e.g. auth checks) cannot be skipped + std::optional subjective_cpu_leeway; + bool trusted_producer_light_validation = false; + uint32_t snapshot_head_block = 0; + named_thread_pool thread_pool; + platform_timer timer; + fc::logger* deep_mind_logger = nullptr; #if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED) - vm::wasm_allocator wasm_alloc; + vm::wasm_allocator wasm_alloc; #endif typedef pair handler_key; diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index 0fa01d46c46..e08dfdaa538 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -128,7 +128,7 @@ struct abi_serializer { "recursive definition, max_recursion_depth ${r} ", ("r", max_recursion_depth) ); EOS_ASSERT( fc::time_point::now() < deadline, abi_serialization_deadline_exception, - "serialization time limit ${t}us exceeded", ("t", max_serialization_time) ); + "serialization time limit ${t}us exceeded", ("t", max_serialization_time) ); }; } diff --git a/libraries/chain/include/eosio/chain/authorization_manager.hpp b/libraries/chain/include/eosio/chain/authorization_manager.hpp index 429f6728321..a61770c3fdb 100644 --- a/libraries/chain/include/eosio/chain/authorization_manager.hpp +++ b/libraries/chain/include/eosio/chain/authorization_manager.hpp @@ -62,9 +62,9 @@ namespace eosio { namespace chain { * @param type The type of message */ std::optional lookup_minimum_permission( account_name authorizer_account, - scope_name code_account, - action_name type - )const; + scope_name code_account, + action_name type + )const; /** * @brief Check authorizations of a vector of actions with provided keys, permission levels, and delay @@ -127,9 +127,9 @@ namespace eosio { namespace chain { fc::microseconds check_canceldelay_authorization( const canceldelay& cancel, const vector& auths )const; std::optional lookup_linked_permission( account_name authorizer_account, - scope_name code_account, - action_name type - )const; + scope_name code_account, + action_name type + )const; }; } } /// namespace eosio::chain diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 298afeeece8..41150618cfb 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -225,12 +225,12 @@ namespace eosio { namespace chain { time_point pending_block_time()const; account_name pending_block_producer()const; const block_signing_authority& pending_block_signing_authority()const; - std::optional pending_producer_block_id()const; + std::optional pending_producer_block_id()const; const deque& get_pending_trx_receipts()const; - const producer_authority_schedule& active_producers()const; - const producer_authority_schedule& pending_producers()const; + const producer_authority_schedule& active_producers()const; + const producer_authority_schedule& pending_producers()const; std::optional proposed_producers()const; uint32_t last_irreversible_block_num() const; diff --git a/libraries/chain/include/eosio/chain/global_property_object.hpp b/libraries/chain/include/eosio/chain/global_property_object.hpp index 5831eafcff4..24ecd26c4f3 100644 --- a/libraries/chain/include/eosio/chain/global_property_object.hpp +++ b/libraries/chain/include/eosio/chain/global_property_object.hpp @@ -26,7 +26,7 @@ namespace eosio { namespace chain { static constexpr uint32_t maximum_version = 2; static_assert(chain_snapshot_header::minimum_compatible_version <= maximum_version, "snapshot_global_property_object_v2 is no longer needed"); - std::optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_schedule_type proposed_schedule; chain_config configuration; }; @@ -35,7 +35,7 @@ namespace eosio { namespace chain { static constexpr uint32_t maximum_version = 3; static_assert(chain_snapshot_header::minimum_compatible_version <= maximum_version, "snapshot_global_property_object_v3 is no longer needed"); - std::optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; @@ -54,7 +54,7 @@ namespace eosio { namespace chain { public: id_type id; - std::optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; shared_producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; @@ -91,7 +91,7 @@ namespace eosio { namespace chain { >; struct snapshot_global_property_object { - std::optional proposed_schedule_block_num; + std::optional proposed_schedule_block_num; producer_authority_schedule proposed_schedule; chain_config configuration; chain_id_type chain_id; diff --git a/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp b/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp index be0db8cea62..87e5c23ecf1 100644 --- a/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp +++ b/libraries/chain/include/eosio/chain/protocol_feature_manager.hpp @@ -93,13 +93,13 @@ class builtin_protocol_feature : public protocol_feature_base { }; struct protocol_feature { - digest_type feature_digest; - digest_type description_digest; - flat_set dependencies; - time_point earliest_allowed_activation_time; - bool preactivation_required = false; - bool enabled = false; - std::optional builtin_feature; + digest_type feature_digest; + digest_type description_digest; + flat_set dependencies; + time_point earliest_allowed_activation_time; + bool preactivation_required = false; + bool enabled = false; + std::optional builtin_feature; fc::variant to_variant( bool include_subjective_restrictions = true, fc::mutable_variant_object* additional_fields = nullptr )const; diff --git a/libraries/chain/include/eosio/chain/thread_utils.hpp b/libraries/chain/include/eosio/chain/thread_utils.hpp index 3869c3b8a67..1645034a0eb 100644 --- a/libraries/chain/include/eosio/chain/thread_utils.hpp +++ b/libraries/chain/include/eosio/chain/thread_utils.hpp @@ -31,7 +31,7 @@ namespace eosio { namespace chain { boost::asio::thread_pool _thread_pool; boost::asio::io_context _ioc; - std::optional _ioc_work; + std::optional _ioc_work; }; diff --git a/libraries/chain/include/eosio/chain/trace.hpp b/libraries/chain/include/eosio/chain/trace.hpp index eabf9146395..a6ad3c7f45c 100644 --- a/libraries/chain/include/eosio/chain/trace.hpp +++ b/libraries/chain/include/eosio/chain/trace.hpp @@ -31,7 +31,7 @@ namespace eosio { namespace chain { fc::unsigned_int action_ordinal; fc::unsigned_int creator_action_ordinal; fc::unsigned_int closest_unnotified_ancestor_action_ordinal; - std::optional receipt; + std::optional receipt; action_name receiver; action act; bool context_free = false; @@ -40,11 +40,11 @@ namespace eosio { namespace chain { transaction_id_type trx_id; ///< the transaction that generated this action uint32_t block_num = 0; block_timestamp_type block_time; - std::optional producer_block_id; + std::optional producer_block_id; flat_set account_ram_deltas; flat_set account_disk_deltas; - std::optional except; - std::optional error_code; + std::optional except; + std::optional error_code; std::vector return_value; }; @@ -52,17 +52,17 @@ namespace eosio { namespace chain { transaction_id_type id; uint32_t block_num = 0; block_timestamp_type block_time; - std::optional producer_block_id; - std::optional receipt; + std::optional producer_block_id; + std::optional receipt; fc::microseconds elapsed; uint64_t net_usage = 0; bool scheduled = false; vector action_traces; - std::optional account_ram_delta; + std::optional account_ram_delta; transaction_trace_ptr failed_dtrx_trace; - std::optional except; - std::optional error_code; + std::optional except; + std::optional error_code; std::exception_ptr except_ptr; }; diff --git a/libraries/chain/include/eosio/chain/transaction_context.hpp b/libraries/chain/include/eosio/chain/transaction_context.hpp index d6d830fc7cb..f0771d12818 100644 --- a/libraries/chain/include/eosio/chain/transaction_context.hpp +++ b/libraries/chain/include/eosio/chain/transaction_context.hpp @@ -150,11 +150,11 @@ namespace eosio { namespace chain { /// Fields: public: - controller& control; - const packed_transaction& packed_trx; - std::optional undo_session; - transaction_trace_ptr trace; - fc::time_point start; + controller& control; + const packed_transaction& packed_trx; + std::optional undo_session; + transaction_trace_ptr trace; + fc::time_point start; fc::time_point published; diff --git a/libraries/fc/include/fc/log/logger_config.hpp b/libraries/fc/include/fc/log/logger_config.hpp index 8d021cdc575..04de647d503 100644 --- a/libraries/fc/include/fc/log/logger_config.hpp +++ b/libraries/fc/include/fc/log/logger_config.hpp @@ -28,11 +28,11 @@ namespace fc { string name; ostring parent; /// if not set, then parents level is used. - std::optional level; + std::optional level; bool enabled; /// if any appenders are sepecified, then parent's appenders are not set. bool additivity; - std::vector appenders; + std::vector appenders; }; struct logging_config { diff --git a/libraries/fc/include/fc/network/url.hpp b/libraries/fc/include/fc/network/url.hpp index 217f4e611a1..c9cd47ce8cb 100644 --- a/libraries/fc/include/fc/network/url.hpp +++ b/libraries/fc/include/fc/network/url.hpp @@ -48,7 +48,7 @@ namespace fc { opath path()const; ostring query()const; ovariant_object args()const; - std::optional port()const; + std::optional port()const; private: friend class mutable_url; diff --git a/libraries/fc/src/log/gelf_appender.cpp b/libraries/fc/src/log/gelf_appender.cpp index cc180773b53..8a7b810ce42 100644 --- a/libraries/fc/src/log/gelf_appender.cpp +++ b/libraries/fc/src/log/gelf_appender.cpp @@ -29,9 +29,9 @@ namespace fc class gelf_appender::impl { public: - config cfg; + config cfg; std::optional gelf_endpoint; - udp_socket gelf_socket; + udp_socket gelf_socket; impl(const config& c) : cfg(c) diff --git a/libraries/fc/src/network/url.cpp b/libraries/fc/src/network/url.cpp index 448fd263f14..defc2ab7c2a 100644 --- a/libraries/fc/src/network/url.cpp +++ b/libraries/fc/src/network/url.cpp @@ -74,7 +74,7 @@ namespace fc opath _path; ostring _query; ovariant_object _args; - std::optional _port; + std::optional _port; }; } @@ -191,7 +191,7 @@ namespace fc { return my->_args; } - std::optional url::port()const + std::optional url::port()const { return my->_port; } diff --git a/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp b/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp index 45b5e870281..cd47a15fe3c 100644 --- a/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp +++ b/libraries/state_history/include/eosio/state_history/transaction_trace_cache.hpp @@ -12,7 +12,7 @@ using chain::transaction_id_type; struct transaction_trace_cache { std::map cached_traces; - std::optional onblock_trace; + std::optional onblock_trace; void add_transaction(const transaction_trace_ptr& trace, const packed_transaction_ptr& transaction); diff --git a/libraries/state_history/include/eosio/state_history/types.hpp b/libraries/state_history/include/eosio/state_history/types.hpp index b45b9fe2500..43d0b509050 100644 --- a/libraries/state_history/include/eosio/state_history/types.hpp +++ b/libraries/state_history/include/eosio/state_history/types.hpp @@ -103,8 +103,8 @@ struct get_blocks_ack_request_v0 { }; struct get_blocks_result_v0 { - block_position head; - block_position last_irreversible; + block_position head; + block_position last_irreversible; std::optional this_block; std::optional prev_block; std::optional block; @@ -149,33 +149,33 @@ struct action { }; struct action_trace_v0 { - fc::unsigned_int action_ordinal = {}; - fc::unsigned_int creator_action_ordinal = {}; + fc::unsigned_int action_ordinal = {}; + fc::unsigned_int creator_action_ordinal = {}; std::optional receipt = {}; - uint64_t receiver = {}; - action act = {}; - bool context_free = {}; - int64_t elapsed = {}; - std::string console = {}; - std::vector account_ram_deltas = {}; + uint64_t receiver = {}; + action act = {}; + bool context_free = {}; + int64_t elapsed = {}; + std::string console = {}; + std::vector account_ram_deltas = {}; std::optional except = {}; std::optional error_code = {}; }; struct action_trace_v1 { - fc::unsigned_int action_ordinal = {}; - fc::unsigned_int creator_action_ordinal = {}; + fc::unsigned_int action_ordinal = {}; + fc::unsigned_int creator_action_ordinal = {}; std::optional receipt = {}; - uint64_t receiver = {}; - action act = {}; - bool context_free = {}; - int64_t elapsed = {}; - std::string console = {}; - std::vector account_ram_deltas = {}; - std::vector account_disk_deltas = {}; + uint64_t receiver = {}; + action act = {}; + bool context_free = {}; + int64_t elapsed = {}; + std::string console = {}; + std::vector account_ram_deltas = {}; + std::vector account_disk_deltas = {}; std::optional except = {}; std::optional error_code = {}; - bytes return_value = {}; + bytes return_value = {}; }; using action_trace = fc::static_variant; @@ -201,7 +201,7 @@ struct partial_transaction_v1 { uint8_t max_cpu_usage_ms = {}; fc::unsigned_int delay_sec = {}; std::vector transaction_extensions = {}; - std::optional prunable_data = {}; + std::optional prunable_data = {}; }; using partial_transaction = fc::static_variant; @@ -209,15 +209,15 @@ using partial_transaction = fc::static_variant; - eosio::chain::digest_type id = {}; - uint8_t status = {}; - uint32_t cpu_usage_us = {}; - fc::unsigned_int net_usage_words = {}; - int64_t elapsed = {}; - uint64_t net_usage = {}; - bool scheduled = {}; - std::vector action_traces = {}; + using transaction_trace = fc::static_variant; + eosio::chain::digest_type id = {}; + uint8_t status = {}; + uint32_t cpu_usage_us = {}; + fc::unsigned_int net_usage_words = {}; + int64_t elapsed = {}; + uint64_t net_usage = {}; + bool scheduled = {}; + std::vector action_traces = {}; std::optional account_ram_delta = {}; std::optional except = {}; std::optional error_code = {}; @@ -225,7 +225,7 @@ struct transaction_trace_v0 { // semantically, this should be std::optional; // it is represented as vector because optional cannot be used for incomplete type std::vector failed_dtrx_trace = {}; - std::optional partial = {}; + std::optional partial = {}; }; using transaction_trace = fc::static_variant; @@ -236,11 +236,11 @@ struct transaction_trace_recurse { using optional_signed_block = std::variant; struct get_blocks_result_v1 { - block_position head; - block_position last_irreversible; + block_position head; + block_position last_irreversible; std::optional this_block; std::optional prev_block; - optional_signed_block block; // packed as std::optional> + optional_signed_block block; // packed as std::optional> opaque> traces; opaque> deltas; }; diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 50d1a81faa1..de070984417 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -154,7 +154,7 @@ class chain_plugin_impl { std::optional genesis; //txn_msg_rate_limits rate_limits; std::optional wasm_runtime; - fc::microseconds abi_serializer_max_time_us; + fc::microseconds abi_serializer_max_time_us; std::optional snapshot_path; @@ -165,7 +165,7 @@ class chain_plugin_impl { channels::irreversible_block::channel_type& irreversible_block_channel; channels::accepted_transaction::channel_type& accepted_transaction_channel; channels::applied_transaction::channel_type& applied_transaction_channel; - incoming::channels::block::channel_type& incoming_block_channel; + incoming::channels::block::channel_type& incoming_block_channel; // retained references to methods for easy calling incoming::methods::block_sync::method_type& incoming_block_sync_method; diff --git a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp index b9bc6d9913e..485d7c2cc4e 100644 --- a/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp @@ -93,39 +93,39 @@ class read_only { using get_info_params = empty; struct get_info_results { - string server_version; - chain::chain_id_type chain_id; - uint32_t head_block_num = 0; - uint32_t last_irreversible_block_num = 0; - chain::block_id_type last_irreversible_block_id; - chain::block_id_type head_block_id; - fc::time_point head_block_time; - account_name head_block_producer; - - uint64_t virtual_block_cpu_limit = 0; - uint64_t virtual_block_net_limit = 0; - - uint64_t block_cpu_limit = 0; - uint64_t block_net_limit = 0; - //string recent_slots; - //double participation_rate = 0; - std::optional server_version_string; + string server_version; + chain::chain_id_type chain_id; + uint32_t head_block_num = 0; + uint32_t last_irreversible_block_num = 0; + chain::block_id_type last_irreversible_block_id; + chain::block_id_type head_block_id; + fc::time_point head_block_time; + account_name head_block_producer; + + uint64_t virtual_block_cpu_limit = 0; + uint64_t virtual_block_net_limit = 0; + + uint64_t block_cpu_limit = 0; + uint64_t block_net_limit = 0; + //string recent_slots; + //double participation_rate = 0; + std::optional server_version_string; std::optional fork_db_head_block_num; std::optional fork_db_head_block_id; - std::optional server_full_version_string; + std::optional server_full_version_string; }; get_info_results get_info(const get_info_params&) const; struct get_activated_protocol_features_params { std::optional lower_bound; std::optional upper_bound; - uint32_t limit = 10; - bool search_by_block_num = false; - bool reverse = false; + uint32_t limit = 10; + bool search_by_block_num = false; + bool reverse = false; }; struct get_activated_protocol_features_results { - fc::variants activated_protocol_features; + fc::variants activated_protocol_features; std::optional more; }; @@ -161,7 +161,7 @@ class read_only { fc::time_point last_code_update; fc::time_point created; - std::optional core_liquid_balance; + std::optional core_liquid_balance; int64_t ram_quota = 0; int64_t net_weight = 0; @@ -181,7 +181,7 @@ class read_only { }; struct get_account_params { - name account_name; + name account_name; std::optional expected_core_symbol; }; get_account_results get_account( const get_account_params& params )const; @@ -192,7 +192,7 @@ class read_only { string wast; string wasm; fc::sha256 code_hash; - std::optional abi; + std::optional abi; }; struct get_code_params { @@ -211,7 +211,7 @@ class read_only { struct get_abi_results { name account_name; - std::optional abi; + std::optional abi; }; struct get_abi_params { @@ -229,15 +229,15 @@ class read_only { }; struct get_raw_abi_params { - name account_name; - std::optional abi_hash; + name account_name; + std::optional abi_hash; }; struct get_raw_abi_results { - name account_name; - fc::sha256 code_hash; - fc::sha256 abi_hash; - std::optional abi; + name account_name; + fc::sha256 code_hash; + fc::sha256 abi_hash; + std::optional abi; }; @@ -307,17 +307,17 @@ class read_only { fc::variant get_block_header_state(const get_block_header_state_params& params) const; struct get_table_rows_params { - bool json = false; - name code; - string scope; - name table; - string table_key; - string lower_bound; - string upper_bound; - uint32_t limit = 10; - string key_type; // type of key specified by index_position - string index_position; // 1 - primary (first), 2 - secondary index (in order defined by multi_index), 3 - third index, etc - string encode_type{"dec"}; //dec, hex , default=dec + bool json = false; + name code; + string scope; + name table; + string table_key; + string lower_bound; + string upper_bound; + uint32_t limit = 10; + string key_type; // type of key specified by index_position + string index_position; // 1 - primary (first), 2 - secondary index (in order defined by multi_index), 3 - third index, etc + string encode_type{"dec"}; //dec, hex , default=dec std::optional reverse; std::optional show_payer; // show RAM pyer }; @@ -331,11 +331,11 @@ class read_only { get_table_rows_result get_table_rows( const get_table_rows_params& params )const; struct get_table_by_scope_params { - name code; // mandatory - name table; // optional, act as filter - string lower_bound; // lower bound of scope, optional - string upper_bound; // upper bound of scope, optional - uint32_t limit = 10; + name code; // mandatory + name table; // optional, act as filter + string lower_bound; // lower bound of scope, optional + string upper_bound; // upper bound of scope, optional + uint32_t limit = 10; std::optional reverse; }; struct get_table_by_scope_result_row { @@ -353,8 +353,8 @@ class read_only { get_table_by_scope_result get_table_by_scope( const get_table_by_scope_params& params )const; struct get_currency_balance_params { - name code; - name account; + name code; + name account; std::optional symbol; }; diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index 6a1472e46e1..365d902f428 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -26,9 +26,9 @@ class read_only { struct get_actions_params { - chain::account_name account_name; - std::optional pos; /// a absolute sequence positon -1 is the end/last action - std::optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) + chain::account_name account_name; + std::optional pos; /// a absolute sequence positon -1 is the end/last action + std::optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) }; struct ordered_action_result { @@ -42,7 +42,7 @@ class read_only { struct get_actions_result { vector actions; uint32_t last_irreversible_block; - std::optional time_limit_exceeded_error; + std::optional time_limit_exceeded_error; }; @@ -51,7 +51,7 @@ class read_only { struct get_transaction_params { string id; - std::optional block_num_hint; + std::optional block_num_hint; }; struct get_transaction_result { diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index bda9977692b..a954aafec6b 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -184,24 +184,24 @@ namespace eosio { // key -> priority, url_handler map url_handlers; std::optional listen_endpoint; - string access_control_allow_origin; - string access_control_allow_headers; - string access_control_max_age; - bool access_control_allow_credentials = false; - size_t max_body_size{1024*1024}; + string access_control_allow_origin; + string access_control_allow_headers; + string access_control_max_age; + bool access_control_allow_credentials = false; + size_t max_body_size{1024*1024}; websocket_server_type server; - uint16_t thread_pool_size = 2; + uint16_t thread_pool_size = 2; std::optional thread_pool; - std::atomic bytes_in_flight{0}; - size_t max_bytes_in_flight = 0; - fc::microseconds max_response_time{30*1000}; + std::atomic bytes_in_flight{0}; + size_t max_bytes_in_flight = 0; + fc::microseconds max_response_time{30*1000}; std::optional https_listen_endpoint; - string https_cert_chain; - string https_key; - https_ecdh_curve_t https_ecdh_curve = SECP384R1; + string https_cert_chain; + string https_key; + https_ecdh_curve_t https_ecdh_curve = SECP384R1; websocket_server_tls_type https_server; diff --git a/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp b/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp index ee8823ddfa8..750ac3a74a3 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/net_plugin.hpp @@ -27,10 +27,10 @@ namespace eosio { void plugin_startup(); void plugin_shutdown(); - string connect( const string& endpoint ); - string disconnect( const string& endpoint ); + string connect( const string& endpoint ); + string disconnect( const string& endpoint ); std::optional status( const string& endpoint )const; - vector connections()const; + vector connections()const; private: std::shared_ptr my; diff --git a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp index ac06b276cfa..f9202fa8301 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/protocol.hpp @@ -136,7 +136,7 @@ namespace eosio { }; struct trx_message_v1 { - std::optional trx_id; // only provided for large trx as trade-off for small trxs not worth it + std::optional trx_id; // only provided for large trx as trade-off for small trxs not worth it std::shared_ptr trx; }; diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 2f519af18ca..250db0eee81 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -269,7 +269,7 @@ namespace eosio { compat::channels::transaction_ack::channel_type::handle incoming_transaction_ack_subscription; - uint16_t thread_pool_size = 2; + uint16_t thread_pool_size = 2; std::optional thread_pool; private: @@ -587,18 +587,18 @@ namespace eosio { std::atomic no_retry{no_reason}; - mutable std::mutex conn_mtx; //< mtx for last_req .. local_endpoint_port + mutable std::mutex conn_mtx; //< mtx for last_req .. local_endpoint_port std::optional last_req; - handshake_message last_handshake_recv; - handshake_message last_handshake_sent; - block_id_type fork_head; - uint32_t fork_head_num{0}; - fc::time_point last_close; - fc::sha256 conn_node_id; - string remote_endpoint_ip; - string remote_endpoint_port; - string local_endpoint_ip; - string local_endpoint_port; + handshake_message last_handshake_recv; + handshake_message last_handshake_sent; + block_id_type fork_head; + uint32_t fork_head_num{0}; + fc::time_point last_close; + fc::sha256 conn_node_id; + string remote_endpoint_ip; + string remote_endpoint_port; + string local_endpoint_ip; + string local_endpoint_port; connection_status get_status()const; diff --git a/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp b/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp index e58f4caaa12..72860a8e1b3 100644 --- a/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp +++ b/plugins/producer_plugin/include/eosio/producer_plugin/producer_plugin.hpp @@ -59,13 +59,13 @@ class producer_plugin : public appbase::plugin { struct get_account_ram_corrections_params { std::optional lower_bound; std::optional upper_bound; - uint32_t limit = 10; - bool reverse = false; + uint32_t limit = 10; + bool reverse = false; }; struct get_account_ram_corrections_result { - std::vector rows; - std::optional more; + std::vector rows; + std::optional more; }; template diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index f9df7ab9beb..efccd967982 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -204,7 +204,7 @@ class producer_plugin_impl : public std::enable_shared_from_this _producer_watermarks; pending_block_mode _pending_block_mode = pending_block_mode::speculating; unapplied_transaction_queue _unapplied_transactions; - std::optional _thread_pool; + std::optional _thread_pool; std::atomic _max_transaction_time_ms; // modified by app thread, read by net_plugin thread pool fc::microseconds _max_irreversible_block_age_us; diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index fcd1a518283..eef63cb57f2 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -42,12 +42,12 @@ auto catch_and_log(F f) { struct state_history_plugin_impl : std::enable_shared_from_this { chain_plugin* chain_plug = nullptr; - std::optional trace_log; - std::optional chain_state_log; + std::optional trace_log; + std::optional chain_state_log; bool stopping = false; - std::optional applied_transaction_connection; - std::optional block_start_connection; - std::optional accepted_block_connection; + std::optional applied_transaction_connection; + std::optional block_start_connection; + std::optional accepted_block_connection; string endpoint_address = "0.0.0.0"; uint16_t endpoint_port = 8080; std::unique_ptr acceptor; @@ -85,7 +85,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this> send_queue; - std::optional current_request; + std::optional current_request; bool need_to_send_update = false; session(std::shared_ptr plugin) diff --git a/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp b/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp index 74b7124ceae..f4a0f1ddaa3 100644 --- a/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp +++ b/plugins/trace_api_plugin/include/eosio/trace_api/chain_extraction.hpp @@ -120,7 +120,7 @@ class chain_extraction_impl_type { StoreProvider store; exception_handler except_handler; std::map cached_traces; - std::optional onblock_trace; + std::optional onblock_trace; }; diff --git a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp index ed7a047de27..89c33b0fa24 100644 --- a/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp +++ b/plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp @@ -97,7 +97,7 @@ struct txn_test_gen_plugin_impl { uint64_t _txcount = 0; uint16_t thread_pool_size; - std::optional thread_pool; + std::optional thread_pool; std::shared_ptr timer; name newaccountA; name newaccountB; diff --git a/programs/eosio-tester/main.cpp b/programs/eosio-tester/main.cpp index 2cab9434beb..18baae26b86 100644 --- a/programs/eosio-tester/main.cpp +++ b/programs/eosio-tester/main.cpp @@ -182,10 +182,10 @@ struct test_chain { fc::temp_directory dir; std::unique_ptr cfg; std::unique_ptr control; - std::optional applied_transaction_connection; - std::optional accepted_block_connection; + std::optional applied_transaction_connection; + std::optional accepted_block_connection; eosio::state_history::transaction_trace_cache trace_cache; - std::optional prev_block; + std::optional prev_block; std::map> history; std::unique_ptr intr_ctx; std::set refs; diff --git a/unittests/state_history_tests.cpp b/unittests/state_history_tests.cpp index eaf36cf7af4..ca6337a3354 100644 --- a/unittests/state_history_tests.cpp +++ b/unittests/state_history_tests.cpp @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(test_state_result_abi) { transaction_trace_cache trace_cache; std::map history; - std::optional prev_block; + std::optional prev_block; chain.control->applied_transaction.connect( [&](std::tuple t) { diff --git a/unittests/whitelist_blacklist_tests.cpp b/unittests/whitelist_blacklist_tests.cpp index b49e4a6eb5e..3392fd22dfc 100644 --- a/unittests/whitelist_blacklist_tests.cpp +++ b/unittests/whitelist_blacklist_tests.cpp @@ -76,7 +76,7 @@ class whitelist_blacklist_tester { private: fc::temp_directory tempdir; // Must come before chain public: - std::optional chain; + std::optional chain; flat_set sender_bypass_whiteblacklist; flat_set actor_whitelist; flat_set actor_blacklist; From fe228e23b805ce376c5faf85507592d23fadebd1 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Fri, 14 Aug 2020 13:44:24 -0400 Subject: [PATCH 13/17] Additional optional changes after rebase. --- libraries/abieos | 2 +- libraries/chain/include/eosio/chain/abi_serializer.hpp | 2 +- libraries/testing/include/eosio/testing/tester.hpp | 7 ++++--- libraries/testing/tester.cpp | 2 +- unittests/api_tests.cpp | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/abieos b/libraries/abieos index f3172ae58d7..89bf52fd718 160000 --- a/libraries/abieos +++ b/libraries/abieos @@ -1 +1 @@ -Subproject commit f3172ae58d759b05f52993aa44ea09f717dd8a4f +Subproject commit 89bf52fd718ef5c45a4b53e34b778e2036dd7c0f diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index e08dfdaa538..08cbc25a827 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -504,7 +504,7 @@ namespace impl { auto act = act_trace.act; try { auto abi = resolver(act.account); - if (abi.valid()) { + if (abi) { auto type = abi->get_action_result_type(act.name); if (!type.empty()) { try { diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 8f8a8818f70..5c1fb2b2828 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -10,6 +10,7 @@ #include #include +#include #define REQUIRE_EQUAL_OBJECTS(left, right) { auto a = fc::variant( left ); auto b = fc::variant( right ); BOOST_REQUIRE_EQUAL( true, a.is_object() ); \ BOOST_REQUIRE_EQUAL( true, b.is_object() ); \ @@ -153,7 +154,7 @@ namespace eosio { namespace testing { virtual ~base_tester() {}; - void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}); + void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}); void init(controller::config config, const snapshot_reader_ptr& snapshot); void init(controller::config config, const genesis_state& genesis); void init(controller::config config); @@ -391,7 +392,7 @@ namespace eosio { namespace testing { return genesis; } - static std::pair default_config(const fc::temp_directory& tempdir, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { + static std::pair default_config(const fc::temp_directory& tempdir, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { controller::config cfg; cfg.blog.log_dir = tempdir.path() / config::default_blocks_dir_name; cfg.state_dir = tempdir.path() / config::default_state_dir_name; @@ -447,7 +448,7 @@ namespace eosio { namespace testing { class tester : public base_tester { public: - tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { + tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { init(policy, read_mode, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); } diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 9d5cede53ea..9ec61d6ed1f 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -150,7 +150,7 @@ namespace eosio { namespace testing { return control->head_block_id() == other.control->head_block_id(); } - void base_tester::init(const setup_policy policy, db_read_mode read_mode, optional genesis_max_inline_action_size, optional config_max_nonprivileged_inline_action_size) { + void base_tester::init(const setup_policy policy, db_read_mode read_mode, std::optional genesis_max_inline_action_size, std::optional config_max_nonprivileged_inline_action_size) { auto def_conf = default_config(tempdir, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); def_conf.first.read_mode = read_mode; cfg = def_conf.first; diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index a7d325d8eba..61a5e04b7c3 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -3669,7 +3669,7 @@ BOOST_FIXTURE_TEST_CASE(action_results_tests, TESTER) { try { BOOST_CHECK_EQUAL( res->receipt->status, transaction_receipt::executed ); auto &atrace = res->action_traces; - BOOST_REQUIRE_EQUAL( atrace[0].receipt.valid(), true ); + BOOST_REQUIRE_EQUAL( atrace[0].receipt.has_value(), true ); BOOST_REQUIRE_EQUAL( atrace[0].return_value.size(), 4 ); BOOST_REQUIRE_EQUAL( fc::raw::unpack(atrace[0].return_value), 10 ); } ); From 38f75f0a26403416df99035ea1c1354a7234c377 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Fri, 14 Aug 2020 15:49:01 -0400 Subject: [PATCH 14/17] Revert "Additional optional changes after rebase." This reverts commit fe228e23b805ce376c5faf85507592d23fadebd1. --- libraries/abieos | 2 +- libraries/chain/include/eosio/chain/abi_serializer.hpp | 2 +- libraries/testing/include/eosio/testing/tester.hpp | 7 +++---- libraries/testing/tester.cpp | 2 +- unittests/api_tests.cpp | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libraries/abieos b/libraries/abieos index 89bf52fd718..f3172ae58d7 160000 --- a/libraries/abieos +++ b/libraries/abieos @@ -1 +1 @@ -Subproject commit 89bf52fd718ef5c45a4b53e34b778e2036dd7c0f +Subproject commit f3172ae58d759b05f52993aa44ea09f717dd8a4f diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index 08cbc25a827..e08dfdaa538 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -504,7 +504,7 @@ namespace impl { auto act = act_trace.act; try { auto abi = resolver(act.account); - if (abi) { + if (abi.valid()) { auto type = abi->get_action_result_type(act.name); if (!type.empty()) { try { diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 5c1fb2b2828..8f8a8818f70 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -10,7 +10,6 @@ #include #include -#include #define REQUIRE_EQUAL_OBJECTS(left, right) { auto a = fc::variant( left ); auto b = fc::variant( right ); BOOST_REQUIRE_EQUAL( true, a.is_object() ); \ BOOST_REQUIRE_EQUAL( true, b.is_object() ); \ @@ -154,7 +153,7 @@ namespace eosio { namespace testing { virtual ~base_tester() {}; - void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}); + void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}); void init(controller::config config, const snapshot_reader_ptr& snapshot); void init(controller::config config, const genesis_state& genesis); void init(controller::config config); @@ -392,7 +391,7 @@ namespace eosio { namespace testing { return genesis; } - static std::pair default_config(const fc::temp_directory& tempdir, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { + static std::pair default_config(const fc::temp_directory& tempdir, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { controller::config cfg; cfg.blog.log_dir = tempdir.path() / config::default_blocks_dir_name; cfg.state_dir = tempdir.path() / config::default_state_dir_name; @@ -448,7 +447,7 @@ namespace eosio { namespace testing { class tester : public base_tester { public: - tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { + tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { init(policy, read_mode, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); } diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 9ec61d6ed1f..9d5cede53ea 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -150,7 +150,7 @@ namespace eosio { namespace testing { return control->head_block_id() == other.control->head_block_id(); } - void base_tester::init(const setup_policy policy, db_read_mode read_mode, std::optional genesis_max_inline_action_size, std::optional config_max_nonprivileged_inline_action_size) { + void base_tester::init(const setup_policy policy, db_read_mode read_mode, optional genesis_max_inline_action_size, optional config_max_nonprivileged_inline_action_size) { auto def_conf = default_config(tempdir, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); def_conf.first.read_mode = read_mode; cfg = def_conf.first; diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 61a5e04b7c3..a7d325d8eba 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -3669,7 +3669,7 @@ BOOST_FIXTURE_TEST_CASE(action_results_tests, TESTER) { try { BOOST_CHECK_EQUAL( res->receipt->status, transaction_receipt::executed ); auto &atrace = res->action_traces; - BOOST_REQUIRE_EQUAL( atrace[0].receipt.has_value(), true ); + BOOST_REQUIRE_EQUAL( atrace[0].receipt.valid(), true ); BOOST_REQUIRE_EQUAL( atrace[0].return_value.size(), 4 ); BOOST_REQUIRE_EQUAL( fc::raw::unpack(atrace[0].return_value), 10 ); } ); From 5b2dd32e68c633ec85e8a3536fbeb4e15bc06761 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Fri, 14 Aug 2020 16:41:03 -0400 Subject: [PATCH 15/17] Revert abieos changes and redo additional optional changes. --- libraries/chain/include/eosio/chain/abi_serializer.hpp | 2 +- libraries/testing/include/eosio/testing/tester.hpp | 7 ++++--- libraries/testing/tester.cpp | 2 +- unittests/api_tests.cpp | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index e08dfdaa538..08cbc25a827 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -504,7 +504,7 @@ namespace impl { auto act = act_trace.act; try { auto abi = resolver(act.account); - if (abi.valid()) { + if (abi) { auto type = abi->get_action_result_type(act.name); if (!type.empty()) { try { diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index 8f8a8818f70..5c1fb2b2828 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -10,6 +10,7 @@ #include #include +#include #define REQUIRE_EQUAL_OBJECTS(left, right) { auto a = fc::variant( left ); auto b = fc::variant( right ); BOOST_REQUIRE_EQUAL( true, a.is_object() ); \ BOOST_REQUIRE_EQUAL( true, b.is_object() ); \ @@ -153,7 +154,7 @@ namespace eosio { namespace testing { virtual ~base_tester() {}; - void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}); + void init(const setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}); void init(controller::config config, const snapshot_reader_ptr& snapshot); void init(controller::config config, const genesis_state& genesis); void init(controller::config config); @@ -391,7 +392,7 @@ namespace eosio { namespace testing { return genesis; } - static std::pair default_config(const fc::temp_directory& tempdir, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { + static std::pair default_config(const fc::temp_directory& tempdir, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { controller::config cfg; cfg.blog.log_dir = tempdir.path() / config::default_blocks_dir_name; cfg.state_dir = tempdir.path() / config::default_state_dir_name; @@ -447,7 +448,7 @@ namespace eosio { namespace testing { class tester : public base_tester { public: - tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, optional genesis_max_inline_action_size = optional{}, optional config_max_nonprivileged_inline_action_size = optional{}) { + tester(setup_policy policy = setup_policy::full, db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional genesis_max_inline_action_size = std::optional{}, std::optional config_max_nonprivileged_inline_action_size = std::optional{}) { init(policy, read_mode, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); } diff --git a/libraries/testing/tester.cpp b/libraries/testing/tester.cpp index 9d5cede53ea..9ec61d6ed1f 100644 --- a/libraries/testing/tester.cpp +++ b/libraries/testing/tester.cpp @@ -150,7 +150,7 @@ namespace eosio { namespace testing { return control->head_block_id() == other.control->head_block_id(); } - void base_tester::init(const setup_policy policy, db_read_mode read_mode, optional genesis_max_inline_action_size, optional config_max_nonprivileged_inline_action_size) { + void base_tester::init(const setup_policy policy, db_read_mode read_mode, std::optional genesis_max_inline_action_size, std::optional config_max_nonprivileged_inline_action_size) { auto def_conf = default_config(tempdir, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size); def_conf.first.read_mode = read_mode; cfg = def_conf.first; diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index a7d325d8eba..61a5e04b7c3 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -3669,7 +3669,7 @@ BOOST_FIXTURE_TEST_CASE(action_results_tests, TESTER) { try { BOOST_CHECK_EQUAL( res->receipt->status, transaction_receipt::executed ); auto &atrace = res->action_traces; - BOOST_REQUIRE_EQUAL( atrace[0].receipt.valid(), true ); + BOOST_REQUIRE_EQUAL( atrace[0].receipt.has_value(), true ); BOOST_REQUIRE_EQUAL( atrace[0].return_value.size(), 4 ); BOOST_REQUIRE_EQUAL( fc::raw::unpack(atrace[0].return_value), 10 ); } ); From 8fe3e694c29dcdc84c1ee2a2cd19210ce0c20964 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Mon, 24 Aug 2020 13:12:01 -0400 Subject: [PATCH 16/17] Move abi_tests over to std::optional --- unittests/abi_tests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index f6f92274402..cd751bf5a79 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -2836,13 +2836,13 @@ BOOST_AUTO_TEST_CASE(serialize_optional_struct_type) } template -inline std::pair generate_action_trace(const fc::optional & return_value, const std::string & return_value_hex, bool parsable = true) +inline std::pair generate_action_trace(const std::optional & return_value, const std::string & return_value_hex, bool parsable = true) { action_trace at; at.action_ordinal = 0; at.creator_action_ordinal = 1; at.closest_unnotified_ancestor_action_ordinal = 2; - at.receipt = fc::optional{}; + at.receipt = std::optional{}; at.receiver = action_name{"test"}; at.act = eosio::chain::action( std::vector{ @@ -2857,8 +2857,8 @@ inline std::pair generate_action_trace(const fc::opti at.trx_id = transaction_id_type{"5d039021cf3262c5036a6ad40a809ae1440ae6c6792a48e6e95abf083b108d5f"}; at.block_num = 4; at.block_time = block_timestamp_type{5}; - at.producer_block_id = fc::optional{}; - if (return_value.valid()) { + at.producer_block_id = std::optional{}; + if (return_value.has_value()) { at.return_value = fc::raw::pack(*return_value); } std::stringstream expected_json; @@ -2891,7 +2891,7 @@ inline std::pair generate_action_trace(const fc::opti << "\"except\":null," << "\"error_code\":null," << "\"return_value_hex_data\":\"" << return_value_hex << "\""; - if (return_value.valid() && parsable) { + if (return_value.has_value() && parsable) { if (std::is_same::value) { expected_json << ",\"return_value_data\":\"" << *return_value << "\""; @@ -2909,14 +2909,14 @@ inline std::pair generate_action_trace(const fc::opti } inline std::pair generate_action_trace() { - return generate_action_trace(fc::optional(), ""); + return generate_action_trace(std::optional(), ""); } BOOST_AUTO_TEST_CASE(abi_to_variant__add_action__good_return_value) { action_trace at; std::string expected_json; - std::tie(at, expected_json) = generate_action_trace(fc::optional{6}, "0600"); + std::tie(at, expected_json) = generate_action_trace(std::optional{6}, "0600"); auto abi = R"({ "version": "eosio::abi/1.0", @@ -2947,7 +2947,7 @@ BOOST_AUTO_TEST_CASE(abi_to_variant__add_action__bad_return_value) { action_trace at; std::string expected_json; - std::tie(at, expected_json) = generate_action_trace(fc::optional{"no return"}, "096e6f2072657475726e", false); + std::tie(at, expected_json) = generate_action_trace(std::optional{"no return"}, "096e6f2072657475726e", false); auto abi = R"({ "version": "eosio::abi/1.0", From 366776306b1f117f37df888d325ece439b554c6f Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Tue, 25 Aug 2020 16:37:17 -0400 Subject: [PATCH 17/17] Merge Develop --- CMakeLists.txt | 4 + libraries/appbase/CMakeLists.txt | 2 +- libraries/appbase/application.cpp | 2 +- libraries/chain/CMakeLists.txt | 2 +- .../chain/webassembly/runtimes/eos-vm.cpp | 365 ++++++++++++++++- .../runtimes/host_function_registrator.cpp | 370 ------------------ libraries/fc/src/network/http/http_client.cpp | 3 +- plugins/http_plugin/http_plugin.cpp | 102 +++-- 8 files changed, 446 insertions(+), 404 deletions(-) delete mode 100644 libraries/chain/webassembly/runtimes/host_function_registrator.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f2fd9152bc6..ac7d58bd584 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID} endif() endif() +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +endif() + if ("${CMAKE_GENERATOR}" STREQUAL "Ninja") add_compile_options(-fdiagnostics-color=always) endif() diff --git a/libraries/appbase/CMakeLists.txt b/libraries/appbase/CMakeLists.txt index bd209d5f7f6..f34f7a12757 100644 --- a/libraries/appbase/CMakeLists.txt +++ b/libraries/appbase/CMakeLists.txt @@ -44,7 +44,6 @@ endif() add_library( appbase application.cpp - version.cpp ${HEADERS} ) @@ -64,6 +63,7 @@ else() set(VERSION_STRING "Unknown") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.cpp @ONLY ESCAPE_QUOTES) endif() +target_sources(appbase PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.cpp) set(CPACK_PACKAGING_INSTALL_PREFIX /) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index ea4112f1acd..6572468e199 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -446,7 +446,7 @@ void application::print_default_config(std::ostream& os) { option_to_plug[opt->long_name()] = plug.second->name(); } - for(const boost::shared_ptr od : my->_cfg_options.options()) + for(const auto& od : my->_cfg_options.options()) { if(!od->description().empty()) { std::string desc = od->description(); diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index c2d628a4148..9a91022c8b1 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -49,7 +49,7 @@ if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES) endif() if("eos-vm" IN_LIST EOSIO_WASM_RUNTIMES OR "eos-vm-jit" IN_LIST EOSIO_WASM_RUNTIMES) - set(CHAIN_EOSVM_SOURCES "webassembly/runtimes/eos-vm.cpp" "webassembly/runtimes/host_function_registrator.cpp") + set(CHAIN_EOSVM_SOURCES "webassembly/runtimes/eos-vm.cpp") set(CHAIN_EOSVM_LIBRARIES eos-vm) endif() diff --git a/libraries/chain/webassembly/runtimes/eos-vm.cpp b/libraries/chain/webassembly/runtimes/eos-vm.cpp index b6502ea1a1a..1c53b62d654 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm.cpp @@ -6,6 +6,12 @@ #include //eos-vm includes #include +#include +#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED +#include +#endif +#include +#include namespace eosio { namespace chain { namespace webassembly { namespace eos_vm_runtime { @@ -189,4 +195,361 @@ std::unique_ptr eos_vm_runtime::instan template class eos_vm_runtime; template class eos_vm_runtime; -}}}} +} + +template +struct host_function_registrator { + template + constexpr host_function_registrator(Mod mod_name, Name fn_name) { + using rhf_t = eos_vm_host_functions_t; + rhf_t::add(mod_name.c_str(), fn_name.c_str()); +#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED + constexpr bool is_injected = (Mod() == BOOST_HANA_STRING(EOSIO_INJECTED_MODULE_NAME)); + eosvmoc::register_eosvm_oc>( + mod_name + BOOST_HANA_STRING(".") + fn_name); +#endif + } +}; + +#define REGISTER_INJECTED_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, ##__VA_ARGS__> NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING(EOSIO_INJECTED_MODULE_NAME), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +#define REGISTER_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, core_precondition, context_aware_check, ##__VA_ARGS__> \ + NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +#define REGISTER_CF_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, core_precondition, ##__VA_ARGS__> NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +#define REGISTER_LEGACY_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, context_aware_check, ##__VA_ARGS__> \ + NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +#define REGISTER_LEGACY_CF_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, ##__VA_ARGS__> \ + NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +#define REGISTER_LEGACY_CF_ONLY_HOST_FUNCTION(NAME, ...) \ + static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, context_free_check, ##__VA_ARGS__> \ + NAME##_registrator_impl() { \ + return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ + } \ + inline static auto NAME##_registrator = NAME##_registrator_impl(); + +// context free api +REGISTER_LEGACY_CF_ONLY_HOST_FUNCTION(get_context_free_data) + +// privileged api +REGISTER_HOST_FUNCTION(is_feature_active, privileged_check); +REGISTER_HOST_FUNCTION(activate_feature, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(preactivate_feature, privileged_check); +REGISTER_HOST_FUNCTION(set_resource_limits, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(get_resource_limits, privileged_check); +REGISTER_HOST_FUNCTION(set_resource_limit, privileged_check); +REGISTER_HOST_FUNCTION(get_resource_limit, privileged_check); +REGISTER_HOST_FUNCTION(get_wasm_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(set_wasm_parameters_packed, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(set_proposed_producers, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(set_proposed_producers_ex, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(get_blockchain_parameters_packed, privileged_check); +REGISTER_LEGACY_HOST_FUNCTION(set_blockchain_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(get_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(set_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(get_kv_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(set_kv_parameters_packed, privileged_check); +REGISTER_HOST_FUNCTION(is_privileged, privileged_check); +REGISTER_HOST_FUNCTION(set_privileged, privileged_check); + +// softfloat api +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_add); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_sub); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_div); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_mul); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_min); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_max); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_copysign); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_abs); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_neg); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_sqrt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ceil); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_floor); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_nearest); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_eq); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ne); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_lt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_le); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_gt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ge); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_add); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_sub); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_div); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_mul); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_min); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_max); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_copysign); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_abs); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_neg); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_sqrt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ceil); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_floor); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_nearest); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_eq); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ne); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_lt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_le); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_gt); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ge); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_promote); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_demote); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i32s); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i32s); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i32u); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i32u); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i64s); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i64s); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i64u); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i64u); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_i32_to_f32); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_i64_to_f32); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui32_to_f32); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui64_to_f32); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_i32_to_f64); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_i64_to_f64); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui32_to_f64); +REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui64_to_f64); + +// producer api +REGISTER_LEGACY_HOST_FUNCTION(get_active_producers); + +// crypto api +REGISTER_LEGACY_CF_HOST_FUNCTION(assert_recover_key); +REGISTER_LEGACY_CF_HOST_FUNCTION(recover_key); +REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha256); +REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha1); +REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha512); +REGISTER_LEGACY_CF_HOST_FUNCTION(assert_ripemd160); +REGISTER_LEGACY_CF_HOST_FUNCTION(sha256); +REGISTER_LEGACY_CF_HOST_FUNCTION(sha1); +REGISTER_LEGACY_CF_HOST_FUNCTION(sha512); +REGISTER_LEGACY_CF_HOST_FUNCTION(ripemd160); + +// permission api +REGISTER_LEGACY_HOST_FUNCTION(check_transaction_authorization); +REGISTER_LEGACY_HOST_FUNCTION(check_permission_authorization); +REGISTER_HOST_FUNCTION(get_permission_last_used); +REGISTER_HOST_FUNCTION(get_account_creation_time); + +// authorization api +REGISTER_HOST_FUNCTION(require_auth); +REGISTER_HOST_FUNCTION(require_auth2); +REGISTER_HOST_FUNCTION(has_auth); +REGISTER_HOST_FUNCTION(require_recipient); +REGISTER_HOST_FUNCTION(is_account); + +// system api +REGISTER_HOST_FUNCTION(current_time); +REGISTER_HOST_FUNCTION(publication_time); +REGISTER_LEGACY_HOST_FUNCTION(is_feature_activated); +REGISTER_HOST_FUNCTION(get_sender); + +// context-free system api +REGISTER_CF_HOST_FUNCTION(abort) +REGISTER_LEGACY_CF_HOST_FUNCTION(eosio_assert) +REGISTER_LEGACY_CF_HOST_FUNCTION(eosio_assert_message) +REGISTER_CF_HOST_FUNCTION(eosio_assert_code) +REGISTER_CF_HOST_FUNCTION(eosio_exit) + +// action api +REGISTER_LEGACY_CF_HOST_FUNCTION(read_action_data); +REGISTER_CF_HOST_FUNCTION(action_data_size); +REGISTER_CF_HOST_FUNCTION(current_receiver); +REGISTER_HOST_FUNCTION(set_action_return_value); + +// console api +REGISTER_LEGACY_CF_HOST_FUNCTION(prints); +REGISTER_LEGACY_CF_HOST_FUNCTION(prints_l); +REGISTER_CF_HOST_FUNCTION(printi); +REGISTER_CF_HOST_FUNCTION(printui); +REGISTER_LEGACY_CF_HOST_FUNCTION(printi128); +REGISTER_LEGACY_CF_HOST_FUNCTION(printui128); +REGISTER_CF_HOST_FUNCTION(printsf); +REGISTER_CF_HOST_FUNCTION(printdf); +REGISTER_LEGACY_CF_HOST_FUNCTION(printqf); +REGISTER_CF_HOST_FUNCTION(printn); +REGISTER_LEGACY_CF_HOST_FUNCTION(printhex); + +// database api +// primary index api +REGISTER_LEGACY_HOST_FUNCTION(db_store_i64); +REGISTER_LEGACY_HOST_FUNCTION(db_update_i64); +REGISTER_HOST_FUNCTION(db_remove_i64); +REGISTER_LEGACY_HOST_FUNCTION(db_get_i64); +REGISTER_LEGACY_HOST_FUNCTION(db_next_i64); +REGISTER_LEGACY_HOST_FUNCTION(db_previous_i64); +REGISTER_HOST_FUNCTION(db_find_i64); +REGISTER_HOST_FUNCTION(db_lowerbound_i64); +REGISTER_HOST_FUNCTION(db_upperbound_i64); +REGISTER_HOST_FUNCTION(db_end_i64); + +// uint64_t secondary index api +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_store); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_update); +REGISTER_HOST_FUNCTION(db_idx64_remove); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_find_secondary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_find_primary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_lowerbound); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_upperbound); +REGISTER_HOST_FUNCTION(db_idx64_end); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_next); +REGISTER_LEGACY_HOST_FUNCTION(db_idx64_previous); + +// uint128_t secondary index api +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_store); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_update); +REGISTER_HOST_FUNCTION(db_idx128_remove); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_find_secondary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_find_primary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_lowerbound); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_upperbound); +REGISTER_HOST_FUNCTION(db_idx128_end); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_next); +REGISTER_LEGACY_HOST_FUNCTION(db_idx128_previous); + +// 256-bit secondary index api +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_store); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_update); +REGISTER_HOST_FUNCTION(db_idx256_remove); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_find_secondary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_find_primary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_lowerbound); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_upperbound); +REGISTER_HOST_FUNCTION(db_idx256_end); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_next); +REGISTER_LEGACY_HOST_FUNCTION(db_idx256_previous); + +// double secondary index api +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_store, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_update, is_nan_check); +REGISTER_HOST_FUNCTION(db_idx_double_remove); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_find_secondary, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_find_primary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_lowerbound, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_upperbound, is_nan_check); +REGISTER_HOST_FUNCTION(db_idx_double_end); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_next); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_previous); + +// long double secondary index api +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_store, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_update, is_nan_check); +REGISTER_HOST_FUNCTION(db_idx_long_double_remove); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_find_secondary, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_find_primary); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_lowerbound, is_nan_check); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_upperbound, is_nan_check); +REGISTER_HOST_FUNCTION(db_idx_long_double_end); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_next); +REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_previous); + +// kv database api +REGISTER_HOST_FUNCTION(kv_erase); +REGISTER_HOST_FUNCTION(kv_set); +REGISTER_HOST_FUNCTION(kv_get); +REGISTER_HOST_FUNCTION(kv_get_data); +REGISTER_HOST_FUNCTION(kv_it_create); +REGISTER_HOST_FUNCTION(kv_it_destroy); +REGISTER_HOST_FUNCTION(kv_it_status); +REGISTER_HOST_FUNCTION(kv_it_compare); +REGISTER_HOST_FUNCTION(kv_it_key_compare); +REGISTER_HOST_FUNCTION(kv_it_move_to_end); +REGISTER_HOST_FUNCTION(kv_it_next); +REGISTER_HOST_FUNCTION(kv_it_prev); +REGISTER_HOST_FUNCTION(kv_it_lower_bound); +REGISTER_HOST_FUNCTION(kv_it_key); +REGISTER_HOST_FUNCTION(kv_it_value); + +// memory api +REGISTER_LEGACY_CF_HOST_FUNCTION(memcpy); +REGISTER_LEGACY_CF_HOST_FUNCTION(memmove); +REGISTER_LEGACY_CF_HOST_FUNCTION(memcmp); +REGISTER_LEGACY_CF_HOST_FUNCTION(memset); + +// transaction api +REGISTER_LEGACY_HOST_FUNCTION(send_inline); +REGISTER_LEGACY_HOST_FUNCTION(send_context_free_inline); +REGISTER_LEGACY_HOST_FUNCTION(send_deferred); +REGISTER_LEGACY_HOST_FUNCTION(cancel_deferred); + +// context-free transaction api +REGISTER_LEGACY_CF_HOST_FUNCTION(read_transaction); +REGISTER_CF_HOST_FUNCTION(transaction_size); +REGISTER_CF_HOST_FUNCTION(expiration); +REGISTER_CF_HOST_FUNCTION(tapos_block_num); +REGISTER_CF_HOST_FUNCTION(tapos_block_prefix); +REGISTER_LEGACY_CF_HOST_FUNCTION(get_action); + +// compiler builtins api +REGISTER_LEGACY_CF_HOST_FUNCTION(__ashlti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__ashrti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__lshlti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__lshrti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__divti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__udivti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__multi3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__modti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__umodti3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__addtf3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__subtf3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__multf3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__divtf3); +REGISTER_LEGACY_CF_HOST_FUNCTION(__negtf2); +REGISTER_LEGACY_CF_HOST_FUNCTION(__extendsftf2); +REGISTER_LEGACY_CF_HOST_FUNCTION(__extenddftf2); +REGISTER_CF_HOST_FUNCTION(__trunctfdf2); +REGISTER_CF_HOST_FUNCTION(__trunctfsf2); +REGISTER_CF_HOST_FUNCTION(__fixtfsi); +REGISTER_CF_HOST_FUNCTION(__fixtfdi); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixtfti); +REGISTER_CF_HOST_FUNCTION(__fixunstfsi); +REGISTER_CF_HOST_FUNCTION(__fixunstfdi); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunstfti); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixsfti); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixdfti); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunssfti); +REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunsdfti); +REGISTER_CF_HOST_FUNCTION(__floatsidf); +REGISTER_LEGACY_CF_HOST_FUNCTION(__floatsitf); +REGISTER_LEGACY_CF_HOST_FUNCTION(__floatditf); +REGISTER_LEGACY_CF_HOST_FUNCTION(__floatunsitf); +REGISTER_LEGACY_CF_HOST_FUNCTION(__floatunditf); +REGISTER_CF_HOST_FUNCTION(__floattidf); +REGISTER_CF_HOST_FUNCTION(__floatuntidf); +REGISTER_CF_HOST_FUNCTION(__cmptf2); +REGISTER_CF_HOST_FUNCTION(__eqtf2); +REGISTER_CF_HOST_FUNCTION(__netf2); +REGISTER_CF_HOST_FUNCTION(__getf2); +REGISTER_CF_HOST_FUNCTION(__gttf2); +REGISTER_CF_HOST_FUNCTION(__letf2); +REGISTER_CF_HOST_FUNCTION(__lttf2); +REGISTER_CF_HOST_FUNCTION(__unordtf2); + +} // namespace webassembly +} // namespace chain +} // namespace eosio diff --git a/libraries/chain/webassembly/runtimes/host_function_registrator.cpp b/libraries/chain/webassembly/runtimes/host_function_registrator.cpp deleted file mode 100644 index b18434f2494..00000000000 --- a/libraries/chain/webassembly/runtimes/host_function_registrator.cpp +++ /dev/null @@ -1,370 +0,0 @@ - -#include -#include -#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED -#include -#endif -#include -#include -#include - -namespace eosio { -namespace chain { -namespace webassembly { - -template -struct host_function_registrator { - template - constexpr host_function_registrator(Mod mod_name, Name fn_name) { - using rhf_t = eos_vm_host_functions_t; - rhf_t::add(mod_name.c_str(), fn_name.c_str()); -#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED - constexpr bool is_injected = (Mod() == BOOST_HANA_STRING(EOSIO_INJECTED_MODULE_NAME)); - eosvmoc::register_eosvm_oc>( - mod_name + BOOST_HANA_STRING(".") + fn_name); -#endif - } -}; - -#define REGISTER_INJECTED_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, ##__VA_ARGS__> NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING(EOSIO_INJECTED_MODULE_NAME), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -#define REGISTER_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, core_precondition, context_aware_check, ##__VA_ARGS__> \ - NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -#define REGISTER_CF_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, core_precondition, ##__VA_ARGS__> NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -#define REGISTER_LEGACY_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, context_aware_check, ##__VA_ARGS__> \ - NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -#define REGISTER_LEGACY_CF_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, ##__VA_ARGS__> \ - NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -#define REGISTER_LEGACY_CF_ONLY_HOST_FUNCTION(NAME, ...) \ - static host_function_registrator<&interface::NAME, legacy_static_check_wl_args, context_free_check, ##__VA_ARGS__> \ - NAME##_registrator_impl() { \ - return {BOOST_HANA_STRING("env"), BOOST_HANA_STRING(#NAME)}; \ - } \ - inline static auto NAME##_registrator = NAME##_registrator_impl(); - -// context free api -REGISTER_LEGACY_CF_ONLY_HOST_FUNCTION(get_context_free_data) - -// privileged api -REGISTER_HOST_FUNCTION(is_feature_active, privileged_check); -REGISTER_HOST_FUNCTION(activate_feature, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(preactivate_feature, privileged_check); -REGISTER_HOST_FUNCTION(set_resource_limits, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(get_resource_limits, privileged_check); -REGISTER_HOST_FUNCTION(set_resource_limit, privileged_check); -REGISTER_HOST_FUNCTION(get_resource_limit, privileged_check); -REGISTER_HOST_FUNCTION(get_wasm_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(set_wasm_parameters_packed, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(set_proposed_producers, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(set_proposed_producers_ex, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(get_blockchain_parameters_packed, privileged_check); -REGISTER_LEGACY_HOST_FUNCTION(set_blockchain_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(get_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(set_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(get_kv_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(set_kv_parameters_packed, privileged_check); -REGISTER_HOST_FUNCTION(is_privileged, privileged_check); -REGISTER_HOST_FUNCTION(set_privileged, privileged_check); - -// softfloat api -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_add); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_sub); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_div); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_mul); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_min); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_max); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_copysign); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_abs); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_neg); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_sqrt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ceil); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_floor); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_nearest); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_eq); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ne); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_lt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_le); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_gt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_ge); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_add); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_sub); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_div); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_mul); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_min); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_max); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_copysign); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_abs); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_neg); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_sqrt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ceil); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_floor); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_nearest); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_eq); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ne); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_lt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_le); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_gt); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_ge); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_promote); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_demote); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i32s); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i32s); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i32u); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i32u); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i64s); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i64s); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f32_trunc_i64u); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_f64_trunc_i64u); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_i32_to_f32); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_i64_to_f32); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui32_to_f32); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui64_to_f32); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_i32_to_f64); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_i64_to_f64); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui32_to_f64); -REGISTER_INJECTED_HOST_FUNCTION(_eosio_ui64_to_f64); - -// producer api -REGISTER_LEGACY_HOST_FUNCTION(get_active_producers); - -// crypto api -REGISTER_LEGACY_CF_HOST_FUNCTION(assert_recover_key); -REGISTER_LEGACY_CF_HOST_FUNCTION(recover_key); -REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha256); -REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha1); -REGISTER_LEGACY_CF_HOST_FUNCTION(assert_sha512); -REGISTER_LEGACY_CF_HOST_FUNCTION(assert_ripemd160); -REGISTER_LEGACY_CF_HOST_FUNCTION(sha256); -REGISTER_LEGACY_CF_HOST_FUNCTION(sha1); -REGISTER_LEGACY_CF_HOST_FUNCTION(sha512); -REGISTER_LEGACY_CF_HOST_FUNCTION(ripemd160); - -// permission api -REGISTER_LEGACY_HOST_FUNCTION(check_transaction_authorization); -REGISTER_LEGACY_HOST_FUNCTION(check_permission_authorization); -REGISTER_HOST_FUNCTION(get_permission_last_used); -REGISTER_HOST_FUNCTION(get_account_creation_time); - -// authorization api -REGISTER_HOST_FUNCTION(require_auth); -REGISTER_HOST_FUNCTION(require_auth2); -REGISTER_HOST_FUNCTION(has_auth); -REGISTER_HOST_FUNCTION(require_recipient); -REGISTER_HOST_FUNCTION(is_account); - -// system api -REGISTER_HOST_FUNCTION(current_time); -REGISTER_HOST_FUNCTION(publication_time); -REGISTER_LEGACY_HOST_FUNCTION(is_feature_activated); -REGISTER_HOST_FUNCTION(get_sender); - -// context-free system api -REGISTER_CF_HOST_FUNCTION(abort) -REGISTER_LEGACY_CF_HOST_FUNCTION(eosio_assert) -REGISTER_LEGACY_CF_HOST_FUNCTION(eosio_assert_message) -REGISTER_CF_HOST_FUNCTION(eosio_assert_code) -REGISTER_CF_HOST_FUNCTION(eosio_exit) - -// action api -REGISTER_LEGACY_CF_HOST_FUNCTION(read_action_data); -REGISTER_CF_HOST_FUNCTION(action_data_size); -REGISTER_CF_HOST_FUNCTION(current_receiver); -REGISTER_HOST_FUNCTION(set_action_return_value); - -// console api -REGISTER_LEGACY_CF_HOST_FUNCTION(prints); -REGISTER_LEGACY_CF_HOST_FUNCTION(prints_l); -REGISTER_CF_HOST_FUNCTION(printi); -REGISTER_CF_HOST_FUNCTION(printui); -REGISTER_LEGACY_CF_HOST_FUNCTION(printi128); -REGISTER_LEGACY_CF_HOST_FUNCTION(printui128); -REGISTER_CF_HOST_FUNCTION(printsf); -REGISTER_CF_HOST_FUNCTION(printdf); -REGISTER_LEGACY_CF_HOST_FUNCTION(printqf); -REGISTER_CF_HOST_FUNCTION(printn); -REGISTER_LEGACY_CF_HOST_FUNCTION(printhex); - -// database api -// primary index api -REGISTER_LEGACY_HOST_FUNCTION(db_store_i64); -REGISTER_LEGACY_HOST_FUNCTION(db_update_i64); -REGISTER_HOST_FUNCTION(db_remove_i64); -REGISTER_LEGACY_HOST_FUNCTION(db_get_i64); -REGISTER_LEGACY_HOST_FUNCTION(db_next_i64); -REGISTER_LEGACY_HOST_FUNCTION(db_previous_i64); -REGISTER_HOST_FUNCTION(db_find_i64); -REGISTER_HOST_FUNCTION(db_lowerbound_i64); -REGISTER_HOST_FUNCTION(db_upperbound_i64); -REGISTER_HOST_FUNCTION(db_end_i64); - -// uint64_t secondary index api -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_store); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_update); -REGISTER_HOST_FUNCTION(db_idx64_remove); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_find_secondary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_find_primary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_lowerbound); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_upperbound); -REGISTER_HOST_FUNCTION(db_idx64_end); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_next); -REGISTER_LEGACY_HOST_FUNCTION(db_idx64_previous); - -// uint128_t secondary index api -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_store); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_update); -REGISTER_HOST_FUNCTION(db_idx128_remove); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_find_secondary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_find_primary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_lowerbound); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_upperbound); -REGISTER_HOST_FUNCTION(db_idx128_end); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_next); -REGISTER_LEGACY_HOST_FUNCTION(db_idx128_previous); - -// 256-bit secondary index api -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_store); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_update); -REGISTER_HOST_FUNCTION(db_idx256_remove); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_find_secondary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_find_primary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_lowerbound); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_upperbound); -REGISTER_HOST_FUNCTION(db_idx256_end); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_next); -REGISTER_LEGACY_HOST_FUNCTION(db_idx256_previous); - -// double secondary index api -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_store, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_update, is_nan_check); -REGISTER_HOST_FUNCTION(db_idx_double_remove); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_find_secondary, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_find_primary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_lowerbound, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_upperbound, is_nan_check); -REGISTER_HOST_FUNCTION(db_idx_double_end); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_next); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_double_previous); - -// long double secondary index api -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_store, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_update, is_nan_check); -REGISTER_HOST_FUNCTION(db_idx_long_double_remove); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_find_secondary, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_find_primary); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_lowerbound, is_nan_check); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_upperbound, is_nan_check); -REGISTER_HOST_FUNCTION(db_idx_long_double_end); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_next); -REGISTER_LEGACY_HOST_FUNCTION(db_idx_long_double_previous); - -// kv database api -REGISTER_HOST_FUNCTION(kv_erase); -REGISTER_HOST_FUNCTION(kv_set); -REGISTER_HOST_FUNCTION(kv_get); -REGISTER_HOST_FUNCTION(kv_get_data); -REGISTER_HOST_FUNCTION(kv_it_create); -REGISTER_HOST_FUNCTION(kv_it_destroy); -REGISTER_HOST_FUNCTION(kv_it_status); -REGISTER_HOST_FUNCTION(kv_it_compare); -REGISTER_HOST_FUNCTION(kv_it_key_compare); -REGISTER_HOST_FUNCTION(kv_it_move_to_end); -REGISTER_HOST_FUNCTION(kv_it_next); -REGISTER_HOST_FUNCTION(kv_it_prev); -REGISTER_HOST_FUNCTION(kv_it_lower_bound); -REGISTER_HOST_FUNCTION(kv_it_key); -REGISTER_HOST_FUNCTION(kv_it_value); - -// memory api -REGISTER_LEGACY_CF_HOST_FUNCTION(memcpy); -REGISTER_LEGACY_CF_HOST_FUNCTION(memmove); -REGISTER_LEGACY_CF_HOST_FUNCTION(memcmp); -REGISTER_LEGACY_CF_HOST_FUNCTION(memset); - -// transaction api -REGISTER_LEGACY_HOST_FUNCTION(send_inline); -REGISTER_LEGACY_HOST_FUNCTION(send_context_free_inline); -REGISTER_LEGACY_HOST_FUNCTION(send_deferred); -REGISTER_LEGACY_HOST_FUNCTION(cancel_deferred); - -// context-free transaction api -REGISTER_LEGACY_CF_HOST_FUNCTION(read_transaction); -REGISTER_CF_HOST_FUNCTION(transaction_size); -REGISTER_CF_HOST_FUNCTION(expiration); -REGISTER_CF_HOST_FUNCTION(tapos_block_num); -REGISTER_CF_HOST_FUNCTION(tapos_block_prefix); -REGISTER_LEGACY_CF_HOST_FUNCTION(get_action); - -// compiler builtins api -REGISTER_LEGACY_CF_HOST_FUNCTION(__ashlti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__ashrti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__lshlti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__lshrti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__divti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__udivti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__multi3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__modti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__umodti3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__addtf3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__subtf3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__multf3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__divtf3); -REGISTER_LEGACY_CF_HOST_FUNCTION(__negtf2); -REGISTER_LEGACY_CF_HOST_FUNCTION(__extendsftf2); -REGISTER_LEGACY_CF_HOST_FUNCTION(__extenddftf2); -REGISTER_CF_HOST_FUNCTION(__trunctfdf2); -REGISTER_CF_HOST_FUNCTION(__trunctfsf2); -REGISTER_CF_HOST_FUNCTION(__fixtfsi); -REGISTER_CF_HOST_FUNCTION(__fixtfdi); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixtfti); -REGISTER_CF_HOST_FUNCTION(__fixunstfsi); -REGISTER_CF_HOST_FUNCTION(__fixunstfdi); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunstfti); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixsfti); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixdfti); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunssfti); -REGISTER_LEGACY_CF_HOST_FUNCTION(__fixunsdfti); -REGISTER_CF_HOST_FUNCTION(__floatsidf); -REGISTER_LEGACY_CF_HOST_FUNCTION(__floatsitf); -REGISTER_LEGACY_CF_HOST_FUNCTION(__floatditf); -REGISTER_LEGACY_CF_HOST_FUNCTION(__floatunsitf); -REGISTER_LEGACY_CF_HOST_FUNCTION(__floatunditf); -REGISTER_CF_HOST_FUNCTION(__floattidf); -REGISTER_CF_HOST_FUNCTION(__floatuntidf); -REGISTER_CF_HOST_FUNCTION(__cmptf2); -REGISTER_CF_HOST_FUNCTION(__eqtf2); -REGISTER_CF_HOST_FUNCTION(__netf2); -REGISTER_CF_HOST_FUNCTION(__getf2); -REGISTER_CF_HOST_FUNCTION(__gttf2); -REGISTER_CF_HOST_FUNCTION(__letf2); -REGISTER_CF_HOST_FUNCTION(__lttf2); -REGISTER_CF_HOST_FUNCTION(__unordtf2); - -} // namespace webassembly -} // namespace chain -} // namespace eosio \ No newline at end of file diff --git a/libraries/fc/src/network/http/http_client.cpp b/libraries/fc/src/network/http/http_client.cpp index 0718ef30ae5..6c0a82db98e 100644 --- a/libraries/fc/src/network/http/http_client.cpp +++ b/libraries/fc/src/network/http/http_client.cpp @@ -372,8 +372,7 @@ class http_client_impl { excp = std::make_shared(err_var["code"].as_int64(), err_var["name"].as_string(), err_var["what"].as_string()); if (err_var.contains("details")) { - auto details = err_var["details"].get_array(); - for (const auto dvar : details) { + for (const auto& dvar : err_var["details"].get_array()) { excp->append_log(FC_LOG_MESSAGE(error, dvar.get_object()["message"].as_string())); } } diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index afd3a1e068c..3c1685c1dc9 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -133,7 +133,10 @@ namespace eosio { struct abstract_conn { virtual ~abstract_conn() {} virtual bool verify_max_bytes_in_flight() = 0; + virtual bool verify_max_requests_in_flight() = 0; virtual void handle_exception() = 0; + + virtual void send_response(std::string body, int code) = 0; }; using abstract_conn_ptr = std::shared_ptr; @@ -192,11 +195,13 @@ namespace eosio { websocket_server_type server; - uint16_t thread_pool_size = 2; - std::optional thread_pool; - std::atomic bytes_in_flight{0}; - size_t max_bytes_in_flight = 0; - fc::microseconds max_response_time{30*1000}; + uint16_t thread_pool_size = 2; + std::optional thread_pool; + std::atomic bytes_in_flight{0}; + std::atomic requests_in_flight{0}; + size_t max_bytes_in_flight = 0; + int32_t max_requests_in_flight = -1; + fc::microseconds max_response_time{30*1000}; std::optional https_listen_endpoint; string https_cert_chain; @@ -322,25 +327,46 @@ namespace eosio { return true; } + template + void report_429_error( const T& con, const std::string & what) { + error_results::error_info ei; + ei.code = websocketpp::http::status_code::too_many_requests; + ei.name = "Busy"; + ei.what = what; + error_results results{websocketpp::http::status_code::too_many_requests, "Busy", ei}; + con->set_body( fc::json::to_string( results, fc::time_point::maximum() )); + con->set_status( websocketpp::http::status_code::too_many_requests ); + con->send_http_response(); + } + template bool verify_max_bytes_in_flight( const T& con ) { auto bytes_in_flight_size = bytes_in_flight.load(); if( bytes_in_flight_size > max_bytes_in_flight ) { fc_dlog( logger, "429 - too many bytes in flight: ${bytes}", ("bytes", bytes_in_flight_size) ); - error_results::error_info ei; - ei.code = websocketpp::http::status_code::too_many_requests; - ei.name = "Busy"; - ei.what = "Too many bytes in flight: " + std::to_string( bytes_in_flight_size ); - error_results results{websocketpp::http::status_code::too_many_requests, "Busy", ei}; - con->set_body( fc::json::to_string( results, fc::time_point::maximum() )); - con->set_status( websocketpp::http::status_code::too_many_requests ); - con->send_http_response(); + string what = "Too many bytes in flight: " + std::to_string( bytes_in_flight_size ) + ". Try again later.";; + report_429_error(con, what); return false; } return true; } + template + bool verify_max_requests_in_flight( const T& con ) { + if (max_requests_in_flight < 0) + return true; + + auto requests_in_flight_num = requests_in_flight.load(); + if( requests_in_flight_num > max_requests_in_flight ) { + fc_dlog( logger, "429 - too many requests in flight: ${requests}", ("requests", requests_in_flight_num) ); + string what = "Too many requests in flight: " + std::to_string( requests_in_flight_num ) + ". Try again later."; + report_429_error(con, what); + return false; + } + return true; + } + /** * child struct, implementing abstract connection for various underlying connection types * that ties it to an http_plugin_impl @@ -352,20 +378,38 @@ namespace eosio { abstract_conn_impl(detail::connection_ptr conn, http_plugin_impl& impl) :_conn(std::move(conn)) ,_impl(impl) - {} + { + _impl.requests_in_flight += 1; + } + + ~abstract_conn_impl() { + _impl.requests_in_flight -= 1; + } + + // No copy constructor and no move + abstract_conn_impl(abstract_conn_impl&) = delete; + abstract_conn_impl(abstract_conn_impl&&) = delete; - ~abstract_conn_impl() = default; - abstract_conn_impl(abstract_conn_impl&&) = default; abstract_conn_impl& operator=(abstract_conn_impl&&) noexcept = default; bool verify_max_bytes_in_flight() override { return _impl.verify_max_bytes_in_flight(_conn); } + bool verify_max_requests_in_flight() override { + return _impl.verify_max_requests_in_flight(_conn); + } + void handle_exception()override { http_plugin_impl::handle_exception(_conn); } + void send_response(std::string body, int code) override { + _conn->set_body(std::move(body)); + _conn->set_status( websocketpp::http::status_code::value( code ) ); + _conn->send_http_response(); + } + detail::connection_ptr _conn; http_plugin_impl &_impl; }; @@ -449,7 +493,7 @@ namespace eosio { */ template static auto make_in_flight(T&& object, http_plugin_impl& impl) { - return std::make_shared>(in_flight(std::forward(object), impl)); + return std::make_shared>(std::forward(object), impl); } /** @@ -512,23 +556,21 @@ namespace eosio { * @return lambda suitable for url_response_callback */ template - auto make_http_response_handler( detail::connection_ptr con ) { - return [this, con]( int code, fc::variant response ) { + auto make_http_response_handler( detail::abstract_conn_ptr abstract_conn_ptr ) { + return [this, abstract_conn_ptr]( int code, fc::variant response ) { auto tracked_response = make_in_flight(std::move(response), *this); - if (!verify_max_bytes_in_flight(con)) { + if (!abstract_conn_ptr->verify_max_bytes_in_flight()) { return; } // post back to an HTTP thread to to allow the response handler to be called from any thread - boost::asio::post( thread_pool->get_executor(), [this, con, code, tracked_response=std::move(tracked_response)]() { + boost::asio::post( thread_pool->get_executor(), [this, abstract_conn_ptr, code, tracked_response=std::move(tracked_response)]() { try { std::string json = fc::json::to_string( *(*tracked_response), fc::time_point::now() + max_response_time ); auto tracked_json = make_in_flight(std::move(json), *this); - con->set_body( std::move( *(*tracked_json) ) ); - con->set_status( websocketpp::http::status_code::value( code ) ); - con->send_http_response(); + abstract_conn_ptr->send_response(std::move(*(*tracked_json)), code); } catch( ... ) { - handle_exception( con ); + abstract_conn_ptr->handle_exception(); } }); }; @@ -563,13 +605,14 @@ namespace eosio { con->append_header( "Content-type", "application/json" ); con->defer_http_response(); - if( !verify_max_bytes_in_flight( con ) ) return; + auto abstract_conn_ptr = make_abstract_conn_ptr(con, *this); + if( !verify_max_bytes_in_flight( con ) || !verify_max_requests_in_flight( con ) ) return; std::string resource = con->get_uri()->get_resource(); auto handler_itr = url_handlers.find( resource ); if( handler_itr != url_handlers.end()) { std::string body = con->get_request_body(); - handler_itr->second( make_abstract_conn_ptr(con, *this), std::move( resource ), std::move( body ), make_http_response_handler(con) ); + handler_itr->second( abstract_conn_ptr, std::move( resource ), std::move( body ), make_http_response_handler(abstract_conn_ptr) ); } else { fc_dlog( logger, "404 - not found: ${ep}", ("ep", resource) ); error_results results{websocketpp::http::status_code::not_found, @@ -688,7 +731,9 @@ namespace eosio { ("max-body-size", bpo::value()->default_value(1024*1024), "The maximum body size in bytes allowed for incoming RPC requests") ("http-max-bytes-in-flight-mb", bpo::value()->default_value(500), - "Maximum size in megabytes http_plugin should use for processing http requests. 503 error response when exceeded." ) + "Maximum size in megabytes http_plugin should use for processing http requests. 429 error response when exceeded." ) + ("http-max-in-flight-requests", bpo::value()->default_value(-1), + "Maximum number of requests http_plugin should use for processing http requests. 429 error response when exceeded." ) ("http-max-response-time-ms", bpo::value()->default_value(30), "Maximum time for processing a request.") ("verbose-http-errors", bpo::bool_switch()->default_value(false), @@ -778,6 +823,7 @@ namespace eosio { "http-threads ${num} must be greater than 0", ("num", my->thread_pool_size)); my->max_bytes_in_flight = options.at( "http-max-bytes-in-flight-mb" ).as() * 1024 * 1024; + my->max_requests_in_flight = options.at( "http-max-in-flight-requests" ).as(); my->max_response_time = fc::microseconds( options.at("http-max-response-time-ms").as() * 1000 ); //watch out for the returns above when adding new code here