From 8efa2e673856f61fac2c283b3b5766ceb1749af7 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 1 Jul 2015 18:17:49 -0400 Subject: [PATCH] Progress auditing TODOs #108, upgrade boost 1.58 --- CMakeLists.txt | 2 +- libraries/chain/asset_evaluator.cpp | 12 +++++++----- libraries/chain/block.cpp | 5 ++++- libraries/chain/db_balance.cpp | 6 ------ libraries/chain/db_debug.cpp | 5 ++++- libraries/chain/db_init.cpp | 3 ++- libraries/chain/include/graphene/chain/block.hpp | 2 +- .../chain/include/graphene/chain/database.hpp | 2 -- .../chain/include/graphene/chain/transaction.hpp | 7 ------- .../graphene/chain/vesting_balance_object.hpp | 14 ++++++++++++++ libraries/chain/limit_order_evaluator.cpp | 4 ++-- libraries/chain/transfer_evaluator.cpp | 8 ++++---- 12 files changed, 39 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b07ef54c..be68c664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ IF( WIN32 ) set(BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all libraries ENDIF(WIN32) -FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) +FIND_PACKAGE(Boost 1.58 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) # For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors IF(NOT "${Boost_VERSION}" MATCHES "1.53(.*)") SET(BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES}) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index a80201a4..b9be88fa 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -449,8 +449,7 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_ if( base.issuer == account_id_type() ) { //It's a delegate-fed asset. Verify that publisher is an active delegate or witness. - // TODO: replace account_id_type with global variable for delegates account id - FC_ASSERT(d.get(account_id_type()).active.auths.count(o.publisher) || + FC_ASSERT(d.get(GRAPHENE_COMMITTEE_ACCOUNT).active.auths.count(o.publisher) || d.get_global_properties().witness_accounts.count(o.publisher)); } else { FC_ASSERT(bitasset.feeds.count(o.publisher)); @@ -464,14 +463,17 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope database& d = db(); const asset_object& base = o.asset_id(d); + const asset_bitasset_data_object& bad = base.bitasset_data(d); + + auto old_feed = bad.current_feed; // Store medians for this asset - d.modify(base.bitasset_data(d), [&o,&d](asset_bitasset_data_object& a) { + d.modify(bad , [&o,&d](asset_bitasset_data_object& a) { a.feeds[o.publisher] = make_pair(d.head_block_time(), o.feed); a.update_median_feeds(d.head_block_time()); }); - /// TODO: optimization: only do this if the median feed actually changed, otherwise there is no point - db().check_call_orders(base); + if( !(old_feed == bad.current_feed) ) + db().check_call_orders(base); return void_result(); } FC_CAPTURE_AND_RETHROW((o)) } diff --git a/libraries/chain/block.cpp b/libraries/chain/block.cpp index ad731b84..f26fa356 100644 --- a/libraries/chain/block.cpp +++ b/libraries/chain/block.cpp @@ -17,6 +17,7 @@ */ #include #include +#include namespace graphene { namespace chain { @@ -25,10 +26,12 @@ namespace graphene { namespace chain { return digest_type::hash(*this); } + uint32_t block_header::num_from_id(const block_id_type& id) { return boost::endian::endian_reverse(id._hash[0]); } + block_id_type signed_block_header::id()const { auto tmp = fc::sha224::hash( *this ); - tmp._hash[0] = htonl(block_num()); // store the block num in the ID, 160 bits is plenty for the hash + tmp._hash[0] = boost::endian::endian_reverse(block_num()); // store the block num in the ID, 160 bits is plenty for the hash static_assert( sizeof(tmp._hash[0]) == 4, "should be 4 bytes" ); block_id_type result; memcpy(result._hash, tmp._hash, std::min(sizeof(result), sizeof(tmp))); diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index bb4d3bab..1b7e03cd 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -38,12 +38,6 @@ asset database::get_balance(const account_object& owner, const asset_object& ass return get_balance(owner.get_id(), asset_obj.get_id()); } -// TODO: this method should be removed -asset database::get_balance( const account_object* owner, const asset_object* asset_obj )const -{ - return get_balance(*owner, *asset_obj); -} - void database::adjust_balance(account_id_type account, asset delta ) { try { if( delta.amount == 0 ) diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index 34b37265..89afa465 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -82,7 +82,10 @@ void database::debug_dump() { edump( (total_balances[asset_id_type()].value)(core_asset_data.current_supply.value )); } - // TODO: Add vesting_balance_object to this method + + const auto& vbidx = db.get_index_type>(); + for( const auto& s : vbidx ) + idump(("vesting_balance")(s)); } } } diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index bc27d34a..d65e1364 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -128,7 +128,8 @@ void database::initialize_indexes() prop_index->add_secondary_index(); add_index< primary_index >(); - add_index< primary_index > >(); + //add_index< primary_index >(); + add_index< primary_index> >(); add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/chain/include/graphene/chain/block.hpp b/libraries/chain/include/graphene/chain/block.hpp index f8988eab..5f3e1357 100644 --- a/libraries/chain/include/graphene/chain/block.hpp +++ b/libraries/chain/include/graphene/chain/block.hpp @@ -36,7 +36,7 @@ namespace graphene { namespace chain { checksum_type transaction_merkle_root; vector extensions; - static uint32_t num_from_id(const block_id_type& id) { return htonl(id._hash[0]); } + static uint32_t num_from_id(const block_id_type& id); }; struct signed_block_header : public block_header diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 6f0cb194..8729fef2 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -334,8 +334,6 @@ namespace graphene { namespace chain { asset get_balance(account_id_type owner, asset_id_type asset_id)const; /// This is an overloaded method. asset get_balance(const account_object& owner, const asset_object& asset_obj)const; - /// This is an overloaded method. - asset get_balance(const account_object* owner, const asset_object* asset_obj)const; /** * @brief Adjust a particular account's balance in a given asset by a delta diff --git a/libraries/chain/include/graphene/chain/transaction.hpp b/libraries/chain/include/graphene/chain/transaction.hpp index 93c106e6..e4e3e6df 100644 --- a/libraries/chain/include/graphene/chain/transaction.hpp +++ b/libraries/chain/include/graphene/chain/transaction.hpp @@ -21,13 +21,6 @@ #include -// this is for htonl() and ntohl() functions -// TODO: write and use FC wrappers for these functions -#ifndef WIN32 - #include -#else - #include -#endif namespace graphene { namespace chain { diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index db20091f..f47c6ead 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -24,6 +24,7 @@ #include #include +#include namespace graphene { namespace chain { using namespace graphene::db; @@ -156,6 +157,19 @@ namespace graphene { namespace chain { void withdraw(const fc::time_point_sec& now, const asset& amount); bool is_withdraw_allowed(const fc::time_point_sec& now, const asset& amount)const; }; + /** + * @ingroup object_index + */ + typedef multi_index_container< + vesting_balance_object, + indexed_by< + hashed_unique< tag, member< object, object_id_type, &object::id > > + > + > vesting_balance_multi_index_type; + /** + * @ingroup object_index + */ + typedef generic_index vesting_balance_index; } } // graphene::chain diff --git a/libraries/chain/limit_order_evaluator.cpp b/libraries/chain/limit_order_evaluator.cpp index 49f7713e..88cc864b 100644 --- a/libraries/chain/limit_order_evaluator.cpp +++ b/libraries/chain/limit_order_evaluator.cpp @@ -39,8 +39,8 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o if( _sell_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset ) ); if( _receive_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset ) ); - FC_ASSERT( d.get_balance( _seller, _sell_asset ) >= op.amount_to_sell, "insufficient balance", - ("balance",d.get_balance(_seller,_sell_asset))("amount_to_sell",op.amount_to_sell) ); + FC_ASSERT( d.get_balance( *_seller, *_sell_asset ) >= op.amount_to_sell, "insufficient balance", + ("balance",d.get_balance(*_seller,*_sell_asset))("amount_to_sell",op.amount_to_sell) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index a3bec25e..d2ef09fb 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -40,8 +40,8 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) if( asset_type.is_transfer_restricted() ) FC_ASSERT( from_account.id == asset_type.issuer || to_account.id == asset_type.issuer ); - FC_ASSERT( d.get_balance( &from_account, &asset_type ).amount >= op.amount.amount, - "", ("total_transfer",op.amount)("balance",d.get_balance(&from_account, &asset_type).amount) ); + FC_ASSERT( d.get_balance( from_account, asset_type ).amount >= op.amount.amount, + "", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -76,8 +76,8 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op if( fee_asset_type.options.flags & white_list ) FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); - FC_ASSERT( d.get_balance( &from_account, &asset_type ).amount >= op.amount.amount, - "", ("total_transfer",op.amount)("balance",d.get_balance(&from_account, &asset_type).amount) ); + FC_ASSERT( d.get_balance( from_account, asset_type ).amount >= op.amount.amount, + "", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) }