From 2a07fba3c2f444daa21c294645b91fd48edfacc2 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Thu, 8 Oct 2015 16:20:33 -0400 Subject: [PATCH 1/3] Win32 compile fixes (#warning) --- libraries/chain/asset_evaluator.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 0c76f467..0e5d3bec 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -73,7 +73,11 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o database& d = db(); -#warning HARDFORK remove this check after HARDFORK_359_TIME and rename is_valid_symbol_old -> is_valid_symbol +#ifdef _MSC_VER +# pragma message ("WARNING:HARDFORK remove this check after HARDFORK_359_TIME and rename is_valid_symbol_old -> is_valid_symbol") +#else +# warning HARDFORK remove this check after HARDFORK_359_TIME and rename is_valid_symbol_old -> is_valid_symbol +#endif if( d.head_block_time() <= HARDFORK_359_TIME ) { FC_ASSERT( is_valid_symbol_old( op.symbol ) ); @@ -507,7 +511,11 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_ const asset_bitasset_data_object& bitasset = base.bitasset_data(d); FC_ASSERT( !bitasset.has_settlement(), "No further feeds may be published after a settlement event" ); -#warning Remove this check when starting a new network +#ifdef _MSC_VER +# pragma message ("WARNING: Remove this check when starting a new network") +#else +# warning Remove this check when starting a new network +#endif if( d.head_block_time() <= HARDFORK_357_TIME ) { FC_ASSERT(o.feed.settlement_price.quote.asset_id == bitasset.options.short_backing_asset); @@ -564,7 +572,11 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_ wdump( (e) ); } -#warning Remove this check when starting a new network +#ifdef _MSC_VER +# pragma message ("WARNING: Remove this check when starting a new network") +#else +# warning Remove this check when starting a new network +#endif if( d.head_block_num() > 59300 ) { FC_ASSERT( @@ -612,7 +624,11 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_operation& o) { try { -#warning Remove this check when preparing for new network release +#ifdef _MSC_VER +# pragma message ("WARNING: Remove this check when preparing for new network release") +#else +# warning Remove this check when preparing for new network release +#endif if( !o.feed.is_for( o.asset_id ) ) { wlog( "Ignoring bad feed" ); From 7fe0e64a5e38df88c5dea32ae35f371e5c425010 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Fri, 9 Oct 2015 11:42:56 -0400 Subject: [PATCH 2/3] Fix two places where objects were being used after they were deleted --- libraries/chain/db_block.cpp | 3 ++- libraries/chain/db_market.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index 8029bea5..e8dd2483 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -458,6 +458,7 @@ void database::apply_block( const signed_block& next_block, uint32_t skip ) void database::_apply_block( const signed_block& next_block ) { try { + uint32_t next_block_num = next_block.block_num(); uint32_t skip = get_node_properties().skip_flags; _applied_ops.clear(); @@ -468,7 +469,7 @@ void database::_apply_block( const signed_block& next_block ) const auto& dynamic_global_props = get(dynamic_global_property_id_type()); bool maint_needed = (dynamic_global_props.next_maintenance_time <= next_block.timestamp); - _current_block_num = next_block.block_num(); + _current_block_num = next_block_num; _current_trx_in_block = 0; for( const auto& trx : next_block.transactions ) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index d9ed6c57..b86959d2 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -89,7 +89,6 @@ void database::globally_settle_asset( const asset_object& mia, const price& sett void database::cancel_order(const force_settlement_object& order, bool create_virtual_op) { adjust_balance(order.owner, order.balance); - remove(order); if( create_virtual_op ) { @@ -99,6 +98,7 @@ void database::cancel_order(const force_settlement_object& order, bool create_vi vop.amount = order.balance; push_applied_operation( vop ); } + remove(order); } void database::cancel_order( const limit_order_object& order, bool create_virtual_op ) @@ -361,7 +361,6 @@ bool database::fill_order(const force_settlement_object& settle, const asset& pa }); filled = false; } else { - remove(settle); filled = true; } adjust_balance(settle.owner, receives - issuer_fees); @@ -369,6 +368,9 @@ bool database::fill_order(const force_settlement_object& settle, const asset& pa assert( pays.asset_id != receives.asset_id ); push_applied_operation( fill_order_operation{ settle.id, settle.owner, pays, receives, issuer_fees } ); + if (filled) + remove(settle); + return filled; } FC_CAPTURE_AND_RETHROW( (settle)(pays)(receives) ) } From f0f96d5a8f0591acb9a59706b5ff04fa93b96d7d Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 9 Oct 2015 11:07:10 -0400 Subject: [PATCH 3/3] Allow witness-fed and committee-fed BitAsset feeds to be specified in flags. This is only technically a hardfork, in order to actually desync the chain the witness account / committee account would need to pass a proposal to do something in their capacity as the owner of an asset_object. It should be fairly safe to say that this will not occur on testnet until witnesses have upgraded. --- libraries/chain/asset_evaluator.cpp | 12 ++++++++---- libraries/chain/db_init.cpp | 9 +++++++-- .../include/graphene/chain/protocol/types.hpp | 19 ++++++++++++++++--- libraries/chain/protocol/asset_ops.cpp | 2 ++ tests/common/database_fixture.cpp | 4 ++++ tests/tests/operation_tests2.cpp | 1 + tests/tests/uia_tests.cpp | 4 ++-- 7 files changed, 40 insertions(+), 11 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 0e5d3bec..971581dd 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -388,8 +388,8 @@ void_result asset_update_feed_producers_evaluator::do_evaluate(const asset_updat const asset_object& a = o.asset_to_update(d); FC_ASSERT(a.is_market_issued(), "Cannot update feed producers on a non-BitAsset."); - FC_ASSERT(a.issuer != GRAPHENE_COMMITTEE_ACCOUNT, "Cannot set feed producers on a committee-issued asset."); - FC_ASSERT(a.issuer != GRAPHENE_WITNESS_ACCOUNT, "Cannot set feed producers on a witness-issued asset."); + FC_ASSERT(!(a.options.flags & committee_fed_asset), "Cannot set feed producers on a committee-fed asset."); + FC_ASSERT(!(a.options.flags & witness_fed_asset), "Cannot set feed producers on a witness-fed asset."); const asset_bitasset_data_object& b = a.bitasset_data(d); bitasset_to_update = &b; @@ -609,9 +609,13 @@ void_result asset_publish_feeds_evaluator::do_evaluate(const asset_publish_feed_ FC_ASSERT( o.feed.is_for( o.asset_id ) ); } //Verify that the publisher is authoritative to publish a feed - if( (base.issuer == GRAPHENE_WITNESS_ACCOUNT) || (base.issuer == GRAPHENE_COMMITTEE_ACCOUNT) ) + if( base.options.flags & witness_fed_asset ) { - FC_ASSERT( d.get(base.issuer).active.account_auths.count(o.publisher) ); + FC_ASSERT( d.get(GRAPHENE_WITNESS_ACCOUNT).active.account_auths.count(o.publisher) ); + } + else if( base.options.flags & committee_fed_asset ) + { + FC_ASSERT( d.get(GRAPHENE_COMMITTEE_ACCOUNT).active.account_auths.count(o.publisher) ); } else { diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 60d8acac..6575f918 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -497,9 +497,14 @@ void database::init_genesis(const genesis_state_type& genesis_state) a.symbol = asset.symbol; a.options.description = asset.description; a.precision = asset.precision; - a.issuer = get_account_id(asset.issuer_name); + string issuer_name = asset.issuer_name; +#warning Remove this check doing real network, change BitAsset owners to be committee-account in genesis. + if( issuer_name == "witness-account" ) + issuer_name = "committee-account"; + a.issuer = get_account_id(issuer_name); a.options.max_supply = asset.max_supply; - + a.options.flags = witness_fed_asset; + a.options.issuer_permissions = charge_market_fee | global_settle | witness_fed_asset | committee_fed_asset; a.dynamic_asset_data_id = dynamic_data_id; a.bitasset_data_id = bitasset_data_id; }); diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index e06f7600..98142fa7 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -86,9 +86,12 @@ namespace graphene { namespace chain { transfer_restricted = 0x08, /**< require the issuer to be one party to every transfer */ disable_force_settle = 0x10, /**< disable force settling */ global_settle = 0x20, /**< allow the bitasset issuer to force a global settling -- this may be set in permissions, but not flags */ - disable_confidential = 0x40 /**< allow the asset to be used with confidential transactions */ + disable_confidential = 0x40, /**< allow the asset to be used with confidential transactions */ + witness_fed_asset = 0x80, /**< allow the asset to be fed by witnesses */ + committee_fed_asset = 0x100 /**< allow the asset to be fed by the committee */ }; - const static uint32_t ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_force_settle|global_settle|disable_confidential; + const static uint32_t ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_force_settle|global_settle|disable_confidential + |witness_fed_asset|committee_fed_asset; const static uint32_t UIA_ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential; enum reserved_spaces @@ -314,4 +317,14 @@ FC_REFLECT_TYPENAME( graphene::chain::account_transaction_history_id_type ) FC_REFLECT_TYPENAME( graphene::chain::budget_record_id_type ) FC_REFLECT( graphene::chain::void_t, ) -FC_REFLECT_ENUM( graphene::chain::asset_issuer_permission_flags, (charge_market_fee)(white_list)(transfer_restricted)(override_authority)(disable_force_settle)(global_settle)(disable_confidential) ) +FC_REFLECT_ENUM( graphene::chain::asset_issuer_permission_flags, + (charge_market_fee) + (white_list) + (transfer_restricted) + (override_authority) + (disable_force_settle) + (global_settle) + (disable_confidential) + (witness_fed_asset) + (committee_fed_asset) + ) diff --git a/libraries/chain/protocol/asset_ops.cpp b/libraries/chain/protocol/asset_ops.cpp index 8bd1eaa0..d80fea27 100644 --- a/libraries/chain/protocol/asset_ops.cpp +++ b/libraries/chain/protocol/asset_ops.cpp @@ -171,6 +171,8 @@ void asset_options::validate()const FC_ASSERT( !(issuer_permissions & ~ASSET_ISSUER_PERMISSION_MASK) ); // The global_settle flag may never be set (this is a permission only) FC_ASSERT( !(flags & global_settle) ); + // the witness_fed and committee_fed flags cannot be set simultaneously + FC_ASSERT( (flags & (witness_fed_asset | committee_fed_asset)) != (witness_fed_asset | committee_fed_asset) ); core_exchange_rate.validate(); FC_ASSERT( core_exchange_rate.base.asset_id.instance.value == 0 || core_exchange_rate.quote.asset_id.instance.value == 0 ); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index ad408fcb..bf64a00b 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -424,6 +424,8 @@ const asset_object& database_fixture::create_bitasset( creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; creator.precision = 2; creator.common_options.market_fee_percent = market_fee_percent; + if( issuer == GRAPHENE_WITNESS_ACCOUNT ) + flags |= witness_fed_asset; creator.common_options.issuer_permissions = flags; creator.common_options.flags = flags & ~global_settle; creator.common_options.core_exchange_rate = price({asset(1,1),asset(1)}); @@ -451,6 +453,8 @@ const asset_object& database_fixture::create_prediction_market( creator.common_options.market_fee_percent = market_fee_percent; creator.common_options.issuer_permissions = flags | global_settle; creator.common_options.flags = flags & ~global_settle; + if( issuer == GRAPHENE_WITNESS_ACCOUNT ) + creator.common_options.flags |= witness_fed_asset; creator.common_options.core_exchange_rate = price({asset(1,1),asset(1)}); creator.bitasset_opts = bitasset_options(); creator.is_prediction_market = true; diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index aebe492f..559ea82c 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -319,6 +319,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) op.issuer = obj.issuer; op.new_issuer = nathan_id; op.new_options = obj.options; + op.new_options.flags &= ~witness_fed_asset; trx.operations.push_back(op); PUSH_TX( db, trx, ~0 ); generate_block(); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 435810ea..2869fa38 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -44,8 +44,8 @@ BOOST_AUTO_TEST_CASE( create_advanced_uia ) creator.common_options.max_supply = 100000000; creator.precision = 2; creator.common_options.market_fee_percent = GRAPHENE_MAX_MARKET_FEE_PERCENT/100; /*1%*/ - creator.common_options.issuer_permissions = ASSET_ISSUER_PERMISSION_MASK & ~(disable_force_settle|global_settle); - creator.common_options.flags = ASSET_ISSUER_PERMISSION_MASK & ~(disable_force_settle|global_settle|transfer_restricted); + creator.common_options.issuer_permissions = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential; + creator.common_options.flags = charge_market_fee|white_list|override_authority|disable_confidential; creator.common_options.core_exchange_rate = price({asset(2),asset(1,1)}); creator.common_options.whitelist_authorities = creator.common_options.blacklist_authorities = {account_id_type()}; trx.operations.push_back(std::move(creator));