diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 054fb9bb..7be8599f 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -153,11 +153,7 @@ void account_object::options_type::validate() const "May not specify fewer witnesses or committee members than the number voted for."); } - - - - -set account_member_index::get_members( const account_object& a )const +set account_member_index::get_members(const account_object& a)const { set result; for( auto auth : a.owner.auths ) @@ -167,17 +163,17 @@ set account_member_index::get_members( const account_object& a return result; } -void account_member_index::object_inserted( const object& obj ) +void account_member_index::object_inserted(const object& obj) { assert( dynamic_cast(&obj) ); // for debug only const account_object& a = static_cast(obj); - set members = get_members(a); + set members = get_members(a); for( auto item : members ) - account_to_memberships[item].insert( obj.id ); + account_to_memberships[item].insert(obj.id); } -void account_member_index::object_removed( const object& obj ) +void account_member_index::object_removed(const object& obj) { assert( dynamic_cast(&obj) ); // for debug only const account_object& a = static_cast(obj); @@ -187,7 +183,7 @@ void account_member_index::object_removed( const object& obj ) account_to_memberships[item].erase( obj.id ); } -void account_member_index::about_to_modify( const object& before ) +void account_member_index::about_to_modify(const object& before) { before_members.clear(); assert( dynamic_cast(&before) ); // for debug only @@ -195,29 +191,28 @@ void account_member_index::about_to_modify( const object& before ) before_members = get_members(a); } -void account_member_index::object_modified( const object& after ) +void account_member_index::object_modified(const object& after) { assert( dynamic_cast(&after) ); // for debug only const account_object& a = static_cast(after); - set after_members = get_members(a); - + set after_members = get_members(a); + vector removed; removed.reserve(before_members.size()); - std::set_difference( before_members.begin(), before_members.end(), - after_members.begin(), after_members.end(), - std::inserter( removed, removed.end() ) ); + std::set_difference(before_members.begin(), before_members.end(), + after_members.begin(), after_members.end(), + std::inserter(removed, removed.end())); for( auto itr = removed.begin(); itr != removed.end(); ++itr ) - account_to_memberships[*itr].erase( after.id ); - - vector added; added.reserve(after_members.size()); - auto add_end = std::set_difference( after_members.begin(), after_members.end(), - before_members.begin(), before_members.end(), - std::inserter( added, added.end()) ); - - for( auto itr = added.begin(); itr != added.end(); ++itr ) - account_to_memberships[*itr].insert( after.id ); -} + account_to_memberships[*itr].erase(after.id); + vector added; added.reserve(after_members.size()); + std::set_difference(after_members.begin(), after_members.end(), + before_members.begin(), before_members.end(), + std::inserter(added, added.end())); + + for( auto itr = added.begin(); itr != added.end(); ++itr ) + account_to_memberships[*itr].insert(after.id); +} void account_referrer_index::object_inserted( const object& obj ) { @@ -232,8 +227,4 @@ void account_referrer_index::object_modified( const object& after ) { } - - - - } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/operations.hpp b/libraries/chain/include/graphene/chain/operations.hpp index 61d22fef..7c556422 100644 --- a/libraries/chain/include/graphene/chain/operations.hpp +++ b/libraries/chain/include/graphene/chain/operations.hpp @@ -348,7 +348,7 @@ namespace graphene { namespace chain { void validate()const; share_type calculate_fee(const fee_schedule_type& k)const; - void get_balance_delta( balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust( fee_payer(), -fee ); } + void get_balance_delta(balance_accumulator& acc, const operation_result& result = asset())const { acc.adjust(fee_payer(), -fee); } }; /** diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp index db8c9334..ef3b12ad 100644 --- a/libraries/chain/include/graphene/chain/types.hpp +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -335,11 +335,6 @@ namespace graphene { namespace chain { } }; - fee_schedule_type() - { - memset((char*)this, 0, sizeof(*this)); - } - /// The number of bytes to charge a data fee for const static int BYTES_PER_DATA_FEE = 1024; @@ -348,57 +343,54 @@ namespace graphene { namespace chain { return data_size(ts...) / BYTES_PER_DATA_FEE * data_fee; } - uint32_t key_create_fee; ///< the cost to register a public key with the blockchain - uint32_t account_create_fee; ///< the cost to register the cheapest non-free account - uint32_t account_update_fee; ///< the cost to update an existing account - uint32_t account_transfer_fee; ///< the cost to transfer an account to a new owner - uint32_t account_len8up_fee; - uint32_t account_len7_fee; - uint32_t account_len6_fee; - uint32_t account_len5_fee; - uint32_t account_len4_fee; - uint32_t account_len3_fee; - uint32_t account_len2_fee; - uint32_t asset_len3_fee; - uint32_t asset_len4_fee; - uint32_t asset_len5_fee; - uint32_t asset_len6_fee; - uint32_t asset_len7up_fee; - uint32_t account_whitelist_fee; ///< the fee to whitelist an account - uint32_t delegate_create_fee; ///< fixed fee for registering as a delegate; used to discourage frivolous delegates - uint32_t witness_withdraw_pay_fee; ///< fee for withdrawing witness pay - uint32_t transfer_fee; ///< fee for transferring some asset - uint32_t limit_order_create_fee; ///< fee for placing a limit order in the markets - uint32_t limit_order_cancel_fee; ///< fee for canceling a limit order - uint32_t call_order_fee; ///< fee for placing a call order in the markets - uint32_t publish_feed_fee; ///< fee for publishing a price feed - uint32_t asset_create_fee; ///< the cost to register the cheapest asset - uint32_t asset_update_fee; ///< the cost to modify a registered asset - uint32_t asset_issue_fee; ///< the cost to modify a registered asset - uint32_t asset_burn_fee; ///< the cost to burn an asset - uint32_t asset_fund_fee_pool_fee; ///< the cost to add funds to an asset's fee pool - uint32_t asset_settle_fee; ///< the cost to trigger a forced settlement of a market-issued asset - uint32_t market_fee; ///< a percentage charged on market orders - uint32_t transaction_fee; ///< a base price for every transaction - uint32_t data_fee; ///< a price per BYTES_PER_DATA_FEE bytes of user data - uint32_t signature_fee; ///< a surcharge on transactions with more than 2 signatures. - uint32_t global_parameters_update_fee; ///< the cost to update the global parameters - uint32_t membership_annual_fee; ///< the annual cost of a membership subscription - uint32_t membership_lifetime_fee; ///< the cost to upgrade to a lifetime member - uint32_t withdraw_permission_create_fee; ///< the cost to create a withdraw permission - uint32_t withdraw_permission_update_fee; ///< the cost to update a withdraw permission - uint32_t withdraw_permission_claim_fee; ///< the cost to withdraw from a withdraw permission - uint32_t withdraw_permission_delete_fee; ///< the cost to delete a withdraw permission - uint32_t vesting_balance_create_fee; - uint32_t vesting_balance_withdraw_fee; - uint32_t global_settle_fee; - uint32_t worker_create_fee; ///< the cost to create a new worker - uint32_t worker_delete_fee; ///< the cost to delete a worker - uint32_t assert_op_fee; ///< fee per assert operation - uint32_t proposal_create_fee; ///< fee for creating a proposed transaction - uint32_t proposal_update_fee; ///< fee for adding or removing approval of a proposed transaction - uint32_t proposal_delete_fee; ///< fee for deleting a proposed transaction - uint32_t custom_operation_fee; ///< fee for a custom operation + uint32_t key_create_fee = 270300; ///< the cost to register a public key with the blockchain + uint32_t account_create_fee = 666666; ///< the cost to register the cheapest non-free account + uint32_t account_update_fee = 150000; ///< the cost to update an existing account + uint32_t account_transfer_fee = 300000; ///< the cost to transfer an account to a new owner + uint32_t account_whitelist_fee = 300000; ///< the fee to whitelist an account + uint32_t account_len8up_fee = 1500000; + uint32_t account_len7_fee = 7000000; + uint32_t account_len6_fee = 14000000; + uint32_t account_len5_fee = 70000000; + uint32_t account_len4_fee = 280000000; + uint32_t account_len3_fee = 680000000; + uint32_t account_len2_fee = 1000000000; + uint32_t asset_create_fee = 680000000; ///< the cost to register the cheapest asset + uint32_t asset_update_fee = 150000; ///< the cost to modify a registered asset + uint32_t asset_issue_fee = 700000; ///< the cost to print a UIA and send it to an account + uint32_t asset_burn_fee = 1500000; ///< the cost to burn an asset + uint32_t asset_fund_fee_pool_fee = 150000; ///< the cost to add funds to an asset's fee pool + uint32_t asset_settle_fee = 7000000; ///< the cost to trigger a forced settlement of a market-issued asset + uint32_t asset_global_settle_fee = 140000000; ///< the cost to trigger a global forced settlement of a market asset + uint32_t asset_len7up_fee = 140000000; + uint32_t asset_len6_fee = 675000000; + uint32_t asset_len5_fee = 1350000000; + uint32_t asset_len4_fee = 2700000000; + uint64_t asset_len3_fee = 7000000000; + uint32_t delegate_create_fee = 680000000; ///< fee for registering as a delegate; used to discourage frivolous delegates + uint32_t witness_create_fee = 680000000; /// < fee for registering as a witness + uint32_t witness_withdraw_pay_fee = 1500000; ///< fee for withdrawing witness pay + uint32_t transfer_fee = 2700000; ///< fee for transferring some asset + uint32_t limit_order_create_fee = 666666; ///< fee for placing a limit order in the markets + uint32_t limit_order_cancel_fee = 150000; ///< fee for canceling a limit order + uint32_t call_order_fee = 800000; ///< fee for placing a call order in the markets + uint32_t publish_feed_fee = 666666; ///< fee for publishing a price feed + uint32_t data_fee = 13500000; ///< a price per BYTES_PER_DATA_FEE bytes of user data + uint32_t global_parameters_update_fee = 1350000; ///< the cost to update the global parameters + uint32_t membership_annual_fee = 270000000; ///< the annual cost of a membership subscription + uint32_t membership_lifetime_fee = 1350000000; ///< the cost to upgrade to a lifetime member + uint32_t withdraw_permission_create_fee = 2700000; ///< the cost to create a withdraw permission + uint32_t withdraw_permission_update_fee = 150000; ///< the cost to update a withdraw permission + uint32_t withdraw_permission_claim_fee = 700000; ///< the cost to withdraw from a withdraw permission + uint32_t withdraw_permission_delete_fee = 150000; ///< the cost to delete a withdraw permission + uint32_t vesting_balance_create_fee = 7000000; + uint32_t vesting_balance_withdraw_fee = 2700000; + uint32_t worker_create_fee = 680000000; ///< the cost to create a new worker + uint32_t assert_op_fee = 150000; ///< fee per assert operation + uint32_t proposal_create_fee = 7000000; ///< fee for creating a proposed transaction + uint32_t proposal_update_fee = 1500000; ///< fee for adding or removing approval of a proposed transaction + uint32_t proposal_delete_fee = 150000; ///< fee for deleting a proposed transaction + uint32_t custom_operation_fee = 300000; ///< fee for a custom operation protected: size_t data_size()const { @@ -565,6 +557,7 @@ FC_REFLECT( graphene::chain::fee_schedule_type, (asset_len7up_fee) (account_whitelist_fee) (delegate_create_fee) + (witness_create_fee) (witness_withdraw_pay_fee) (transfer_fee) (limit_order_create_fee) @@ -577,10 +570,7 @@ FC_REFLECT( graphene::chain::fee_schedule_type, (asset_burn_fee) (asset_fund_fee_pool_fee) (asset_settle_fee) - (market_fee) - (transaction_fee) (data_fee) - (signature_fee) (global_parameters_update_fee) (membership_annual_fee) (membership_lifetime_fee) @@ -590,9 +580,8 @@ FC_REFLECT( graphene::chain::fee_schedule_type, (withdraw_permission_delete_fee) (vesting_balance_create_fee) (vesting_balance_withdraw_fee) - (global_settle_fee) + (asset_global_settle_fee) (worker_create_fee) - (worker_delete_fee) (assert_op_fee) (proposal_create_fee) (proposal_update_fee) diff --git a/libraries/chain/operations.cpp b/libraries/chain/operations.cpp index 1fa19be1..65edbad3 100644 --- a/libraries/chain/operations.cpp +++ b/libraries/chain/operations.cpp @@ -575,7 +575,7 @@ void witness_create_operation::validate() const share_type witness_create_operation::calculate_fee(const fee_schedule_type& k) const { - return k.delegate_create_fee + k.total_data_fee(url); + return k.witness_create_fee + k.total_data_fee(url); } void withdraw_permission_update_operation::get_required_auth(flat_set& active_auth_set, flat_set&)const @@ -668,7 +668,7 @@ void asset_global_settle_operation::validate()const share_type asset_global_settle_operation::calculate_fee(const fee_schedule_type& k)const { - return k.global_settle_fee; + return k.asset_global_settle_fee; } void asset_settle_operation::get_required_auth(flat_set& active_auth_set, flat_set&) const diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 02685c58..45803265 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -65,6 +65,7 @@ database_fixture::database_fixture() genesis_state.initial_committee.push_back({name}); genesis_state.initial_witnesses.push_back({name, delegate_priv_key.get_public_key(), secret}); } + fc::reflector::visit(fee_schedule_type::fee_set_visitor{genesis_state.initial_parameters.current_fees, 0}); db.init_genesis(genesis_state); ahplugin->plugin_startup(); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index cab95933..441266fa 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -49,6 +49,7 @@ genesis_state_type make_genesis() { genesis_state.initial_committee.push_back({name}); genesis_state.initial_witnesses.push_back({name, delegate_priv_key.get_public_key(), secret}); } + fc::reflector::visit(fee_schedule_type::fee_set_visitor{genesis_state.initial_parameters.current_fees, 0}); return genesis_state; } @@ -74,25 +75,20 @@ BOOST_AUTO_TEST_CASE( block_database_test ) bdb.store( b.id(), b ); auto fetch = bdb.fetch_by_number( b.block_num() ); - //idump((fetch)); FC_ASSERT( fetch.valid() ); FC_ASSERT( fetch->witness == b.witness ); fetch = bdb.fetch_by_number( i+1 ); - //idump((fetch)); FC_ASSERT( fetch.valid() ); FC_ASSERT( fetch->witness == b.witness ); fetch = bdb.fetch_optional( b.id() ); - //idump((fetch)); FC_ASSERT( fetch.valid() ); FC_ASSERT( fetch->witness == b.witness ); } - //ilog("-----------" ); for( uint32_t i = 1; i < 5; ++i ) { auto blk = bdb.fetch_by_number( i ); FC_ASSERT( blk.valid() ); - //idump((blk)(i)); FC_ASSERT( blk->witness == witness_id_type(blk->block_num()) ); } @@ -110,7 +106,6 @@ BOOST_AUTO_TEST_CASE( block_database_test ) { auto blk = bdb.fetch_by_number( i+1 ); FC_ASSERT( blk.valid() ); - //idump((blk)(i)); FC_ASSERT( blk->witness == witness_id_type(blk->block_num()) ); } @@ -141,7 +136,6 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) witness_id_type prev_witness = b.witness; now += db.block_interval(); witness_id_type cur_witness = db.get_scheduled_witness( 1 ).first; - // TODO: Uncomment this when witness scheduling implemented BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block( now, cur_witness, delegate_priv_key, database::skip_nothing ); BOOST_CHECK( b.witness == cur_witness ); @@ -149,7 +143,6 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) db.close(); } { - //wlog( "------------------------------------------------" ); database db; db.open(data_dir.path() ); BOOST_CHECK_EQUAL( db.head_block_num(), 200 ); @@ -159,7 +152,6 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) witness_id_type prev_witness = b.witness; now += db.block_interval(); witness_id_type cur_witness = db.get_scheduled_witness( 1 ).first; - // TODO: Uncomment this when witness scheduling implemented BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block( now, cur_witness, delegate_priv_key, database::skip_nothing ); } @@ -189,15 +181,12 @@ BOOST_AUTO_TEST_CASE( undo_block ) BOOST_CHECK( db.head_block_num() == 5 ); db.pop_block(); now -= db.block_interval(); - //wdump( (witness_schedule_id_type()(db)) ); BOOST_CHECK( db.head_block_num() == 4 ); db.pop_block(); now -= db.block_interval(); - //wdump( (witness_schedule_id_type()(db)) ); BOOST_CHECK( db.head_block_num() == 3 ); db.pop_block(); now -= db.block_interval(); - //wdump( (witness_schedule_id_type()(db)) ); BOOST_CHECK( db.head_block_num() == 2 ); for( uint32_t i = 0; i < 5; ++i ) { diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 50a0573e..fd418fa6 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -228,35 +228,35 @@ BOOST_AUTO_TEST_CASE( black_swan ) transfer(genesis_account, buyer_id, asset(init_balance)); transfer(genesis_account, borrower_id, asset(init_balance)); transfer(genesis_account, borrower2_id, asset(init_balance)); - update_feed_producers( bitusd, {feedproducer.id} ); + update_feed_producers(bitusd, {feedproducer.id}); price_feed current_feed; - current_feed.settlement_price = bitusd.amount( 100 ) / core.amount(100); + current_feed.settlement_price = bitusd.amount(100) / core.amount(100); // starting out with price 1:1 - publish_feed( bitusd, feedproducer, current_feed ); + publish_feed(bitusd, feedproducer, current_feed); // start out with 2:1 collateral - borrow( borrower, bitusd.amount(1000), asset(2000) ); - borrow( borrower2, bitusd.amount(1000), asset(4000) ); + borrow(borrower, bitusd.amount(1000), asset(2000)); + borrow(borrower2, bitusd.amount(1000), asset(4000)); - BOOST_REQUIRE_EQUAL( get_balance( borrower, bitusd ), 1000 ); - BOOST_REQUIRE_EQUAL( get_balance( borrower2, bitusd ), 1000 ); - BOOST_REQUIRE_EQUAL( get_balance( borrower , core ), init_balance - 2000 ); - BOOST_REQUIRE_EQUAL( get_balance( borrower2, core ), init_balance - 4000 ); + BOOST_REQUIRE_EQUAL( get_balance(borrower, bitusd), 1000 ); + BOOST_REQUIRE_EQUAL( get_balance(borrower2, bitusd), 1000 ); + BOOST_REQUIRE_EQUAL( get_balance(borrower , core), init_balance - 2000 ); + BOOST_REQUIRE_EQUAL( get_balance(borrower2, core), init_balance - 4000 ); current_feed.settlement_price = bitusd.amount( 100 ) / core.amount(200); publish_feed( bitusd, feedproducer, current_feed ); /// this sell order is designed to trigger a black swan - auto order = create_sell_order( borrower2, bitusd.amount(1000), core.amount(3000) ); + create_sell_order(borrower2, bitusd.amount(1000), core.amount(3000)); FC_ASSERT( bitusd.bitasset_data(db).has_settlement() ); - force_settle( borrower, bitusd.amount(100) ); + force_settle(borrower, bitusd.amount(100)); BOOST_TEST_MESSAGE( "Verify that we cannot borrow after black swan" ); - BOOST_REQUIRE_THROW( borrow( borrower, bitusd.amount(1000), asset(2000) ), fc::exception ); + BOOST_REQUIRE_THROW( borrow(borrower, bitusd.amount(1000), asset(2000)), fc::exception ); } catch( const fc::exception& e) { edump((e.to_detail_string())); throw; diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 2e80e9b1..a087fa76 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -805,34 +805,28 @@ BOOST_AUTO_TEST_CASE( assert_op_test ) try { // create some objects auto nathan_private_key = generate_private_key("nathan"); - auto dan_private_key = generate_private_key("dan"); public_key_type nathan_public_key = nathan_private_key.get_public_key(); - public_key_type dan_public_key = dan_private_key.get_public_key(); key_id_type nathan_key_id = register_key(nathan_public_key).id; - key_id_type dan_key_id = register_key(dan_public_key).id; account_id_type nathan_id = create_account("nathan", nathan_key_id).id; assert_operation op; - decltype( key_object::key_data ) lit_key = nathan_public_key; + decltype(key_object::key_data) lit_key = nathan_public_key; // nathan checks that his public key is equal to the given value. op.fee_paying_account = nathan_id; - op.predicates = vector< vector< char > >(); + op.predicates = vector>(); op.predicates.push_back( fc::raw::pack( - predicate( pred::account_name_eq_lit{ nathan_id, "nathan" } ) - ) ); + predicate(pred::account_name_eq_lit{ nathan_id, "nathan" }) + )); trx.operations.push_back(op); - trx.sign( nathan_key_id, nathan_private_key ); + trx.sign(nathan_key_id, nathan_private_key); PUSH_TX( db, trx ); // nathan checks that his public key is not equal to the given value (fail) - op.predicates.back() = - fc::raw::pack( - predicate( pred::account_name_eq_lit{ nathan_id, "dan" } ) - ); + op.predicates.back() = fc::raw::pack(predicate(pred::account_name_eq_lit{ nathan_id, "dan" })); trx.operations.back() = op; - trx.sign( nathan_key_id, nathan_private_key ); + trx.sign(nathan_key_id, nathan_private_key); BOOST_CHECK_THROW( PUSH_TX( db, trx ), fc::exception ); } FC_LOG_AND_RETHROW() }