From 6b593c2d8f09d55669e4dfc135937a3c902599f4 Mon Sep 17 00:00:00 2001 From: Reverse Flash Date: Thu, 15 Sep 2016 15:27:29 -0400 Subject: [PATCH] some work toward fixed sized memory and memory mapped files --- CMakeLists.txt | 2 +- libraries/app/database_api.cpp | 28 ++- libraries/app/impacted.cpp | 2 +- .../app/include/steemit/app/database_api.hpp | 6 +- libraries/app/include/steemit/app/state.hpp | 2 +- libraries/chain/block_database.cpp | 6 +- libraries/chain/database.cpp | 68 ++++--- .../include/steemit/chain/account_object.hpp | 64 +++---- .../include/steemit/chain/comment_object.hpp | 106 +---------- .../chain/include/steemit/chain/database.hpp | 26 +-- .../steemit/chain/global_property_object.hpp | 2 +- .../include/steemit/chain/history_object.hpp | 6 +- .../steemit/chain/protocol/authority.hpp | 15 +- .../chain/protocol/steem_operations.hpp | 169 +++++++++--------- .../include/steemit/chain/protocol/types.hpp | 7 +- .../include/steemit/chain/steem_objects.hpp | 72 ++++---- .../include/steemit/chain/witness_objects.hpp | 35 ++-- libraries/chain/protocol/authority.cpp | 2 +- libraries/chain/protocol/steem_operations.cpp | 8 +- libraries/chain/steem_evaluator.cpp | 3 +- .../include/graphene/db/object_database.hpp | 33 ++-- .../db/include/graphene/db/undo_database.hpp | 3 +- libraries/fc | 2 +- libraries/plugins/follow/follow_plugin.cpp | 21 ++- libraries/plugins/raw_block/raw_block_api.cpp | 8 +- programs/util/CMakeLists.txt | 6 + tests/tests/serialization_tests.cpp | 26 +++ 27 files changed, 356 insertions(+), 372 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3a021f7b9..53ceed7d8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,7 @@ else( WIN32 ) # Apple AND Linux if( APPLE ) # Apple Specific Options Here message( STATUS "Configuring Steem on OS X" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall -Wno-conversion" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) else( APPLE ) # Linux Specific Options Here message( STATUS "Configuring Steem on Linux" ) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 9fb3b72ac9..633fffe174 100755 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -60,7 +60,7 @@ class database_api_impl : public std::enable_shared_from_this // Witnesses vector> get_witnesses(const vector& witness_ids)const; fc::optional get_witness_by_account( string account_name )const; - set lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; + set lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; uint64_t get_witness_count()const; // Market @@ -581,12 +581,12 @@ fc::optional database_api_impl::get_witness_by_account( string a return {}; } -set< string > database_api::lookup_witness_accounts( const string& lower_bound_name, uint32_t limit ) const +set< account_name_type > database_api::lookup_witness_accounts( const string& lower_bound_name, uint32_t limit ) const { return my->lookup_witness_accounts( lower_bound_name, limit ); } -set< string > database_api_impl::lookup_witness_accounts( const string& lower_bound_name, uint32_t limit ) const +set< account_name_type > database_api_impl::lookup_witness_accounts( const string& lower_bound_name, uint32_t limit ) const { FC_ASSERT( limit <= 1000 ); const auto& witnesses_by_id = _db.get_index_type< witness_index >().indices().get< by_id >(); @@ -594,7 +594,7 @@ set< string > database_api_impl::lookup_witness_accounts( const string& lower_bo // get all the names and look them all up, sort them, then figure out what // records to return. This could be optimized, but we expect the // number of witnesses to be few and the frequency of calls to be rare - set< std::string > witnesses_by_account_name; + set< account_name_type > witnesses_by_account_name; for ( const witness_object& witness : witnesses_by_id ) if ( witness.owner >= lower_bound_name ) // we can ignore anything below lower_bound_name witnesses_by_account_name.insert( witness.owner ); @@ -843,7 +843,7 @@ bool database_api_impl::verify_account_authority( const string& name_or_id, cons /// reuse trx.verify_authority by creating a dummy transfer signed_transaction trx; transfer_operation op; - op.from = account->id; + op.from = account->name; trx.operations.emplace_back(op); return verify_authority( trx ); @@ -1013,6 +1013,8 @@ vector database_api::get_content_replies( string author, string perm vector database_api::get_replies_by_last_update( string start_parent_author, string start_permlink, uint32_t limit )const { // idump((start_parent_author)(start_permlink)(limit) ); + vector result; + /* const auto& last_update_idx = my->_db.get_index_type< comment_index >().indices().get< by_last_update >(); auto itr = last_update_idx.begin(); @@ -1026,7 +1028,6 @@ vector database_api::get_replies_by_last_update( string start_parent filter_by_parent_author = true; } - vector result; while( itr != last_update_idx.end() && result.size() < limit ) { if( filter_by_parent_author && itr->parent_author != start_parent_author ) { return result; @@ -1037,6 +1038,7 @@ vector database_api::get_replies_by_last_update( string start_parent result.back().active_votes = get_active_votes( itr->author, itr->permlink ); ++itr; } + */ return result; } @@ -1353,8 +1355,8 @@ void database_api::recursively_fetch_content( state& _state, discussion& root, s } } FC_CAPTURE_AND_RETHROW( (root.author)(root.permlink) ) } -vector database_api::get_miner_queue()const { - vector result; +vector database_api::get_miner_queue()const { + vector result; const auto& pow_idx = my->_db.get_index_type().indices().get(); auto itr = pow_idx.upper_bound(0); @@ -1366,7 +1368,7 @@ vector database_api::get_miner_queue()const { return result; } -vector database_api::get_active_witnesses()const { +vector database_api::get_active_witnesses()const { const auto& wso = my->_db.get_witness_schedule_object(); return wso.current_shuffled_witnesses; } @@ -1378,6 +1380,7 @@ vector database_api::get_discussions_by_author_before_date( { vector result; + /* FC_ASSERT( limit <= 100 ); result.reserve( limit ); int count = 0; @@ -1406,6 +1409,7 @@ vector database_api::get_discussions_by_author_before_date( } ++itr; } + */ return result; } @@ -1518,6 +1522,7 @@ state database_api::get_state( string path )const } } } else if( part[1] == "recent-replies" ) { + /* auto replies = get_replies_by_last_update( acnt, "", 50 ); eacnt.recent_replies = vector(); for( const auto& reply : replies ) { @@ -1529,7 +1534,9 @@ state database_api::get_state( string path )const } eacnt.recent_replies->push_back( reply_ref ); } + */ } else if( part[1] == "posts" ) { + /* int count = 0; const auto& pidx = my->_db.get_index_type().indices().get(); auto itr = pidx.lower_bound( boost::make_tuple(acnt, time_point_sec::maximum() ) ); @@ -1541,7 +1548,9 @@ state database_api::get_state( string path )const ++itr; ++count; } + */ } else if( part[1].size() == 0 || part[1] == "blog" ) { + /* int count = 0; const auto& pidx = my->_db.get_index_type().indices().get(); auto itr = pidx.lower_bound( boost::make_tuple(acnt, std::string(""), time_point_sec::maximum() ) ); @@ -1553,6 +1562,7 @@ state database_api::get_state( string path )const ++itr; ++count; } + */ } else if( part[1].size() == 0 || part[1] == "feed" ) { if( my->_follow_api ) diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index 9b968c396e..2239fb2f56 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -110,7 +110,7 @@ struct get_impacted_account_visitor { _impacted.insert( op.from ); - if ( !op.to.empty() && op.to != op.from ) + if ( op.to != account_name_type() && op.to != op.from ) { _impacted.insert( op.to ); } diff --git a/libraries/app/include/steemit/app/database_api.hpp b/libraries/app/include/steemit/app/database_api.hpp index 2605ff6e7f..eaa2a08a4a 100755 --- a/libraries/app/include/steemit/app/database_api.hpp +++ b/libraries/app/include/steemit/app/database_api.hpp @@ -129,8 +129,8 @@ class database_api vector get_active_categories( string after, uint32_t limit )const; vector get_recent_categories( string after, uint32_t limit )const; - vector get_active_witnesses()const; - vector get_miner_queue()const; + vector get_active_witnesses()const; + vector get_miner_queue()const; ///////////////////////////// // Blocks and transactions // @@ -255,7 +255,7 @@ class database_api * @param limit Maximum number of results to return -- must not exceed 1000 * @return Map of witness names to corresponding IDs */ - set lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; + set lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const; /** * @brief Get the total number of witnesses registered with the blockchain diff --git a/libraries/app/include/steemit/app/state.hpp b/libraries/app/include/steemit/app/state.hpp index bac68b8928..29c23f3457 100644 --- a/libraries/app/include/steemit/app/state.hpp +++ b/libraries/app/include/steemit/app/state.hpp @@ -155,7 +155,7 @@ namespace steemit { namespace app { /** * The list of miners who are queued to produce work */ - vector pow_queue; + vector pow_queue; map witnesses; witness_schedule_object witness_schedule; price feed_price; diff --git a/libraries/chain/block_database.cpp b/libraries/chain/block_database.cpp index 7e2f488cc0..1e08a06de6 100644 --- a/libraries/chain/block_database.cpp +++ b/libraries/chain/block_database.cpp @@ -172,11 +172,13 @@ optional block_database::fetch_by_number( uint32_t block_num )cons FC_ASSERT( result.id() == e.block_id ); return result; } - catch (const fc::exception&) + catch (const fc::exception& e) { + idump((e.to_detail_string())); } - catch (const std::exception&) + catch (const std::exception& e) { + idump((e.what())); } return optional(); } diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index f6dfe749d7..add2c20abe 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -145,7 +145,7 @@ void database::reindex(fc::path data_dir ) if( !block.valid() ) { // TODO gap handling may not properly init fork db - wlog( "Reindexing terminated due to gap: Block ${i} does not exist!", ("i", i) ); + wlog( "Reindexing terminated due to error unpacking block: Block ${i}", ("i", i) ); uint32_t dropped_count = 0; while( true ) { @@ -182,6 +182,7 @@ void database::reindex(fc::path data_dir ) skip_transaction_signatures | skip_transaction_dupe_check | skip_tapos_check | + skip_merkle_check | skip_witness_schedule_check | skip_authority_check | skip_validate | /// no need to validate operations @@ -340,7 +341,7 @@ chain_id_type database::get_chain_id() const return STEEMIT_CHAIN_ID; } -const account_object& database::get_account( const string& name )const +const account_object& database::get_account( const account_name_type& name )const { const auto& accounts_by_name = get_index_type().indices().get(); auto itr = accounts_by_name.find(name); @@ -350,14 +351,14 @@ const account_object& database::get_account( const string& name )const return *itr; } -const escrow_object& database::get_escrow( const string& name, uint32_t escrow_id )const { +const escrow_object& database::get_escrow( const account_name_type& name, uint32_t escrow_id )const { const auto& escrow_idx = get_index_type().indices().get(); auto itr = escrow_idx.find( boost::make_tuple(name,escrow_id) ); FC_ASSERT( itr != escrow_idx.end() ); return *itr; } -const limit_order_object* database::find_limit_order( const string& name, uint32_t orderid )const +const limit_order_object* database::find_limit_order( const account_name_type& name, uint32_t orderid )const { if( !has_hardfork( STEEMIT_HARDFORK_0_6__127 ) ) orderid = orderid & 0x0000FFFF; @@ -367,7 +368,7 @@ const limit_order_object* database::find_limit_order( const string& name, uint32 return &*itr; } -const limit_order_object& database::get_limit_order( const string& name, uint32_t orderid )const +const limit_order_object& database::get_limit_order( const account_name_type& name, uint32_t orderid )const { if( !has_hardfork( STEEMIT_HARDFORK_0_6__127 ) ) orderid = orderid & 0x0000FFFF; @@ -379,7 +380,7 @@ const limit_order_object& database::get_limit_order( const string& name, uint32_ return *itr; } -const witness_object& database::get_witness( const string& name ) const +const witness_object& database::get_witness( const account_name_type& name ) const { const auto& witnesses_by_name = get_index_type< witness_index >().indices().get< by_name >(); auto itr = witnesses_by_name.find( name ); @@ -389,7 +390,7 @@ const witness_object& database::get_witness( const string& name ) const return *itr; } -const witness_object* database::find_witness( const string& name ) const +const witness_object* database::find_witness( const account_name_type& name ) const { const auto& witnesses_by_name = get_index_type< witness_index >().indices().get< by_name >(); auto itr = witnesses_by_name.find( name ); @@ -397,7 +398,7 @@ const witness_object* database::find_witness( const string& name ) const return &*itr; } -const comment_object& database::get_comment( const string& author, const string& permlink )const +const comment_object& database::get_comment( const account_name_type& author, const string& permlink )const { try { @@ -409,14 +410,14 @@ const comment_object& database::get_comment( const string& author, const string& FC_CAPTURE_AND_RETHROW( (author)(permlink) ) } -const comment_object* database::find_comment( const string& author, const string& permlink )const +const comment_object* database::find_comment( const account_name_type& author, const string& permlink )const { const auto& by_permlink_idx = get_index_type< comment_index >().indices().get< by_permlink >(); auto itr = by_permlink_idx.find( boost::make_tuple( author, permlink ) ); return itr == by_permlink_idx.end() ? nullptr : &*itr; } -const savings_withdraw_object& database::get_savings_withdraw( const string& owner, uint32_t request_id )const +const savings_withdraw_object& database::get_savings_withdraw( const account_name_type& owner, uint32_t request_id )const { try { @@ -428,7 +429,7 @@ const savings_withdraw_object& database::get_savings_withdraw( const string& own FC_CAPTURE_AND_RETHROW( (owner)(request_id) ) } -const savings_withdraw_object* database::find_savings_withdraw( const string& owner, uint32_t request_id )const +const savings_withdraw_object* database::find_savings_withdraw( const account_name_type& owner, uint32_t request_id )const { const auto& savings_withdraw_idx = get_index_type< withdraw_index >().indices().get< by_from_rid >(); auto itr = savings_withdraw_idx.find( boost::make_tuple( owner, request_id ) ); @@ -438,7 +439,7 @@ const savings_withdraw_object* database::find_savings_withdraw( const string& ow const time_point_sec database::calculate_discussion_payout_time( const comment_object& comment )const { - if( comment.parent_author == "" ) + if( comment.parent_author == account_name_type() ) return comment.cashout_time; else return comment.root_comment( *this ).cashout_time; @@ -723,7 +724,7 @@ void database::_push_transaction( const signed_transaction& trx ) signed_block database::generate_block( fc::time_point_sec when, - const string& witness_owner, + const account_name_type& witness_owner, const fc::ecc::private_key& block_signing_private_key, uint32_t skip /* = 0 */ ) @@ -743,7 +744,7 @@ signed_block database::generate_block( signed_block database::_generate_block( fc::time_point_sec when, - const string& witness_owner, + const account_name_type& witness_owner, const fc::ecc::private_key& block_signing_private_key ) { @@ -948,7 +949,7 @@ void database::notify_on_applied_transaction( const signed_transaction& tx ) STEEMIT_TRY_NOTIFY( on_applied_transaction, tx ) } -string database::get_scheduled_witness( uint32_t slot_num )const +account_name_type database::get_scheduled_witness( uint32_t slot_num )const { const dynamic_global_property_object& dpo = get_dynamic_global_properties(); const witness_schedule_object& wso = witness_schedule_id_type()(*this); @@ -1091,7 +1092,7 @@ uint32_t database::get_pow_summary_target()const void database::update_witness_schedule4() { - vector active_witnesses; + vector active_witnesses; /// Add the highest voted witnesses flat_set selected_voted; @@ -1193,7 +1194,7 @@ void database::update_witness_schedule4() if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) ) { flat_map< version, uint32_t, std::greater< version > > witness_versions; - flat_map< std::tuple< hardfork_version, time_point_sec >, uint32_t > hardfork_version_votes; + flat_map< std::pair< hardfork_version, time_point_sec >, uint32_t > hardfork_version_votes; for( uint32_t i = 0; i < wso.current_shuffled_witnesses.size(); i++ ) { @@ -1233,12 +1234,16 @@ void database::update_witness_schedule4() { if( hf_itr->second >= STEEMIT_HARDFORK_REQUIRED_WITNESSES ) { - modify( hardfork_property_id_type()( *this ), [&]( hardfork_property_object& hpo ) - { - hpo.next_hardfork = std::get<0>( hf_itr->first ); - hpo.next_hardfork_time = std::get<1>( hf_itr->first ); - } ); + const auto& hfp = hardfork_property_id_type()( *this ); + if( hfp.next_hardfork != std::get<0>( hf_itr->first ) || + hfp.next_hardfork_time != std::get<1>( hf_itr->first ) ) { + modify( hfp, [&]( hardfork_property_object& hpo ) + { + hpo.next_hardfork = std::get<0>( hf_itr->first ); + hpo.next_hardfork_time = std::get<1>( hf_itr->first ); + } ); + } break; } @@ -1304,7 +1309,7 @@ void database::update_witness_schedule() const witness_schedule_object& wso = witness_schedule_id_type()(*this); - vector active_witnesses; + vector active_witnesses; active_witnesses.reserve( STEEMIT_MAX_MINERS ); fc::uint128 new_virtual_time; @@ -2701,7 +2706,7 @@ void database::notify_changed_objects() //////////////////// private methods //////////////////// void database::apply_block( const signed_block& next_block, uint32_t skip ) -{ +{ try { auto block_num = next_block.block_num(); if( _checkpoints.size() && _checkpoints.rbegin()->second != block_id_type() ) { @@ -2737,7 +2742,7 @@ void database::apply_block( const signed_block& next_block, uint32_t skip ) validate_invariants(); } FC_CAPTURE_AND_RETHROW( (next_block) );*/ -} +} FC_CAPTURE_AND_RETHROW( (next_block) ) } void database::_apply_block( const signed_block& next_block ) { try { @@ -2772,8 +2777,12 @@ void database::_apply_block( const signed_block& next_block ) if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) ) // Cannot remove after hardfork { - FC_ASSERT( get_witness( next_block.witness ).running_version >= hardfork_property_id_type()( *this ).current_hardfork_version, - "Block produced by witness that is not running current hardfork" ); + const auto& witness = get_witness( next_block.witness ); + const auto& hardfork_state = hardfork_property_id_type()( *this ); + FC_ASSERT( witness.running_version >= hardfork_state.current_hardfork_version, + "Block produced by witness that is not running current hardfork", + ("witness",witness)("next_block.witness",next_block.witness)("hardfork_state", hardfork_state) + ); } for( const auto& trx : next_block.transactions ) @@ -2838,6 +2847,7 @@ void database::process_header_extensions( const signed_block& next_block ) { auto reported_version = itr->get< version >(); const auto& signing_witness = get_witness( next_block.witness ); + //idump( (next_block.witness)(signing_witness.running_version)(reported_version) ); if( reported_version != signing_witness.running_version ) { @@ -2852,6 +2862,7 @@ void database::process_header_extensions( const signed_block& next_block ) { auto hfv = itr->get< hardfork_version_vote >(); const auto& signing_witness = get_witness( next_block.witness ); + //idump( (next_block.witness)(signing_witness.running_version)(hfv) ); if( hfv.hf_version != signing_witness.hardfork_version_vote || hfv.hf_time != signing_witness.hardfork_time_vote ) modify( signing_witness, [&]( witness_object& wo ) @@ -3681,8 +3692,9 @@ void database::process_hardforks() while( _hardfork_versions[ hardforks.last_hardfork ] < hardforks.next_hardfork && hardforks.next_hardfork_time <= head_block_time() ) { - if( hardforks.last_hardfork < STEEMIT_NUM_HARDFORKS ) + if( hardforks.last_hardfork < STEEMIT_NUM_HARDFORKS ) { apply_hardfork( hardforks.last_hardfork + 1 ); + } else throw unknown_hardfork_exception(); } diff --git a/libraries/chain/include/steemit/chain/account_object.hpp b/libraries/chain/include/steemit/chain/account_object.hpp index 5576cf701c..4a9b77147e 100644 --- a/libraries/chain/include/steemit/chain/account_object.hpp +++ b/libraries/chain/include/steemit/chain/account_object.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -19,25 +20,25 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_account_object_type; - string name; - authority owner; ///< used for backup control, can set owner or active - authority active; ///< used for all monetary operations, can set active or posting - authority posting; ///< used for voting and posting - public_key_type memo_key; - string json_metadata = ""; - string proxy; + account_name_type name; + authority owner; ///< used for backup control, can set owner or active + authority active; ///< used for all monetary operations, can set active or posting + authority posting; ///< used for voting and posting + public_key_type memo_key; + string json_metadata; + account_name_type proxy; time_point_sec last_owner_update; time_point_sec last_account_update; - time_point_sec created; - bool mined = true; - bool owner_challenged = false; - bool active_challenged = false; - time_point_sec last_owner_proved = time_point_sec::min(); - time_point_sec last_active_proved = time_point_sec::min(); - string recovery_account = ""; - string reset_account = STEEMIT_NULL_ACCOUNT; + time_point_sec created; + bool mined = true; + bool owner_challenged = false; + bool active_challenged = false; + time_point_sec last_owner_proved = time_point_sec::min(); + time_point_sec last_active_proved = time_point_sec::min(); + account_name_type recovery_account; + account_name_type reset_account = STEEMIT_NULL_ACCOUNT; time_point_sec last_account_recovery; uint32_t comment_count = 0; uint32_t lifetime_vote_count = 0; @@ -88,7 +89,8 @@ namespace steemit { namespace chain { share_type to_withdraw = 0; /// Might be able to look this up with operation history. uint16_t withdraw_routes = 0; - std::vector proxied_vsf_votes = std::vector( STEEMIT_MAX_PROXY_RECURSION_DEPTH, 0 ); ///< the total VFS votes proxied to this account + fc::array proxied_vsf_votes;// = std::vector( STEEMIT_MAX_PROXY_RECURSION_DEPTH, 0 ); ///< the total VFS votes proxied to this account + uint16_t witnesses_voted_for = 0; /** @@ -163,7 +165,7 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_owner_authority_history_object_type; - string account; + account_name_type account; authority previous_owner_authority; time_point_sec last_valid_time; @@ -176,9 +178,9 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_account_recovery_request_object_type; - string account_to_recover; - authority new_owner_authority; - time_point_sec expires; + account_name_type account_to_recover; + authority new_owner_authority; + time_point_sec expires; account_recovery_request_id_type get_id()const { return id; } }; @@ -189,9 +191,9 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_change_recovery_account_request_object_type; - string account_to_recover; - string recovery_account; - time_point_sec effective_on; + account_name_type account_to_recover; + account_name_type recovery_account; + time_point_sec effective_on; change_recovery_account_request_id_type get_id()const { return id; } }; @@ -217,10 +219,10 @@ namespace steemit { namespace chain { ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_name >, - member< account_object, string, &account_object::name > >, + member< account_object, account_name_type, &account_object::name > >, ordered_unique< tag< by_proxy >, composite_key< account_object, - member< account_object, string, &account_object::proxy >, + member< account_object, account_name_type, &account_object::proxy >, member > /// composite key by proxy >, @@ -299,11 +301,11 @@ namespace steemit { namespace chain { member< object, object_id_type, &object::id > >, ordered_unique< tag< by_account >, composite_key< owner_authority_history_object, - member< owner_authority_history_object, string, &owner_authority_history_object::account >, + member< owner_authority_history_object, account_name_type, &owner_authority_history_object::account >, member< owner_authority_history_object, time_point_sec, &owner_authority_history_object::last_valid_time >, member< object, object_id_type, &object::id > >, - composite_key_compare< std::less< string >, std::less< time_point_sec >, std::less< object_id_type > > + composite_key_compare< std::less< account_name_type >, std::less< time_point_sec >, std::less< object_id_type > > > > > owner_authority_history_multi_index_type; @@ -317,10 +319,10 @@ namespace steemit { namespace chain { member< object, object_id_type, &object::id > >, ordered_unique< tag< by_account >, composite_key< account_recovery_request_object, - member< account_recovery_request_object, string, &account_recovery_request_object::account_to_recover >, + member< account_recovery_request_object, account_name_type, &account_recovery_request_object::account_to_recover >, member< object, object_id_type, &object::id > >, - composite_key_compare< std::less< string >, std::less< object_id_type > > + composite_key_compare< std::less< account_name_type >, std::less< object_id_type > > >, ordered_unique< tag< by_expiration >, composite_key< account_recovery_request_object, @@ -341,10 +343,10 @@ namespace steemit { namespace chain { member< object, object_id_type, &object::id > >, ordered_unique< tag< by_account >, composite_key< change_recovery_account_request_object, - member< change_recovery_account_request_object, string, &change_recovery_account_request_object::account_to_recover >, + member< change_recovery_account_request_object, account_name_type, &change_recovery_account_request_object::account_to_recover >, member< object, object_id_type, &object::id > >, - composite_key_compare< std::less< string >, std::less< object_id_type > > + composite_key_compare< std::less< account_name_type >, std::less< object_id_type > > >, ordered_unique< tag< by_effective_date >, composite_key< change_recovery_account_request_object, diff --git a/libraries/chain/include/steemit/chain/comment_object.hpp b/libraries/chain/include/steemit/chain/comment_object.hpp index 359d9409f7..9fd54349eb 100644 --- a/libraries/chain/include/steemit/chain/comment_object.hpp +++ b/libraries/chain/include/steemit/chain/comment_object.hpp @@ -76,9 +76,9 @@ namespace steemit { namespace chain { static const uint8_t type_id = impl_comment_object_type; string category; - string parent_author; + account_name_type parent_author; string parent_permlink; - string author; + account_name_type author; string permlink; string title = ""; @@ -222,117 +222,25 @@ namespace steemit { namespace chain { >, ordered_unique< tag< by_permlink >, /// used by consensus to find posts referenced in ops composite_key< comment_object, - member< comment_object, string, &comment_object::author >, + member< comment_object, account_name_type, &comment_object::author >, member< comment_object, string, &comment_object::permlink > >, - composite_key_compare< std::less< string >, std::less< string > > + composite_key_compare< std::less< account_name_type >, std::less< string > > >, ordered_unique< tag< by_root >, composite_key< comment_object, member< comment_object, comment_id_type, &comment_object::root_comment >, member< object, object_id_type, &object::id > > - > - -//#ifndef IS_LOW_MEM - , + >, ordered_unique< tag< by_parent >, /// used by consensus to find posts referenced in ops composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, + member< comment_object, account_name_type, &comment_object::parent_author >, member< comment_object, string, &comment_object::parent_permlink >, member< object, object_id_type, &object::id > >, - composite_key_compare< std::less< string >, std::less< string >, std::less > - >, - ordered_unique< tag, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, time_point_sec, &comment_object::active >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - /// PENDING PAYOUT relative to a parent - ordered_unique< tag< by_pending_payout >, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, - member< comment_object, share_type, &comment_object::net_rshares >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - /// TOTAL PENDING PAYOUT - this is the default TRENDING ORDER - ordered_unique< tag< by_total_pending_payout >, - composite_key< comment_object, - member< comment_object, comment_mode, &comment_object::mode >, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, fc::uint128_t, &comment_object::children_rshares2 >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::less, std::greater, std::less > - >, - /// used to sort all posts by the last time they were edited - ordered_unique< tag, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, time_point_sec, &comment_object::last_update >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - /// used to sort all posts by the last time they were edited - ordered_unique< tag, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, time_point_sec, &comment_object::created >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - ordered_unique< tag, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, int32_t, &comment_object::net_votes >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - ordered_unique< tag, - composite_key< comment_object, - member< comment_object, string, &comment_object::parent_author >, /// parent author of "" is root topic - member< comment_object, uint32_t, &comment_object::children >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less, std::greater, std::less > - >, - /// posts with the high dollar value received - ordered_unique< tag< by_payout >, - composite_key< comment_object, - member< comment_object, asset, &comment_object::total_payout_value >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::greater, std::less > - >, - /// used to find all top-level posts (blog posts) - ordered_unique< tag< by_blog >, - composite_key< comment_object, - member< comment_object, string, &comment_object::author >, - member< comment_object, string, &comment_object::parent_author >, - member< comment_object, time_point_sec, &comment_object::created >, - member< comment_object, string, &comment_object::permlink > - >, - composite_key_compare< std::less< string >, std::less< string >, std::greater, std::less > - >, - /// used to find all posts by an author - ordered_unique< tag< by_author_last_update >, - composite_key< comment_object, - member< comment_object, string, &comment_object::author >, - member< comment_object, time_point_sec, &comment_object::last_update >, - member< object, object_id_type, &object::id > - >, - composite_key_compare< std::less< string >, std::greater, std::less > + composite_key_compare< std::less< account_name_type >, std::less< string >, std::less > > -// #endif /// IS_LOW_MEM > > comment_multi_index_type; diff --git a/libraries/chain/include/steemit/chain/database.hpp b/libraries/chain/include/steemit/chain/database.hpp index 8b7fb37fb9..5188933e93 100644 --- a/libraries/chain/include/steemit/chain/database.hpp +++ b/libraries/chain/include/steemit/chain/database.hpp @@ -102,19 +102,19 @@ namespace steemit { namespace chain { chain_id_type get_chain_id()const; - const witness_object* find_witness( const string& name )const; + const witness_object* find_witness( const account_name_type& name )const; const category_object* find_category( const string& name )const; const category_object& get_category( const string& name )const; - const witness_object& get_witness( const string& name )const; - const account_object& get_account( const string& name )const; - const comment_object& get_comment( const string& author, const string& permlink )const; - const comment_object* find_comment( const string& author, const string& permlink )const; - const escrow_object& get_escrow( const string& name, uint32_t escrowid )const; + const witness_object& get_witness( const account_name_type& name )const; + const account_object& get_account( const account_name_type& name )const; + const comment_object& get_comment( const account_name_type& author, const string& permlink )const; + const comment_object* find_comment( const account_name_type& author, const string& permlink )const; + const escrow_object& get_escrow( const account_name_type& name, uint32_t escrowid )const; const time_point_sec calculate_discussion_payout_time( const comment_object& comment )const; - const limit_order_object& get_limit_order( const string& owner, uint32_t id )const; - const limit_order_object* find_limit_order( const string& owner, uint32_t id )const; - const savings_withdraw_object& get_savings_withdraw( const string& owner, uint32_t request_id )const; - const savings_withdraw_object* find_savings_withdraw( const string& owner, uint32_t request_id )const; + const limit_order_object& get_limit_order( const account_name_type& owner, uint32_t id )const; + const limit_order_object* find_limit_order( const account_name_type& owner, uint32_t id )const; + const savings_withdraw_object& get_savings_withdraw( const account_name_type& owner, uint32_t request_id )const; + const savings_withdraw_object* find_savings_withdraw( const account_name_type& owner, uint32_t request_id )const; /** * Deducts fee from the account and the share supply @@ -142,13 +142,13 @@ namespace steemit { namespace chain { signed_block generate_block( const fc::time_point_sec when, - const string& witness_owner, + const account_name_type& witness_owner, const fc::ecc::private_key& block_signing_private_key, uint32_t skip ); signed_block _generate_block( const fc::time_point_sec when, - const string& witness_owner, + const account_name_type& witness_owner, const fc::ecc::private_key& block_signing_private_key ); @@ -227,7 +227,7 @@ namespace steemit { namespace chain { * * Passing slot_num == 0 returns STEEMIT_NULL_WITNESS */ - string get_scheduled_witness(uint32_t slot_num)const; + account_name_type get_scheduled_witness(uint32_t slot_num)const; /** * Get the time at which the given slot occurs. diff --git a/libraries/chain/include/steemit/chain/global_property_object.hpp b/libraries/chain/include/steemit/chain/global_property_object.hpp index 438d2bee27..5ec69141da 100644 --- a/libraries/chain/include/steemit/chain/global_property_object.hpp +++ b/libraries/chain/include/steemit/chain/global_property_object.hpp @@ -27,7 +27,7 @@ namespace steemit { namespace chain { uint32_t head_block_number = 0; block_id_type head_block_id; time_point_sec time; - string current_witness; + account_name_type current_witness; /** diff --git a/libraries/chain/include/steemit/chain/history_object.hpp b/libraries/chain/include/steemit/chain/history_object.hpp index c3a61699c2..5b1d6c2e55 100644 --- a/libraries/chain/include/steemit/chain/history_object.hpp +++ b/libraries/chain/include/steemit/chain/history_object.hpp @@ -59,7 +59,7 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_account_history_object_type; - string account; + account_name_type account; uint32_t sequence = 0; operation_id_type op; }; @@ -71,10 +71,10 @@ namespace steemit { namespace chain { ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_account >, composite_key< account_history_object, - member< account_history_object, string, &account_history_object::account>, + member< account_history_object, account_name_type, &account_history_object::account>, member< account_history_object, uint32_t, &account_history_object::sequence> >, - composite_key_compare< std::less, std::greater > + composite_key_compare< std::less, std::greater > > > > account_history_multi_index_type; diff --git a/libraries/chain/include/steemit/chain/protocol/authority.hpp b/libraries/chain/include/steemit/chain/protocol/authority.hpp index 2aa57f55c1..968b18cfce 100644 --- a/libraries/chain/include/steemit/chain/protocol/authority.hpp +++ b/libraries/chain/include/steemit/chain/protocol/authority.hpp @@ -24,7 +24,7 @@ namespace steemit { namespace chain { { key_auths[k] = w; } - void add_authority( string k, weight_type w ) + void add_authority( const account_name_type& k, weight_type w ) { account_auths[k] = w; } @@ -66,9 +66,16 @@ namespace steemit { namespace chain { uint32_t num_auths()const { return account_auths.size() + key_auths.size(); } void clear() { account_auths.clear(); key_auths.clear(); } - uint32_t weight_threshold = 0; - flat_map account_auths; - flat_map key_auths; + + struct string_less { + bool operator()( const account_name_type& a, const account_name_type& b )const { + return string(a) < string(b); + } + }; + + uint32_t weight_threshold = 0; + flat_map account_auths; + flat_map key_auths; void validate()const; }; diff --git a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp index c8e7b77232..93c595d0b9 100644 --- a/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp +++ b/libraries/chain/include/steemit/chain/protocol/steem_operations.hpp @@ -6,12 +6,13 @@ #include namespace steemit { namespace chain { + typedef string aname_type; struct account_create_operation : public base_operation { asset fee; - string creator; - string new_account_name; + aname_type creator; + aname_type new_account_name; authority owner; authority active; authority posting; @@ -24,7 +25,7 @@ namespace steemit { namespace chain { struct account_update_operation : public base_operation { - string account; + aname_type account; optional< authority > owner; optional< authority > active; optional< authority > posting; @@ -45,10 +46,10 @@ namespace steemit { namespace chain { struct comment_operation : public base_operation { - string parent_author; + aname_type parent_author; string parent_permlink; - string author; + aname_type author; string permlink; string title; @@ -69,8 +70,8 @@ namespace steemit { namespace chain { */ struct comment_options_operation : public base_operation { - string author; - string permlink; + aname_type author; + string permlink; asset max_accepted_payout = asset( 1000000000, SBD_SYMBOL ); /// SBD value of the maximum payout this post will receive uint16_t percent_steem_dollars = STEEMIT_100_PERCENT; /// the percent of Steem Dollars to key, unkept amounts will be received as Steem Power @@ -84,8 +85,8 @@ namespace steemit { namespace chain { struct challenge_authority_operation : public base_operation { - string challenger; - string challenged; + aname_type challenger; + aname_type challenged; bool require_owner = false; void validate()const; @@ -95,7 +96,7 @@ namespace steemit { namespace chain { struct prove_authority_operation : public base_operation { - string challenged; + aname_type challenged; bool require_owner = false; void validate()const; @@ -106,7 +107,7 @@ namespace steemit { namespace chain { struct delete_comment_operation : public base_operation { - string author; + aname_type author; string permlink; void validate()const; @@ -115,8 +116,8 @@ namespace steemit { namespace chain { struct vote_operation : public base_operation { - string voter; - string author; + aname_type voter; + aname_type author; string permlink; int16_t weight = 0; @@ -128,7 +129,7 @@ namespace steemit { namespace chain { author_reward_operation(){} author_reward_operation( const string& a, const string& p, const asset& s, const asset& v ) :author(a),permlink(p),sbd_payout(s),vesting_payout(v){} - string author; + aname_type author; string permlink; asset sbd_payout; asset vesting_payout; @@ -140,9 +141,9 @@ namespace steemit { namespace chain { curation_reward_operation( const string& c, const asset& r, const string& a, const string& p ) :curator(c),reward(r),comment_author(a),comment_permlink(p){} - string curator; + aname_type curator; asset reward; - string comment_author; + aname_type comment_author; string comment_permlink; }; @@ -152,7 +153,7 @@ namespace steemit { namespace chain { comment_reward_operation( const string& a, const string& pl, const asset& p ) :author(a),permlink(pl),payout(p){} - string author; + aname_type author; string permlink; asset payout; }; @@ -162,7 +163,7 @@ namespace steemit { namespace chain { liquidity_reward_operation( string o = string(), asset p = asset() ) :owner(o),payout(p){} - string owner; + aname_type owner; asset payout; }; @@ -171,7 +172,7 @@ namespace steemit { namespace chain { interest_operation( const string& o = "", const asset& i = asset(0,SBD_SYMBOL) ) :owner(o),interest(i){} - string owner; + aname_type owner; asset interest; }; @@ -180,7 +181,7 @@ namespace steemit { namespace chain { fill_convert_request_operation(){} fill_convert_request_operation( const string& o, const uint32_t id, const asset& in, const asset& out ) :owner(o), requestid(id), amount_in(in), amount_out(out){} - string owner; + aname_type owner; uint32_t requestid = 0; asset amount_in; asset amount_out; @@ -191,8 +192,8 @@ namespace steemit { namespace chain { fill_vesting_withdraw_operation(){} fill_vesting_withdraw_operation( const string& f, const string& t, const asset& w, const asset& d ) :from_account(f), to_account(t), withdrawn(w), deposited(d){} - string from_account; - string to_account; + aname_type from_account; + aname_type to_account; asset withdrawn; asset deposited; }; @@ -201,7 +202,7 @@ namespace steemit { namespace chain { { shutdown_witness_operation(){} shutdown_witness_operation( const string& o ):owner(o) {} - string owner; + aname_type owner; }; /** @@ -211,9 +212,9 @@ namespace steemit { namespace chain { */ struct transfer_operation : public base_operation { - string from; + aname_type from; /// Account to transfer asset to - string to; + aname_type to; /// The amount of asset to transfer from @ref from to @ref to asset amount; @@ -246,9 +247,9 @@ namespace steemit { namespace chain { */ struct escrow_transfer_operation : public base_operation { - string from; - string to; - string agent; + aname_type from; + aname_type to; + aname_type agent; uint32_t escrow_id = 0; asset sbd_amount = asset( 0, SBD_SYMBOL ); @@ -271,10 +272,10 @@ namespace steemit { namespace chain { */ struct escrow_approve_operation : public base_operation { - string from; - string to; - string agent; - string who; // Either to or agent + aname_type from; + aname_type to; + aname_type agent; + aname_type who; // Either to or agent uint32_t escrow_id = 0; bool approve = true; @@ -289,10 +290,10 @@ namespace steemit { namespace chain { */ struct escrow_dispute_operation : public base_operation { - string from; - string to; - string agent; - string who; + aname_type from; + aname_type to; + aname_type agent; + aname_type who; uint32_t escrow_id = 0; void validate()const; @@ -311,11 +312,11 @@ namespace steemit { namespace chain { */ struct escrow_release_operation : public base_operation { - string from; - string to; ///< the original 'to' - string agent; - string who; ///< the account that is attempting to release the funds, determines valid 'receiver' - string receiver; ///< the account that should receive funds (might be from, might be to) + aname_type from; + aname_type to; ///< the original 'to' + aname_type agent; + aname_type who; ///< the account that is attempting to release the funds, determines valid 'receiver' + aname_type receiver; ///< the account that should receive funds (might be from, might be to) uint32_t escrow_id = 0; asset sbd_amount = asset( 0, SBD_SYMBOL ); ///< the amount of sbd to release asset steem_amount = asset( 0, STEEM_SYMBOL ); ///< the amount of steem to release @@ -333,8 +334,8 @@ namespace steemit { namespace chain { */ struct transfer_to_vesting_operation : public base_operation { - string from; - string to; ///< if null, then same as from + aname_type from; + aname_type to; ///< if null, then same as from asset amount; ///< must be STEEM void validate()const; @@ -354,7 +355,7 @@ namespace steemit { namespace chain { */ struct withdraw_vesting_operation : public base_operation { - string account; + aname_type account; asset vesting_shares; void validate()const; @@ -370,8 +371,8 @@ namespace steemit { namespace chain { */ struct set_withdraw_vesting_route_operation : public base_operation { - string from_account; - string to_account; + aname_type from_account; + aname_type to_account; uint16_t percent = 0; bool auto_vest = false; @@ -426,7 +427,7 @@ namespace steemit { namespace chain { */ struct witness_update_operation : public base_operation { - string owner; + aname_type owner; string url; public_key_type block_signing_key; chain_properties props; @@ -443,8 +444,8 @@ namespace steemit { namespace chain { */ struct account_witness_vote_operation : public base_operation { - string account; - string witness; + aname_type account; + aname_type witness; bool approve = true; void validate() const; @@ -453,8 +454,8 @@ namespace steemit { namespace chain { struct account_witness_proxy_operation : public base_operation { - string account; - string proxy; + aname_type account; + aname_type proxy; void validate()const; void get_required_active_authorities( flat_set& a )const{ a.insert(account); } @@ -468,7 +469,7 @@ namespace steemit { namespace chain { */ struct custom_operation : public base_operation { - flat_set required_auths; + flat_set required_auths; uint16_t id = 0; vector data; @@ -481,8 +482,8 @@ namespace steemit { namespace chain { **/ struct custom_json_operation : public base_operation { - flat_set required_auths; - flat_set required_posting_auths; + flat_set required_auths; + flat_set required_posting_auths; string id; ///< must be less than 32 characters long string json; ///< must be proper utf8 / JSON string. @@ -493,9 +494,9 @@ namespace steemit { namespace chain { struct custom_binary_operation : public base_operation { - flat_set required_owner_auths; - flat_set required_active_auths; - flat_set required_posting_auths; + flat_set required_owner_auths; + flat_set required_active_auths; + flat_set required_posting_auths; vector required_auths; string id; ///< must be less than 32 characters long @@ -514,7 +515,7 @@ namespace steemit { namespace chain { */ struct feed_publish_operation : public base_operation { - string publisher; + aname_type publisher; price exchange_rate; void validate()const; @@ -527,7 +528,7 @@ namespace steemit { namespace chain { */ struct convert_operation : public base_operation { - string owner; + aname_type owner; uint32_t requestid = 0; asset amount; @@ -540,7 +541,7 @@ namespace steemit { namespace chain { */ struct limit_order_create_operation : public base_operation { - string owner; + aname_type owner; uint32_t orderid = 0; /// an ID assigned by owner, must be unique asset amount_to_sell; asset min_to_receive; @@ -566,7 +567,7 @@ namespace steemit { namespace chain { */ struct limit_order_create2_operation : public base_operation { - string owner; + aname_type owner; uint32_t orderid = 0; /// an ID assigned by owner, must be unique asset amount_to_sell; bool fill_or_kill = false; @@ -592,10 +593,10 @@ namespace steemit { namespace chain { fill_order_operation( const string& c_o, uint32_t c_id, const asset& c_p, const string& o_o, uint32_t o_id, const asset& o_p ) :current_owner(c_o),current_orderid(c_id),current_pays(c_p),open_owner(o_o),open_orderid(o_id),open_pays(o_p){} - string current_owner; + aname_type current_owner; uint32_t current_orderid = 0; asset current_pays; - string open_owner; + aname_type open_owner; uint32_t open_orderid = 0; asset open_pays; }; @@ -605,7 +606,7 @@ namespace steemit { namespace chain { */ struct limit_order_cancel_operation : public base_operation { - string owner; + aname_type owner; uint32_t orderid = 0; void validate()const; @@ -626,7 +627,7 @@ namespace steemit { namespace chain { struct pow_operation : public base_operation { - string worker_account; + aname_type worker_account; block_id_type block_id; uint64_t nonce = 0; pow work; @@ -635,7 +636,7 @@ namespace steemit { namespace chain { void validate()const; fc::sha256 work_input()const; - const string& get_worker_account()const { return worker_account; } + const aname_type& get_worker_account()const { return worker_account; } /** there is no need to verify authority, the proof of work is sufficient */ void get_required_active_authorities( flat_set& a )const{ } @@ -643,7 +644,7 @@ namespace steemit { namespace chain { struct pow2_input { - string worker_account; + aname_type worker_account; block_id_type prev_block; uint64_t nonce = 0; }; @@ -653,7 +654,7 @@ namespace steemit { namespace chain { pow2_input input; uint32_t pow_summary = 0; - void create( const block_id_type& prev_block, const string& account_name, uint64_t nonce ); + void create( const block_id_type& prev_block, const aname_type& account_name, uint64_t nonce ); void validate()const; }; @@ -699,7 +700,7 @@ namespace steemit { namespace chain { */ struct report_over_production_operation : public base_operation { - string reporter; + aname_type reporter; signed_block_header first_block; signed_block_header second_block; @@ -735,9 +736,9 @@ namespace steemit { namespace chain { */ struct request_account_recovery_operation : public base_operation { - string recovery_account; ///< The recovery account is listed as the recovery account on the account to recover. + aname_type recovery_account; ///< The recovery account is listed as the recovery account on the account to recover. - string account_to_recover; ///< The account to recover. This is likely due to a compromised owner authority. + aname_type account_to_recover; ///< The account to recover. This is likely due to a compromised owner authority. authority new_owner_authority; ///< The new owner authority the account to recover wishes to have. This is secret ///< known by the account to recover and will be confirmed in a recover_account_operation @@ -788,7 +789,7 @@ namespace steemit { namespace chain { */ struct recover_account_operation : public base_operation { - string account_to_recover; ///< The account to be recovered + aname_type account_to_recover; ///< The account to be recovered authority new_owner_authority; ///< The new owner authority as specified in the request account recovery operation. @@ -810,8 +811,8 @@ namespace steemit { namespace chain { * new_owner_authority after 60 days of inactivity. */ struct reset_account_operation : public base_operation { - string reset_account; - string account_to_reset; + aname_type reset_account; + aname_type account_to_reset; authority new_owner_authority; @@ -827,8 +828,8 @@ namespace steemit { namespace chain { * to execute the 'reset_account_operation' after 60 days. */ struct set_reset_account_operation : public base_operation { - string account; - string reset_account; + aname_type account; + aname_type reset_account; void validate()const; void get_required_active_authorities( flat_set& a )const { @@ -857,9 +858,9 @@ namespace steemit { namespace chain { */ struct change_recovery_account_operation : public base_operation { - string account_to_recover; ///< The account that would be recovered in case of compromise + aname_type account_to_recover; ///< The account that would be recovered in case of compromise - string new_recovery_account; ///< The account that creates the recover request + aname_type new_recovery_account; ///< The account that creates the recover request extensions_type extensions; ///< Extensions. Not currently used. @@ -869,8 +870,8 @@ namespace steemit { namespace chain { }; struct transfer_to_savings_operation : public base_operation { - string from; - string to; + aname_type from; + aname_type to; asset amount; string memo; @@ -879,9 +880,9 @@ namespace steemit { namespace chain { }; struct transfer_from_savings_operation : public base_operation { - string from; + aname_type from; uint32_t request_id = 0; - string to; + aname_type to; asset amount; string memo; @@ -890,7 +891,7 @@ namespace steemit { namespace chain { }; struct cancel_transfer_from_savings_operation : public base_operation { - string from; + aname_type from; uint32_t request_id = 0; void get_required_active_authorities( flat_set& a )const{ a.insert( from ); } @@ -899,7 +900,7 @@ namespace steemit { namespace chain { struct decline_voting_rights_operation : public base_operation { - string account; + aname_type account; bool decline = true; void get_required_owner_authorities( flat_set< string >& a )const{ a.insert( account ); } diff --git a/libraries/chain/include/steemit/chain/protocol/types.hpp b/libraries/chain/include/steemit/chain/protocol/types.hpp index ec42b40797..ac81ca0409 100644 --- a/libraries/chain/include/steemit/chain/protocol/types.hpp +++ b/libraries/chain/include/steemit/chain/protocol/types.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include @@ -71,8 +72,10 @@ namespace steemit { namespace chain { using fc::ecc::commitment_type; struct void_t{}; - typedef fc::ecc::private_key private_key_type; - typedef fc::sha256 chain_id_type; + typedef fc::ecc::private_key private_key_type; + typedef fc::sha256 chain_id_type; + typedef fc::fixed_string<> account_name_type; +// typedef std::string account_name_type; enum reserved_spaces diff --git a/libraries/chain/include/steemit/chain/steem_objects.hpp b/libraries/chain/include/steemit/chain/steem_objects.hpp index 3c6ed9b5b9..f9a2ad64e0 100755 --- a/libraries/chain/include/steemit/chain/steem_objects.hpp +++ b/libraries/chain/include/steemit/chain/steem_objects.hpp @@ -23,10 +23,10 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_convert_request_object_type; - string owner; - uint32_t requestid = 0; ///< id set by owner, the owner,requestid pair must be unique - asset amount; - time_point_sec conversion_date; ///< at this time the feed_history_median_price * amount + account_name_type owner; + uint32_t requestid = 0; ///< id set by owner, the owner,requestid pair must be unique + asset amount; + time_point_sec conversion_date; ///< at this time the feed_history_median_price * amount }; class escrow_object : public abstract_object { @@ -34,18 +34,18 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_escrow_object_type; - uint32_t escrow_id = 0; - string from; - string to; - string agent; - time_point_sec ratification_deadline; - time_point_sec escrow_expiration; - asset sbd_balance; - asset steem_balance; - asset pending_fee; - bool to_approved = false; - bool agent_approved = false; - bool disputed = false; + uint32_t escrow_id = 0; + account_name_type from; + account_name_type to; + account_name_type agent; + time_point_sec ratification_deadline; + time_point_sec escrow_expiration; + asset sbd_balance; + asset steem_balance; + asset pending_fee; + bool to_approved = false; + bool agent_approved = false; + bool disputed = false; }; class savings_withdraw_object : public abstract_object { @@ -53,12 +53,12 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_savings_withdraw_object_type; - string from; - string to; - string memo; - uint32_t request_id = 0; - asset amount; - time_point_sec complete; + account_name_type from; + account_name_type to; + string memo; + uint32_t request_id = 0; + asset amount; + time_point_sec complete; }; @@ -125,12 +125,12 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_limit_order_object_type; - time_point_sec created; - time_point_sec expiration; - string seller; - uint32_t orderid = 0; - share_type for_sale; ///< asset id is sell_price.base.symbol - price sell_price; + time_point_sec created; + time_point_sec expiration; + account_name_type seller; + uint32_t orderid = 0; + share_type for_sale; ///< asset id is sell_price.base.symbol + price sell_price; pair get_market()const { @@ -185,7 +185,7 @@ namespace steemit { namespace chain { >, ordered_unique< tag, composite_key< limit_order_object, - member< limit_order_object, string, &limit_order_object::seller>, + member< limit_order_object, account_name_type, &limit_order_object::seller>, member< limit_order_object, uint32_t, &limit_order_object::orderid> > > @@ -206,7 +206,7 @@ namespace steemit { namespace chain { >, ordered_unique< tag< by_owner >, composite_key< convert_request_object, - member< convert_request_object, string, &convert_request_object::owner>, + member< convert_request_object, account_name_type, &convert_request_object::owner>, member< convert_request_object, uint32_t, &convert_request_object::requestid > > > @@ -264,19 +264,19 @@ namespace steemit { namespace chain { ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_from_id >, composite_key< escrow_object, - member< escrow_object, string, &escrow_object::from >, + member< escrow_object, account_name_type, &escrow_object::from >, member< escrow_object, uint32_t, &escrow_object::escrow_id > > >, ordered_unique< tag< by_to >, composite_key< escrow_object, - member< escrow_object, string, &escrow_object::to >, + member< escrow_object, account_name_type, &escrow_object::to >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_agent >, composite_key< escrow_object, - member< escrow_object, string, &escrow_object::agent >, + member< escrow_object, account_name_type, &escrow_object::agent >, member< object, object_id_type, &object::id > > >, @@ -308,13 +308,13 @@ namespace steemit { namespace chain { ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_from_rid >, composite_key< savings_withdraw_object, - member< savings_withdraw_object, string, &savings_withdraw_object::from >, + member< savings_withdraw_object, account_name_type, &savings_withdraw_object::from >, member< savings_withdraw_object, uint32_t, &savings_withdraw_object::request_id > > >, ordered_unique< tag< by_to_complete >, composite_key< savings_withdraw_object, - member< savings_withdraw_object, string, &savings_withdraw_object::to >, + member< savings_withdraw_object, account_name_type, &savings_withdraw_object::to >, member< savings_withdraw_object, time_point_sec, &savings_withdraw_object::complete >, member< object, object_id_type, &object::id > > @@ -322,7 +322,7 @@ namespace steemit { namespace chain { ordered_unique< tag< by_complete_from_rid >, composite_key< savings_withdraw_object, member< savings_withdraw_object, time_point_sec, &savings_withdraw_object::complete >, - member< savings_withdraw_object, string, &savings_withdraw_object::from >, + member< savings_withdraw_object, account_name_type, &savings_withdraw_object::from >, member< savings_withdraw_object, uint32_t, &savings_withdraw_object::request_id > > > diff --git a/libraries/chain/include/steemit/chain/witness_objects.hpp b/libraries/chain/include/steemit/chain/witness_objects.hpp index 8abb17c7d2..993112a84d 100644 --- a/libraries/chain/include/steemit/chain/witness_objects.hpp +++ b/libraries/chain/include/steemit/chain/witness_objects.hpp @@ -25,9 +25,9 @@ namespace steemit { namespace chain { static const uint8_t type_id = impl_witness_object_type; /** the account that has authority over this witness */ - string owner; - time_point_sec created; - string url; + account_name_type owner; + time_point_sec created; + string url; uint32_t total_missed = 0; uint64_t last_aslot = 0; uint64_t last_confirmed_block_num = 0; @@ -115,11 +115,24 @@ namespace steemit { namespace chain { static const uint8_t space_id = implementation_ids; static const uint8_t type_id = impl_witness_schedule_object_type; - fc::uint128 current_virtual_time; - uint32_t next_shuffle_block_num = 1; - vector< string > current_shuffled_witnesses; - chain_properties median_props; - version majority_version; + fc::uint128 current_virtual_time; + uint32_t next_shuffle_block_num = 1; + vector< account_name_type > current_shuffled_witnesses; + chain_properties median_props; + version majority_version; + }; + + struct string_less { + bool operator()( const std::string& a, const std::string& b )const { + return a < b; + } + bool operator()( const fc::fixed_string<>& a, const fc::fixed_string<>& b )const { + const char* ap = (const char*)&a; + const char* ab = (const char*)&b; + int count = sizeof(a); + while( *ap == *ab && count ) { ++ap; ++ab; --count; } + return *ap < *ab; + } }; struct by_vote_name; @@ -135,14 +148,14 @@ namespace steemit { namespace chain { indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, member >, - ordered_unique< tag, member >, + ordered_unique< tag, member >, ordered_non_unique< tag, member >, ordered_unique< tag, composite_key< witness_object, member, - member + member >, - composite_key_compare< std::greater< share_type >, std::less< string > > + composite_key_compare< std::greater< share_type >, string_less > //std::less< account_name_type > > >, ordered_unique< tag, composite_key< witness_object, diff --git a/libraries/chain/protocol/authority.cpp b/libraries/chain/protocol/authority.cpp index 86612f4f38..1e3a40000a 100644 --- a/libraries/chain/protocol/authority.cpp +++ b/libraries/chain/protocol/authority.cpp @@ -3,7 +3,7 @@ namespace steemit { namespace chain { void add_authority_accounts( - flat_set& result, + flat_set& result, const authority& a ) { diff --git a/libraries/chain/protocol/steem_operations.cpp b/libraries/chain/protocol/steem_operations.cpp index dd3225bf04..737a95aff3 100644 --- a/libraries/chain/protocol/steem_operations.cpp +++ b/libraries/chain/protocol/steem_operations.cpp @@ -44,8 +44,10 @@ namespace steemit { namespace chain { validate_account_name( account ); if( owner ) owner->validate(); - if (active) + if( active ) active->validate(); + if( posting ) + posting->validate(); if ( json_metadata.size() > 0 ) { @@ -122,7 +124,7 @@ namespace steemit { namespace chain { { validate_account_name( from ); FC_ASSERT( is_asset_type( amount, STEEM_SYMBOL ), "Amount must be STEEM" ); - if ( !to.empty() ) validate_account_name( to ); + if ( to != aname_type() ) validate_account_name( to ); FC_ASSERT( amount > asset( 0, STEEM_SYMBOL ), "Must transfer a nonzero amount" ); } @@ -212,7 +214,7 @@ namespace steemit { namespace chain { work = fc::sha256::hash(recover); } - void pow2::create( const block_id_type& prev, const string& account_name, uint64_t n ) + void pow2::create( const block_id_type& prev, const aname_type& account_name, uint64_t n ) { input.worker_account = account_name; input.prev_block = prev; diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index 5d81c349c6..0e67fd62a5 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -419,7 +419,7 @@ void comment_evaluator::do_apply( const comment_operation& o ) if( !parent ) { - FC_ASSERT( com.parent_author == "", "The parent of a comment cannot change" ); + FC_ASSERT( com.parent_author == account_name_type(), "The parent of a comment cannot change" ); FC_ASSERT( com.parent_permlink == o.parent_permlink, "The permlink of a comment cannot change" ); } else @@ -1316,6 +1316,7 @@ void pow_apply( database& db, Operation o ) { } const auto& accounts_by_name = db.get_index_type().indices().get(); + auto itr = accounts_by_name.find(o.get_worker_account()); if(itr == accounts_by_name.end()) { db.create< account_object >( [&]( account_object& acc ) diff --git a/libraries/db/include/graphene/db/object_database.hpp b/libraries/db/include/graphene/db/object_database.hpp index faed1f1d7f..594e5c42e0 100644 --- a/libraries/db/include/graphene/db/object_database.hpp +++ b/libraries/db/include/graphene/db/object_database.hpp @@ -1,37 +1,20 @@ -/* - * Copyright (c) 2015 Cryptonomex, Inc., and contributors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ #pragma once #include #include #include +#include +#include +#include + #include #include namespace graphene { namespace db { + namespace bip = boost::interprocess; + /** * @class object_database * @brief maintains a set of indexed objects that can be modified with multi-level rollback support @@ -166,6 +149,10 @@ namespace graphene { namespace db { void save_undo_add( const object& obj ); void save_undo_remove( const object& obj ); + + unique_ptr _managed_mem; + unique_ptr _managed_mem_mutex; + fc::path _data_dir; vector< vector< unique_ptr > > _index; }; diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 9f10486960..e9349967aa 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -29,6 +29,7 @@ namespace graphene { namespace db { using std::unordered_map; + using std::unordered_set; using fc::flat_set; class object_database; @@ -36,7 +37,7 @@ namespace graphene { namespace db { { unordered_map > old_values; unordered_map old_index_next_ids; - std::unordered_set new_ids; + unordered_set new_ids; unordered_map > removed; }; diff --git a/libraries/fc b/libraries/fc index 19d41b8606..f59a516256 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 19d41b860676959e2014dd34700209df49eb62c4 +Subproject commit f59a51625690d40b9bf481c1f8b158434e9ca88e diff --git a/libraries/plugins/follow/follow_plugin.cpp b/libraries/plugins/follow/follow_plugin.cpp index 54d48972b6..a87fb783ab 100644 --- a/libraries/plugins/follow/follow_plugin.cpp +++ b/libraries/plugins/follow/follow_plugin.cpp @@ -41,15 +41,6 @@ class follow_plugin_impl follow_plugin_impl::follow_plugin_impl( follow_plugin& _plugin ) : _self( _plugin ) { - // Each plugin needs its own evaluator registry. - _evaluator_registry = std::make_shared< json_evaluator_registry< steemit::follow::follow_plugin_operation > >( database() ); - - // Add each operation evaluator to the registry - _evaluator_registry->register_evaluator( &_self ); - _evaluator_registry->register_evaluator( &_self ); - - // Add the registry to the database so the database can delegate custom ops to the plugin - database().set_custom_json_evaluator( _self.plugin_name(), _evaluator_registry ); } struct pre_operation_visitor @@ -349,6 +340,18 @@ void follow_plugin::plugin_initialize( const boost::program_options::variables_m try { ilog("Intializing follow plugin" ); + wdump(("register follow evaluator" )); + // Each plugin needs its own evaluator registry. + my->_evaluator_registry = std::make_shared< json_evaluator_registry< steemit::follow::follow_plugin_operation > >( database() ); + + // Add each operation evaluator to the registry + my->_evaluator_registry->register_evaluator( this ); + my->_evaluator_registry->register_evaluator( this ); + + // Add the registry to the database so the database can delegate custom ops to the plugin + database().set_custom_json_evaluator( plugin_name(), my->_evaluator_registry ); + + database().pre_apply_operation.connect( [&]( const operation_object& o ){ my->pre_operation( o ); } ); database().post_apply_operation.connect( [&]( const operation_object& o ){ my->on_operation( o ); } ); database().add_index< primary_index< follow_index > >(); diff --git a/libraries/plugins/raw_block/raw_block_api.cpp b/libraries/plugins/raw_block/raw_block_api.cpp index 5534d54812..eee3b4140b 100644 --- a/libraries/plugins/raw_block/raw_block_api.cpp +++ b/libraries/plugins/raw_block/raw_block_api.cpp @@ -45,8 +45,8 @@ get_raw_block_result raw_block_api::get_raw_block( get_raw_block_args args ) return result; } std::stringstream ss; - fc::raw::pack( ss, *block ); - result.raw_block = fc::base64_encode( ss.str() ); + auto rest = fc::raw::pack( *block ); + result.raw_block = fc::base64_encode( std::string( &rest[0], &rest[0] + rest.size()) ); //ss.str() ); result.block_id = block->id(); result.previous = block->previous; result.timestamp = block->timestamp; @@ -57,9 +57,9 @@ void raw_block_api::push_raw_block( std::string block_b64 ) std::shared_ptr< steemit::chain::database > db = my->app.chain_database(); std::string block_bin = fc::base64_decode( block_b64 ); - std::stringstream ss( block_bin ); + fc::datastream ds( block_bin.c_str(), block_bin.size() ); chain::signed_block block; - fc::raw::unpack( ss, block ); + fc::raw::unpack( ds, block ); db->push_block( block ); diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index cb4f3efc5b..46eb28c445 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -11,6 +11,12 @@ install( TARGETS ARCHIVE DESTINATION lib ) + +add_executable( test_shared_mem test_shared_mem.cpp ) + +target_link_libraries( test_shared_mem + PRIVATE steemit_app steemit_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) + add_executable( sign_digest sign_digest.cpp ) target_link_libraries( sign_digest diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index 715798375e..2e7cc1b17f 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -39,6 +39,32 @@ using namespace steemit::chain; BOOST_FIXTURE_TEST_SUITE( serialization_tests, clean_database_fixture ) + /* +BOOST_AUTO_TEST_CASE( account_name_type_test ) +{ + + auto test = []( const string& data ) { + fixed_string<> a(data); + std::string b(data); + + auto ap = fc::raw::pack( empty ); + auto bp = fc::raw::pack( emptystr ); + FC_ASSERT( ap.size() == bp.size() ); + FC_ASSERT( std::equal( ap.begin(), ap.end(), bp.begin() ) ); + + auto sfa = fc::raw::unpack( ap ); + auto afs = fc::raw::unpack>( bp ); + } + test( std::string() ); + test( "helloworld" ); + test( "1234567890123456" ); + + auto packed_long_string = fc::raw::pack( std::string( "12345678901234567890" ) ); + auto unpacked = fc::raw::unpack>( packed_long_string ); + idump( (unpacked) ); +} +*/ + BOOST_AUTO_TEST_CASE( serialization_raw_test ) { try {