From 9d3652e9eccde397d3f001bf5352a7c2dcf7950a Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 28 Oct 2015 13:03:31 -0400 Subject: [PATCH 01/32] Fix tests to obey new feed publishing requirement !core_exchange_rate.is_null() --- tests/common/database_fixture.cpp | 2 ++ tests/tests/operation_tests.cpp | 12 ++++++------ tests/tests/operation_tests2.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 1fb51ac385..e671aba406 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -733,6 +733,8 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje op.publisher = by.id; op.asset_id = mia.id; op.feed = f; + if( op.feed.core_exchange_rate.is_null() ) + op.feed.core_exchange_rate = op.feed.settlement_price; trx.operations.emplace_back( std::move(op) ); for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 9c1edef5db..001450af32 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -636,11 +636,11 @@ BOOST_AUTO_TEST_CASE( update_mia ) pop.asset_id = bit_usd.get_id(); pop.publisher = get_account("init0").get_id(); price_feed feed; - feed.settlement_price = price(bit_usd.amount(5), bit_usd.amount(5)); + feed.settlement_price = feed.core_exchange_rate = price(bit_usd.amount(5), bit_usd.amount(5)); REQUIRE_THROW_WITH_VALUE(pop, feed, feed); - feed.settlement_price = ~price(bit_usd.amount(5), asset(5)); + feed.settlement_price = feed.core_exchange_rate = ~price(bit_usd.amount(5), asset(5)); REQUIRE_THROW_WITH_VALUE(pop, feed, feed); - feed.settlement_price = price(bit_usd.amount(5), asset(5)); + feed.settlement_price = feed.core_exchange_rate = price(bit_usd.amount(5), asset(5)); pop.feed = feed; REQUIRE_THROW_WITH_VALUE(pop, feed.maintenance_collateral_ratio, 0); trx.operations.back() = pop; @@ -1144,7 +1144,7 @@ BOOST_AUTO_TEST_CASE( witness_feeds ) asset_publish_feed_operation op; op.publisher = active_witnesses[0]; op.asset_id = bit_usd.get_id(); - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); // Accept defaults for required collateral trx.operations.emplace_back(op); PUSH_TX( db, trx, ~0 ); @@ -1154,7 +1154,7 @@ BOOST_AUTO_TEST_CASE( witness_feeds ) BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = active_witnesses[1]; - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); @@ -1162,7 +1162,7 @@ BOOST_AUTO_TEST_CASE( witness_feeds ) BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = active_witnesses[2]; - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); // But this witness is an idiot. op.feed.maintenance_collateral_ratio = 1001; trx.operations.back() = op; diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 5e123e9e00..ee05ffd927 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -348,7 +348,8 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) asset_publish_feed_operation op; op.publisher = vikram_id; op.asset_id = bit_usd_id; - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(30)); + // We'll expire margins after a month // Accept defaults for required collateral trx.operations.emplace_back(op); @@ -359,7 +360,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = ben_id; - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(25)); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); @@ -367,7 +368,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) BOOST_CHECK(bitasset.current_feed.maintenance_collateral_ratio == GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); op.publisher = dan_id; - op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); + op.feed.settlement_price = op.feed.core_exchange_rate = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); op.feed.maximum_short_squeeze_ratio = 1001; op.feed.maintenance_collateral_ratio = 1001; trx.operations.back() = op; From d1d06213e11b6c543afc3d0ef3d89bf5546de08d Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 29 Oct 2015 19:17:21 -0400 Subject: [PATCH 02/32] block_tests.cpp: Fix generate_empty_blocks --- tests/tests/block_tests.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 4273054350..f61245837a 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -131,14 +131,15 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) // TODO: Don't generate this here auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); - signed_block b200; + signed_block cutoff_block; { database db; db.open(data_dir.path(), make_genesis ); b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); + // TODO: Change this test when we correct #406 // n.b. we generate GRAPHENE_MIN_UNDO_HISTORY+1 extra blocks which will be discarded on save - for( uint32_t i = 1; i < 200+GRAPHENE_MIN_UNDO_HISTORY+1; ++i ) + for( uint32_t i = 1; ; ++i ) { BOOST_CHECK( db.head_block_id() == b.id() ); //witness_id_type prev_witness = b.witness; @@ -146,8 +147,12 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) //BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); BOOST_CHECK( b.witness == cur_witness ); - if( i == 199 ) - b200 = b; + uint32_t cutoff_height = db.get_dynamic_global_properties().last_irreversible_block_num; + if( cutoff_height >= 200 ) + { + cutoff_block = *(db.fetch_block_by_number( cutoff_height )); + break; + } } db.close(); } @@ -155,7 +160,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) database db; db.open(data_dir.path(), []{return genesis_state_type();}); BOOST_CHECK_EQUAL( db.head_block_num(), 200 ); - b = b200; + b = cutoff_block; for( uint32_t i = 0; i < 200; ++i ) { BOOST_CHECK( db.head_block_id() == b.id() ); From a1b00b274926615ad65a646016a2a3efdff3eb37 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 29 Oct 2015 19:28:06 -0400 Subject: [PATCH 03/32] db_management.cpp: Only pop to last irreversible block, fix #407 --- libraries/chain/db_management.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 7aa14eaef8..4cac9941a5 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -144,7 +144,9 @@ void database::close(bool rewind) { try { - while( true ) + uint32_t cutoff = get_dynamic_global_properties().last_irreversible_block_num; + + while( head_block_num() > cutoff ) { // elog("pop"); block_id_type popped_block_id = head_block_id(); From 5e91e095c04bde597ad44ca28100d2262aacf121 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 27 Oct 2015 15:00:57 -0400 Subject: [PATCH 04/32] vesting_balance_object.cpp: Handle vesting_seconds == 0 case #390 --- libraries/chain/vesting_balance_object.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 296e4cea4a..fc32a24955 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -94,7 +94,7 @@ fc::uint128_t cdd_vesting_policy::compute_coin_seconds_earned(const vesting_poli delta_coin_seconds *= delta_seconds; fc::uint128_t coin_seconds_earned_cap = ctx.balance.amount.value; - coin_seconds_earned_cap *= vesting_seconds; + coin_seconds_earned_cap *= std::max(vesting_seconds, 1u); return std::min(coin_seconds_earned + delta_coin_seconds, coin_seconds_earned_cap); } @@ -110,7 +110,7 @@ asset cdd_vesting_policy::get_allowed_withdraw(const vesting_policy_context& ctx if(ctx.now <= start_claim) return asset(0, ctx.balance.asset_id); fc::uint128_t cs_earned = compute_coin_seconds_earned(ctx); - fc::uint128_t withdraw_available = cs_earned / vesting_seconds; + fc::uint128_t withdraw_available = cs_earned / std::max(vesting_seconds, 1u); assert(withdraw_available <= ctx.balance.amount.value); return asset(withdraw_available.to_uint64(), ctx.balance.asset_id); } @@ -123,14 +123,14 @@ void cdd_vesting_policy::on_deposit(const vesting_policy_context& ctx) void cdd_vesting_policy::on_deposit_vested(const vesting_policy_context& ctx) { on_deposit(ctx); - coin_seconds_earned += ctx.amount.amount.value * vesting_seconds; + coin_seconds_earned += ctx.amount.amount.value * std::max(vesting_seconds, 1u); } void cdd_vesting_policy::on_withdraw(const vesting_policy_context& ctx) { update_coin_seconds_earned(ctx); fc::uint128_t coin_seconds_needed = ctx.amount.amount.value; - coin_seconds_needed *= vesting_seconds; + coin_seconds_needed *= std::max(vesting_seconds, 1u); // is_withdraw_allowed should forbid any withdrawal that // would trigger this assert assert(coin_seconds_needed <= coin_seconds_earned); From fda84dfe8bdafe1b7e35565c1b022548b6f046f6 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 24 Oct 2015 12:21:48 -0400 Subject: [PATCH 05/32] witness: Submit wakeup time for fc::schedule() on local system clock, not NTP --- libraries/plugins/witness/witness.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index fd3463424b..acdad20232 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -146,12 +146,18 @@ void witness_plugin::plugin_shutdown() void witness_plugin::schedule_production_loop() { //Schedule for the next second's tick regardless of chain state - // If we would wait less than 200ms, wait for the whole second. - fc::time_point now = graphene::time::now(); - fc::time_point_sec next_second( now + fc::microseconds( 1200000 ) ); - //wdump( (now.time_since_epoch().count())(next_second) ); + // If we would wait less than 50ms, wait for the whole second. + fc::time_point ntp_now = graphene::time::now(); + fc::time_point fc_now = fc::time_point::now(); + int64_t time_to_next_second = 1000000 - (ntp_now.time_since_epoch().count() % 1000000); + if( time_to_next_second < 50000 ) // we must sleep for at least 50ms + time_to_next_second += 1000000; + + fc::time_point next_wakeup( fc_now + fc::microseconds( time_to_next_second ) ); + + //wdump( (now.time_since_epoch().count())(next_wakeup.time_since_epoch().count()) ); _block_production_task = fc::schedule([this]{block_production_loop();}, - next_second, "Witness Block Production"); + next_wakeup, "Witness Block Production"); } block_production_condition::block_production_condition_enum witness_plugin::block_production_loop() From 7d9d96fe630897ecaa19f6c208b446395d14c640 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 26 Oct 2015 17:07:26 -0400 Subject: [PATCH 06/32] genesis_util: apply_patch appends to empty list with warning --- programs/genesis_util/apply_patch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/programs/genesis_util/apply_patch.py b/programs/genesis_util/apply_patch.py index 259ee6c987..bbce41b46f 100755 --- a/programs/genesis_util/apply_patch.py +++ b/programs/genesis_util/apply_patch.py @@ -31,6 +31,9 @@ def main(): with open(filename, "r") as f: patch = json.load(f) for k, v in patch.get("append", {}).items(): + if k not in genesis: + genesis[k] = [] + sys.stderr.write("[WARN] item {k} was created\n".format(k=k)) genesis[k].extend(v) sys.stderr.write("appended {n} items to {k}\n".format(n=len(v), k=k)) for k, v in patch.get("replace", {}).items(): From 76ba85f93e596b1e6b3062952829837da24e4cde Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 23 Oct 2015 18:16:40 -0400 Subject: [PATCH 07/32] genesis_util: Implement generate_init_config.py --- programs/genesis_util/generate_init_config.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 programs/genesis_util/generate_init_config.py diff --git a/programs/genesis_util/generate_init_config.py b/programs/genesis_util/generate_init_config.py new file mode 100755 index 0000000000..6e65c69b4e --- /dev/null +++ b/programs/genesis_util/generate_init_config.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +import argparse +import json +import subprocess +import sys + +def dump_json(obj, out, pretty): + if pretty: + json.dump(obj, out, indent=2, sort_keys=True) + else: + json.dump(obj, out, separators=(",", ":"), sort_keys=True) + return + +def main(): + parser = argparse.ArgumentParser(description="Generate a patch file that adds init accounts") + parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)") + parser.add_argument("-n", "--num", metavar="N", default=11, type=int, help="number of init witnesses") + parser.add_argument("-w", "--witness", metavar="N", default=1, type=int, help="starting witness ID") + parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output") + parser.add_argument("-m", "--mname", metavar="HOSTNAME", default="", help="machine name of target machine") + parser.add_argument("-s", "--secret", metavar="SECRET", default=None, help="private key generation secret") + opts = parser.parse_args() + + if opts.secret is None: + sys.stderr.write("missing required parameter --secret\n") + sys.stderr.flush() + sys.exit(1) + + out_wits = [] + out_keys = [] + + for i in range(opts.num): + if opts.mname != "": + istr = "wit-block-signing-"+opts.mname+"-"+str(i) + else: + istr = "wit-block-signing-"+str(i) + prod_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, istr]).decode("utf-8") + prod = json.loads(prod_str) + out_wits.append('witness-id = "1.6.'+str(opts.witness+i)+'"\n') + out_keys.append("private-key = "+json.dumps([prod[0]["public_key"], prod[0]["private_key"]])+"\n") + + out_data = "".join(out_wits + ["\n"] + out_keys) + + if opts.output == "-": + sys.stdout.write(out_data) + sys.stdout.flush() + else: + with open(opts.output, "w") as f: + f.write(out_data) + return + +if __name__ == "__main__": + main() From 0f25cd2a0d078079934cdeb3db6661f82b325451 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 27 Oct 2015 13:52:23 -0400 Subject: [PATCH 08/32] Fix Issue #324 - getKeyRefs now returns for memo and active keys --- libraries/chain/account_object.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 7972963875..0830ce0747 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -128,6 +128,8 @@ set account_member_index::get_account_members(const account_obj set result; for( auto auth : a.owner.account_auths ) result.insert(auth.first); + for( auto auth : a.active.account_auths ) + result.insert(auth.first); return result; } set account_member_index::get_key_members(const account_object& a)const @@ -135,6 +137,9 @@ set account_member_index::get_key_members(const account_object& set result; for( auto auth : a.owner.key_auths ) result.insert(auth.first); + for( auto auth : a.active.key_auths ) + result.insert(auth.first); + result.insert( a.options.memo_key ); return result; } set
account_member_index::get_address_members(const account_object& a)const @@ -142,6 +147,9 @@ set
account_member_index::get_address_members(const account_object& a)c set
result; for( auto auth : a.owner.address_auths ) result.insert(auth.first); + for( auto auth : a.active.address_auths ) + result.insert(auth.first); + result.insert( a.options.memo_key ); return result; } From 57015b43faa766f0ed0cdfecf85d5271a7b3471e Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 26 Oct 2015 21:25:16 -0400 Subject: [PATCH 09/32] Add missing FC_REFLECT_TYPENAME #414 --- libraries/chain/include/graphene/chain/protocol/base.hpp | 1 + libraries/chain/include/graphene/chain/protocol/types.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libraries/chain/include/graphene/chain/protocol/base.hpp b/libraries/chain/include/graphene/chain/protocol/base.hpp index 92708933a4..5f9114b1c9 100644 --- a/libraries/chain/include/graphene/chain/protocol/base.hpp +++ b/libraries/chain/include/graphene/chain/protocol/base.hpp @@ -117,4 +117,5 @@ namespace graphene { namespace chain { } } // graphene::chain FC_REFLECT_TYPENAME( graphene::chain::operation_result ) +FC_REFLECT_TYPENAME( graphene::chain::future_extensions ) FC_REFLECT( graphene::chain::void_result, ) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 94c8a58ea7..ec0006b136 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -310,6 +310,7 @@ FC_REFLECT_TYPENAME( graphene::chain::operation_history_id_type ) FC_REFLECT_TYPENAME( graphene::chain::withdraw_permission_id_type ) FC_REFLECT_TYPENAME( graphene::chain::vesting_balance_id_type ) FC_REFLECT_TYPENAME( graphene::chain::worker_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::balance_id_type ) FC_REFLECT_TYPENAME( graphene::chain::global_property_id_type ) FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_id_type ) FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_id_type ) From d1f9216f8598290b514e59e2ed656c00458f7ab1 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 28 Oct 2015 11:51:38 -0400 Subject: [PATCH 10/32] HARDFORK enable whitelisting of everyone, but blacklisting of some --- libraries/chain/account_object.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 7972963875..839a4537c7 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -38,12 +38,23 @@ share_type cut_fee(share_type a, uint16_t p) return r.to_uint64(); } -bool account_object::is_authorized_asset(const asset_object& asset_obj) const { +bool account_object::is_authorized_asset(const asset_object& asset_obj) const +{ for( const auto id : blacklisting_accounts ) - if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() ) return false; + { + if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() ) + return false; + } + + if( asset_obj.options.whitelist_authorities.size() == 0 ) + return true; for( const auto id : whitelisting_accounts ) - if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() ) return true; + { + if( asset_obj.options.whitelist_authorities.find(id) != asset_obj.options.whitelist_authorities.end() ) + return true; + } + return false; } From 20c8ca8fa1552bfca814610c4a8e3d8e337e209b Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 30 Oct 2015 09:50:48 -0400 Subject: [PATCH 11/32] Fix #398 - reserve_asset was calling fund_fee_pool in wallet --- libraries/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index cccf510ac6..3858f4c145 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2955,7 +2955,7 @@ signed_transaction wallet_api::reserve_asset(string from, string symbol, bool broadcast /* = false */) { - return my->fund_asset_fee_pool(from, amount, symbol, broadcast); + return my->reserve_asset(from, amount, symbol, broadcast); } signed_transaction wallet_api::global_settle_asset(string symbol, From db045f453cd303d32b42142144b1363f8fd62f80 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 13:10:09 -0400 Subject: [PATCH 12/32] Implement hardfork logic for #415 --- libraries/chain/account_object.cpp | 10 +++++++--- libraries/chain/asset_evaluator.cpp | 8 ++++---- .../include/graphene/chain/account_object.hpp | 2 +- .../chain/include/graphene/chain/hardfork.hpp | 1 + libraries/chain/market_evaluator.cpp | 6 +++--- libraries/chain/transfer_evaluator.cpp | 16 ++++++++-------- .../chain/withdraw_permission_evaluator.cpp | 6 +++--- tests/tests/uia_tests.cpp | 6 +++--- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 839a4537c7..ef52056c20 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace graphene { namespace chain { @@ -38,7 +39,7 @@ share_type cut_fee(share_type a, uint16_t p) return r.to_uint64(); } -bool account_object::is_authorized_asset(const asset_object& asset_obj) const +bool account_object::is_authorized_asset(const asset_object& asset_obj, const database& d) const { for( const auto id : blacklisting_accounts ) { @@ -46,8 +47,11 @@ bool account_object::is_authorized_asset(const asset_object& asset_obj) const return false; } - if( asset_obj.options.whitelist_authorities.size() == 0 ) - return true; + if( d.head_block_time() > HARDFORK_415_TIME ) + { + if( asset_obj.options.whitelist_authorities.size() == 0 ) + return true; + } for( const auto id : whitelisting_accounts ) { diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 2fe586dad7..03e07e662b 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -126,7 +126,7 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o ) { try { - database& d = db(); + const database& d = db(); const asset_object& a = o.asset_to_issue.asset_id(d); FC_ASSERT( o.issuer == a.issuer ); @@ -136,7 +136,7 @@ void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o ) if( a.options.flags & white_list ) { - FC_ASSERT( to_account->is_authorized_asset( a ) ); + FC_ASSERT( to_account->is_authorized_asset( a, d ) ); } asset_dyn_data = &a.dynamic_asset_data_id(d); @@ -158,7 +158,7 @@ void_result asset_issue_evaluator::do_apply( const asset_issue_operation& o ) void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& o ) { try { - database& d = db(); + const database& d = db(); const asset_object& a = o.amount_to_reserve.asset_id(d); GRAPHENE_ASSERT( @@ -172,7 +172,7 @@ void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& if( a.options.flags & white_list ) { - FC_ASSERT( from_account->is_authorized_asset( a ) ); + FC_ASSERT( from_account->is_authorized_asset( a, d ) ); } asset_dyn_data = &a.dynamic_asset_data_id(d); diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 7c6dac905e..5067292dfb 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -229,7 +229,7 @@ namespace graphene { namespace chain { * @return true if this account is whitelisted and not blacklisted to transact in the provided asset; false * otherwise. */ - bool is_authorized_asset(const asset_object& asset_obj)const; + bool is_authorized_asset(const asset_object& asset_obj, const database& d)const; account_id_type get_id()const { return id; } }; diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index 01907932d0..503e5f0b1c 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -22,3 +22,4 @@ #define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) +#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index a0eeac97e7..19f7742f67 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -29,7 +29,7 @@ namespace graphene { namespace chain { void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_operation& op) { try { - database& d = db(); + const database& d = db(); FC_ASSERT( op.expiration >= d.head_block_time() ); @@ -42,8 +42,8 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o if( _sell_asset->options.blacklist_markets.size() ) FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end() ); - 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 ) ); + if( _sell_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) ); + if( _receive_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) ); 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) ); diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 91e6eeb41a..521f2f5564 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -26,7 +26,7 @@ namespace graphene { namespace chain { void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) { try { - database& d = db(); + const database& d = db(); const account_object& from_account = op.from(d); const account_object& to_account = op.to(d); @@ -38,14 +38,14 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) if( asset_type.options.flags & white_list ) { GRAPHENE_ASSERT( - from_account.is_authorized_asset( asset_type ), + from_account.is_authorized_asset( asset_type, d ), transfer_from_account_not_whitelisted, "'from' account ${from} is not whitelisted for asset ${asset}", ("from",op.from) ("asset",op.amount.asset_id) ); GRAPHENE_ASSERT( - to_account.is_authorized_asset( asset_type ), + to_account.is_authorized_asset( asset_type, d ), transfer_to_account_not_whitelisted, "'to' account ${to} is not whitelisted for asset ${asset}", ("to",op.to) @@ -54,7 +54,7 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) } if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); if( asset_type.is_transfer_restricted() ) { @@ -87,7 +87,7 @@ void_result transfer_evaluator::do_apply( const transfer_operation& o ) void_result override_transfer_evaluator::do_evaluate( const override_transfer_operation& op ) { try { - database& d = db(); + const database& d = db(); const asset_object& asset_type = op.amount.asset_id(d); GRAPHENE_ASSERT( @@ -104,12 +104,12 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op if( asset_type.options.flags & white_list ) { - FC_ASSERT( to_account.is_authorized_asset( asset_type ) ); - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( to_account.is_authorized_asset( asset_type, d ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); } if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); 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) ); diff --git a/libraries/chain/withdraw_permission_evaluator.cpp b/libraries/chain/withdraw_permission_evaluator.cpp index 620a2af748..17e96c4533 100644 --- a/libraries/chain/withdraw_permission_evaluator.cpp +++ b/libraries/chain/withdraw_permission_evaluator.cpp @@ -53,7 +53,7 @@ object_id_type withdraw_permission_create_evaluator::do_apply(const operation_ty void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_permission_claim_evaluator::operation_type& op) { try { - database& d = db(); + const database& d = db(); const withdraw_permission_object& permit = op.withdraw_permission(d); FC_ASSERT(permit.expiration > d.head_block_time() ); @@ -69,8 +69,8 @@ void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_perm { const account_object& from = op.withdraw_to_account(d); const account_object& to = permit.authorized_account(d); - FC_ASSERT( to.is_authorized_asset( _asset ) ); - FC_ASSERT( from.is_authorized_asset( _asset ) ); + FC_ASSERT( to.is_authorized_asset( _asset, d ) ); + FC_ASSERT( from.is_authorized_asset( _asset, d ) ); } return void_result(); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 2ef816c93a..924a91fdce 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) trx.operations.back() = wop; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK(nathan.is_authorized_asset(advanced)); + BOOST_CHECK(nathan.is_authorized_asset(advanced, db)); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) trx.operations.back() = op; //Fail because nathan is blacklisted - BOOST_CHECK(!nathan.is_authorized_asset(advanced)); + BOOST_CHECK(!nathan.is_authorized_asset(advanced, db)); GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); //Remove nathan from committee's whitelist, add him to dan's. This should not authorize him to hold ADVANCED. @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) trx.operations.back() = op; //Fail because nathan is not whitelisted - BOOST_CHECK(!nathan.is_authorized_asset(advanced)); + BOOST_CHECK(!nathan.is_authorized_asset(advanced, db)); GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); burn.payer = dan.id; From d821d4a9936e715ae2073cc9028172a835946111 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 13:47:22 -0400 Subject: [PATCH 13/32] Get rid of enforce_white_list() #416 --- libraries/chain/account_object.cpp | 7 ++++++- libraries/chain/confidential_evaluator.cpp | 2 +- .../chain/include/graphene/chain/asset_object.hpp | 2 -- libraries/chain/include/graphene/chain/hardfork.hpp | 1 + .../include/graphene/chain/protocol/asset_ops.hpp | 9 ++++----- libraries/chain/market_evaluator.cpp | 12 ++++++++++-- libraries/chain/withdraw_permission_evaluator.cpp | 13 ++++++++++++- tests/tests/operation_tests.cpp | 2 +- tests/tests/uia_tests.cpp | 2 +- 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index ef52056c20..6ef1c04271 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -41,6 +41,12 @@ share_type cut_fee(share_type a, uint16_t p) bool account_object::is_authorized_asset(const asset_object& asset_obj, const database& d) const { + if( d.head_block_time() > HARDFORK_416_TIME ) + { + if( !(asset_obj.options.flags & white_list) ) + return true; + } + for( const auto id : blacklisting_accounts ) { if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() ) @@ -68,7 +74,6 @@ void account_balance_object::adjust_balance(const asset& delta) balance += delta.amount; } - void account_statistics_object::process_fees(const account_object& a, database& d) const { if( pending_fees > 0 || pending_vested_fees > 0 ) diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 014e62243e..065cbe4300 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -32,7 +32,7 @@ void_result transfer_to_blind_evaluator::do_evaluate( const transfer_to_blind_op const auto& atype = o.amount.asset_id(db()); FC_ASSERT( atype.allow_confidential() ); FC_ASSERT( !atype.is_transfer_restricted() ); - FC_ASSERT( !atype.enforce_white_list() ); + FC_ASSERT( !(atype.options.flags & white_list) ); for( const auto& out : o.outputs ) { diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 4496fe0355..1ffe7e9506 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -82,8 +82,6 @@ namespace graphene { namespace chain { /// @return true if symbol is a valid ticker symbol; false otherwise. static bool is_valid_symbol( const string& symbol ); - /// @return true if accounts must be on a whitelist in order to hold this asset; false otherwise. - bool enforce_white_list()const { return options.flags & white_list; } /// @return true if this is a market-issued asset; false otherwise. bool is_market_issued()const { return bitasset_data_id.valid(); } /// @return true if users may request force-settlement of this market-issued asset; false otherwise diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index 503e5f0b1c..da94532d48 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -23,3 +23,4 @@ #define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) +#define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 )) diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index e0cd26ebc6..afb7b8e221 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -53,12 +53,11 @@ namespace graphene { namespace chain { /// the core exchange rate. price core_exchange_rate; - /// A set of accounts which maintain whitelists to consult for this asset. If enforce_white_list() returns - /// true, an account may only send, receive, trade, etc. in this asset if one of these accounts appears in - /// its account_object::whitelisting_accounts field. + /// A set of accounts which maintain whitelists to consult for this asset. If whitelist_authorities + /// is non-empty, then only accounts in whitelist_authorities are allowed to hold, use, or transfer the asset. flat_set whitelist_authorities; - /// A set of accounts which maintain blacklists to consult for this asset. If enforce_white_list() returns - /// true, an account may only send, receive, trade, etc. in this asset if none of these accounts appears in + /// A set of accounts which maintain blacklists to consult for this asset. If flags & white_list is set, + /// an account may only send, receive, trade, etc. in this asset if none of these accounts appears in /// its account_object::blacklisting_accounts field. If the account is blacklisted, it may not transact in /// this asset even if it is also whitelisted. flat_set blacklist_authorities; diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 19f7742f67..f357a18e4e 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -42,8 +42,16 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o if( _sell_asset->options.blacklist_markets.size() ) FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end() ); - if( _sell_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) ); - if( _receive_asset->enforce_white_list() ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) ); + if( d.head_block_time() <= HARDFORK_416_TIME ) + { + if( _sell_asset->options.flags & white_list ) FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) ); + if( _receive_asset->options.flags & white_list ) FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) ); + } + else + { + FC_ASSERT( _seller->is_authorized_asset( *_sell_asset, d ) ); + FC_ASSERT( _seller->is_authorized_asset( *_receive_asset, d ) ); + } 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) ); diff --git a/libraries/chain/withdraw_permission_evaluator.cpp b/libraries/chain/withdraw_permission_evaluator.cpp index 17e96c4533..1c1fb62098 100644 --- a/libraries/chain/withdraw_permission_evaluator.cpp +++ b/libraries/chain/withdraw_permission_evaluator.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace graphene { namespace chain { @@ -65,7 +66,17 @@ void_result withdraw_permission_claim_evaluator::do_evaluate(const withdraw_perm const asset_object& _asset = op.amount_to_withdraw.asset_id(d); if( _asset.is_transfer_restricted() ) FC_ASSERT( _asset.issuer == permit.authorized_account || _asset.issuer == permit.withdraw_from_account ); - if( _asset.enforce_white_list() ) + if( d.head_block_time() <= HARDFORK_416_TIME ) + { + if( _asset.options.flags & white_list ) + { + const account_object& from = op.withdraw_to_account(d); + const account_object& to = permit.authorized_account(d); + FC_ASSERT( to.is_authorized_asset( _asset, d ) ); + FC_ASSERT( from.is_authorized_asset( _asset, d ) ); + } + } + else { const account_object& from = op.withdraw_to_account(d); const account_object& to = permit.authorized_account(d); diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 001450af32..b85b3161b9 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -687,7 +687,7 @@ BOOST_AUTO_TEST_CASE( create_uia ) const asset_object& test_asset = test_asset_id(db); BOOST_CHECK(test_asset.symbol == "TEST"); BOOST_CHECK(asset(1, test_asset_id) * test_asset.options.core_exchange_rate == asset(2)); - BOOST_CHECK(!test_asset.enforce_white_list()); + BOOST_CHECK((test_asset.options.flags & white_list) == 0); BOOST_CHECK(test_asset.options.max_supply == 100000000); BOOST_CHECK(!test_asset.bitasset_data_id.valid()); BOOST_CHECK(test_asset.options.market_fee_percent == GRAPHENE_MAX_MARKET_FEE_PERCENT/100); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 924a91fdce..25b134845b 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE( create_advanced_uia ) const asset_object& test_asset = test_asset_id(db); BOOST_CHECK(test_asset.symbol == "ADVANCED"); BOOST_CHECK(asset(1, test_asset_id) * test_asset.options.core_exchange_rate == asset(2)); - BOOST_CHECK(test_asset.enforce_white_list()); + BOOST_CHECK(test_asset.options.flags & white_list); BOOST_CHECK(test_asset.options.max_supply == 100000000); BOOST_CHECK(!test_asset.bitasset_data_id.valid()); BOOST_CHECK(test_asset.options.market_fee_percent == GRAPHENE_MAX_MARKET_FEE_PERCENT/100); From 4f2b8bd6f6dc295f2197002611b03cb1e8f8b234 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 14:22:02 -0400 Subject: [PATCH 14/32] HARDFORK Move fee blacklist check to evaluator #419 --- libraries/chain/evaluator.cpp | 19 ++++++++++++++----- .../chain/include/graphene/chain/hardfork.hpp | 1 + libraries/chain/transfer_evaluator.cpp | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 4a190963fd..878d98cbd3 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -46,17 +47,25 @@ database& generic_evaluator::db()const { return trx_state->db(); } void generic_evaluator::prepare_fee(account_id_type account_id, asset fee) { + const database& d = db(); fee_from_account = fee; FC_ASSERT( fee.amount >= 0 ); - fee_paying_account = &account_id(db()); - fee_paying_account_statistics = &fee_paying_account->statistics(db()); + fee_paying_account = &account_id(d); + fee_paying_account_statistics = &fee_paying_account->statistics(d); - fee_asset = &fee.asset_id(db()); - fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(db()); + fee_asset = &fee.asset_id(d); + fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); + + if( d.head_block_time() > HARDFORK_419_TIME ) + { + FC_ASSERT( fee_paying_account->is_authorized_asset( *fee_asset, d ), "Account ${acct} '${name}' attempted to pay fee by using asset ${a} '${sym}', which is unauthorized due to whitelist / blacklist", + ("acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id)("sym", fee_asset->symbol) ); + } if( fee_from_account.asset_id == asset_id_type() ) core_fee_paid = fee_from_account.amount; - else { + else + { asset fee_from_pool = fee_from_account * fee_asset->options.core_exchange_rate; FC_ASSERT( fee_from_pool.asset_id == asset_id_type() ); core_fee_paid = fee_from_pool.amount; diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index da94532d48..821f930643 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -24,3 +24,4 @@ #define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) #define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 )) +#define HARDFORK_419_TIME (fc::time_point_sec( 1446652800 )) diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 521f2f5564..0f1a1f3caa 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace graphene { namespace chain { void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) @@ -53,8 +54,12 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) ); } - if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); + if( d.head_block_time() <= HARDFORK_419_TIME ) + { + if( fee_asset_type.options.flags & white_list ) + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); + } + // the above becomes no-op after hardfork because this check will then be performed in evaluator if( asset_type.is_transfer_restricted() ) { @@ -108,8 +113,12 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); } - if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); + if( d.head_block_time() <= HARDFORK_419_TIME ) + { + if( fee_asset_type.options.flags & white_list ) + FC_ASSERT( from_account.is_authorized_asset( asset_type, d ) ); + } + // the above becomes no-op after hardfork because this check will then be performed in evaluator 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) ); From 032eeda416f2214a83a10de86944c5d80e4a39a4 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Tue, 27 Oct 2015 18:41:38 -0400 Subject: [PATCH 15/32] generic_index.hpp: Change sparse_index to use ordered_unique --- libraries/db/include/graphene/db/generic_index.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/db/include/graphene/db/generic_index.hpp b/libraries/db/include/graphene/db/generic_index.hpp index 1ccb4154a6..d93546cf27 100644 --- a/libraries/db/include/graphene/db/generic_index.hpp +++ b/libraries/db/include/graphene/db/generic_index.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace graphene { namespace chain { @@ -117,7 +116,7 @@ namespace graphene { namespace chain { struct sparse_index : public generic_index, member > From 5d6091e58190cfa8ab1d8cf224d603c5242fc670 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 27 Oct 2015 11:05:59 -0400 Subject: [PATCH 16/32] HARDFORK - adding operation to claim asset fees #413 --- libraries/app/impacted.cpp | 1 + libraries/chain/asset_evaluator.cpp | 27 +++++++++++++++++++ libraries/chain/db_init.cpp | 1 + .../graphene/chain/asset_evaluator.hpp | 9 +++++++ .../chain/include/graphene/chain/hardfork.hpp | 2 -- .../graphene/chain/protocol/asset_ops.hpp | 22 +++++++++++++++ .../graphene/chain/protocol/operations.hpp | 4 +-- libraries/chain/market_evaluator.cpp | 1 + libraries/chain/protocol/asset_ops.cpp | 5 ++++ 9 files changed, 68 insertions(+), 4 deletions(-) diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index f5ed105164..e928a369de 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -39,6 +39,7 @@ struct get_impacted_account_visitor _impacted.insert( op.to ); } + void operator()( const asset_claim_fees_operation& op ){} void operator()( const limit_order_create_operation& op ) {} void operator()( const limit_order_cancel_operation& op ) { diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 2fe586dad7..bc84cefd72 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -514,4 +514,31 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope return void_result(); } FC_CAPTURE_AND_RETHROW((o)) } + + +void_result asset_claim_fees_evaluator::do_evaluate( const asset_claim_fees_operation& o ) +{ try { + FC_ASSERT( o.amount_to_claim.asset_id(db()).issuer == o.issuer, "Asset fees may only be claimed by the issuer" ); + return void_result(); +} FC_CAPTURE_AND_RETHROW( (o) ) } + + +void_result asset_claim_fees_evaluator::do_apply( const asset_claim_fees_operation& o ) +{ try { + database& d = db(); + + const asset_object& a = o.amount_to_claim.asset_id(d); + const asset_dynamic_data_object& addo = a.dynamic_asset_data_id(d); + FC_ASSERT( o.amount_to_claim.amount <= addo.accumulated_fees, "Attempt to claim more fees than have accumulated", ("addo",addo) ); + + d.modify( addo, [&]( asset_dynamic_data_object& _addo ) { + _addo.accumulated_fees -= o.amount_to_claim.amount; + }); + + d.adjust_balance( o.issuer, o.amount_to_claim ); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (o) ) } + + } } // graphene::chain diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 2d06aa94ad..ba2d07a609 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -158,6 +158,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); } void database::initialize_indexes() diff --git a/libraries/chain/include/graphene/chain/asset_evaluator.hpp b/libraries/chain/include/graphene/chain/asset_evaluator.hpp index 7e5b926870..d302450e6b 100644 --- a/libraries/chain/include/graphene/chain/asset_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/asset_evaluator.hpp @@ -133,4 +133,13 @@ namespace graphene { namespace chain { std::map,price_feed> median_feed_values; }; + class asset_claim_fees_evaluator : public evaluator + { + public: + typedef asset_claim_fees_operation operation_type; + + void_result do_evaluate( const asset_claim_fees_operation& o ); + void_result do_apply( const asset_claim_fees_operation& o ); + }; + } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index 01907932d0..e5da0a01c3 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -20,5 +20,3 @@ */ #pragma once -#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 )) -#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) diff --git a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp index e0cd26ebc6..f81f39f700 100644 --- a/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp +++ b/libraries/chain/include/graphene/chain/protocol/asset_ops.hpp @@ -420,8 +420,30 @@ namespace graphene { namespace chain { void validate()const; }; + /** + * @brief used to transfer accumulated fees back to the issuer's balance. + */ + struct asset_claim_fees_operation : public base_operation + { + struct fee_parameters_type { + uint64_t fee = 20 * GRAPHENE_BLOCKCHAIN_PRECISION; + }; + + asset fee; + account_id_type issuer; + asset amount_to_claim; /// amount_to_claim.asset_id->issuer must == issuer + extensions_type extensions; + + account_id_type fee_payer()const { return issuer; } + void validate()const; + }; + + } } // graphene::chain +FC_REFLECT( graphene::chain::asset_claim_fees_operation, (fee)(issuer)(amount_to_claim)(extensions) ) +FC_REFLECT( graphene::chain::asset_claim_fees_operation::fee_parameters_type, (fee) ) + FC_REFLECT( graphene::chain::asset_options, (max_supply) (market_fee_percent) diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 9ef0c54917..55cfdf93e4 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -85,8 +85,8 @@ namespace graphene { namespace chain { transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, - - asset_settle_cancel_operation // VIRTUAL + asset_settle_cancel_operation, // VIRTUAL + asset_claim_fees_operation > operation; /// @} // operations group diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index a0eeac97e7..723735fa22 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -95,6 +95,7 @@ asset limit_order_cancel_evaluator::do_apply(const limit_order_cancel_operation& auto quote_asset = _order->sell_price.quote.asset_id; auto refunded = _order->amount_for_sale(); + /// TODO... implement this refund in a better way if( true ) // HARD FORK d.head_block_time() > { const auto& fees = d.current_fee_schedule(); diff --git a/libraries/chain/protocol/asset_ops.cpp b/libraries/chain/protocol/asset_ops.cpp index b73a0b8256..bf0c126a98 100644 --- a/libraries/chain/protocol/asset_ops.cpp +++ b/libraries/chain/protocol/asset_ops.cpp @@ -224,4 +224,9 @@ void asset_options::validate()const } } +void asset_claim_fees_operation::validate()const { + FC_ASSERT( fee.amount >= 0 ); + FC_ASSERT( amount_to_claim.amount > 0 ); +} + } } // namespace graphene::chain From 966b3edf0c777906e8a75772d8176d87ebe10797 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 13:02:44 -0400 Subject: [PATCH 17/32] Add hardfork logic #413 --- libraries/chain/asset_evaluator.cpp | 1 + libraries/chain/include/graphene/chain/hardfork.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index bc84cefd72..889d9f2576 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -518,6 +518,7 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope void_result asset_claim_fees_evaluator::do_evaluate( const asset_claim_fees_operation& o ) { try { + FC_ASSERT( db().head_block_time() > HARDFORK_413_TIME ); FC_ASSERT( o.amount_to_claim.asset_id(db()).issuer == o.issuer, "Asset fees may only be claimed by the issuer" ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index e5da0a01c3..2c5571087d 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -20,3 +20,4 @@ */ #pragma once +#define HARDFORK_413_TIME (fc::time_point_sec( 1446652800 )) From e8b1deec03a83d313e9e31243fb66d29c05f4511 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 18:17:19 -0400 Subject: [PATCH 18/32] uia_tests.cpp: Mostly rewrite issue_whitelist_uia to test new whitelist logic #415 --- tests/tests/uia_tests.cpp | 64 +++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 924a91fdce..4054143c41 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -134,33 +135,72 @@ BOOST_AUTO_TEST_CASE( override_transfer_test2 ) BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) { try { - INVOKE(create_advanced_uia); - const asset_object& advanced = get_asset("ADVANCED"); - const account_object& nathan = create_account("nathan"); - upgrade_to_lifetime_member(nathan); + account_id_type dan_id = create_account("dan").id; + const asset_id_type uia_id = create_user_issued_asset( + "WLUIA", dan_id(db), white_list ).id; + account_id_type nathan_id = create_account("nathan").id; + account_id_type vikram_id = create_account("vikram").id; trx.clear(); asset_issue_operation op; - op.issuer = advanced.issuer; - op.asset_to_issue = advanced.amount(1000); - op.issue_to_account = nathan.id; //({asset(), advanced.issuer, advanced.amount(1000), nathan.id}); + op.issuer = uia_id(db).issuer; + op.asset_to_issue = asset(1000, uia_id); + op.issue_to_account = nathan_id; trx.operations.emplace_back(op); - //Fail because nathan is not whitelisted. + set_expiration( db, trx ); + //Fail because nathan is not whitelisted, but only before hardfork time GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); + generate_blocks( HARDFORK_415_TIME ); + generate_block(); + set_expiration( db, trx ); + PUSH_TX( db, trx, ~0 ); + + BOOST_CHECK(nathan_id(db).is_authorized_asset(uia_id(db), db)); + BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 1000); + + // Make a whitelist, now it should fail + { + BOOST_TEST_MESSAGE( "Changing the whitelist authority" ); + asset_update_operation uop; + uop.issuer = dan_id; + uop.asset_to_update = uia_id; + uop.new_options = uia_id(db).options; + uop.new_options.whitelist_authorities.insert(dan_id); + trx.operations.back() = uop; + PUSH_TX( db, trx, ~0 ); + BOOST_CHECK( uia_id(db).options.whitelist_authorities.find(dan_id) != uia_id(db).options.whitelist_authorities.end() ); + } + + // Fail because there is a whitelist authority and I'm not whitelisted + trx.operations.back() = op; + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); account_whitelist_operation wop; - wop.authorizing_account = account_id_type(); - wop.account_to_list = nathan.id; + wop.authorizing_account = dan_id; + wop.account_to_list = vikram_id; wop.new_listing = account_whitelist_operation::white_listed; trx.operations.back() = wop; + // Fail because whitelist function is restricted to members only + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); + upgrade_to_lifetime_member( dan_id ); + trx.operations.clear(); + trx.operations.push_back( wop ); PUSH_TX( db, trx, ~0 ); - BOOST_CHECK(nathan.is_authorized_asset(advanced, db)); + // Still fail after an irrelevant account was added + trx.operations.back() = op; + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); + + wop.account_to_list = nathan_id; + trx.operations.back() = wop; + PUSH_TX( db, trx, ~0 ); trx.operations.back() = op; + BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 1000); + // Finally succeed when we were whitelisted PUSH_TX( db, trx, ~0 ); + BOOST_CHECK_EQUAL(get_balance(nathan_id, uia_id), 2000); - BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 1000); } catch(fc::exception& e) { edump((e.to_detail_string())); throw; From 1559df551a5cdcfbe4a2788584c7c291f6d80a74 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 10:40:37 -0400 Subject: [PATCH 19/32] uia_tests.cpp: Fix transfer_whitelist_uia test broken by issue_whitelist_uia changes #415 --- tests/tests/uia_tests.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 4054143c41..c8a7ae05c1 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -135,9 +135,9 @@ BOOST_AUTO_TEST_CASE( override_transfer_test2 ) BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) { try { - account_id_type dan_id = create_account("dan").id; + account_id_type izzy_id = create_account("izzy").id; const asset_id_type uia_id = create_user_issued_asset( - "WLUIA", dan_id(db), white_list ).id; + "ADVANCED", izzy_id(db), white_list ).id; account_id_type nathan_id = create_account("nathan").id; account_id_type vikram_id = create_account("vikram").id; trx.clear(); @@ -162,13 +162,13 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) { BOOST_TEST_MESSAGE( "Changing the whitelist authority" ); asset_update_operation uop; - uop.issuer = dan_id; + uop.issuer = izzy_id; uop.asset_to_update = uia_id; uop.new_options = uia_id(db).options; - uop.new_options.whitelist_authorities.insert(dan_id); + uop.new_options.whitelist_authorities.insert(izzy_id); trx.operations.back() = uop; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK( uia_id(db).options.whitelist_authorities.find(dan_id) != uia_id(db).options.whitelist_authorities.end() ); + BOOST_CHECK( uia_id(db).options.whitelist_authorities.find(izzy_id) != uia_id(db).options.whitelist_authorities.end() ); } // Fail because there is a whitelist authority and I'm not whitelisted @@ -176,14 +176,14 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); account_whitelist_operation wop; - wop.authorizing_account = dan_id; + wop.authorizing_account = izzy_id; wop.account_to_list = vikram_id; wop.new_listing = account_whitelist_operation::white_listed; trx.operations.back() = wop; // Fail because whitelist function is restricted to members only GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); - upgrade_to_lifetime_member( dan_id ); + upgrade_to_lifetime_member( izzy_id ); trx.operations.clear(); trx.operations.push_back( wop ); PUSH_TX( db, trx, ~0 ); @@ -214,6 +214,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) const asset_object& advanced = get_asset("ADVANCED"); const account_object& nathan = get_account("nathan"); const account_object& dan = create_account("dan"); + account_id_type izzy_id = get_account("izzy").id; upgrade_to_lifetime_member(dan); trx.clear(); @@ -229,23 +230,36 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) BOOST_TEST_MESSAGE( "Adding dan to whitelist for asset ADVANCED" ); account_whitelist_operation wop; - wop.authorizing_account = account_id_type(); + wop.authorizing_account = izzy_id; wop.account_to_list = dan.id; wop.new_listing = account_whitelist_operation::white_listed; trx.operations.back() = wop; PUSH_TX( db, trx, ~0 ); - BOOST_TEST_MESSAGE( "Attempting to trnsfer from nathan to dan after whitelisting dan, should succeed" ); + BOOST_TEST_MESSAGE( "Attempting to transfer from nathan to dan after whitelisting dan, should succeed" ); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 900); + BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 1900); BOOST_CHECK_EQUAL(get_balance(dan, advanced), 100); BOOST_TEST_MESSAGE( "Attempting to blacklist nathan" ); + { + BOOST_TEST_MESSAGE( "Changing the blacklist authority" ); + asset_update_operation uop; + uop.issuer = izzy_id; + uop.asset_to_update = advanced.id; + uop.new_options = advanced.options; + uop.new_options.blacklist_authorities.insert(izzy_id); + trx.operations.back() = uop; + PUSH_TX( db, trx, ~0 ); + BOOST_CHECK( advanced.options.blacklist_authorities.find(izzy_id) != advanced.options.blacklist_authorities.end() ); + } + wop.new_listing |= account_whitelist_operation::black_listed; wop.account_to_list = nathan.id; trx.operations.back() = wop; PUSH_TX( db, trx, ~0 ); + BOOST_CHECK( !(nathan.is_authorized_asset(advanced, db)) ); BOOST_TEST_MESSAGE( "Attempting to transfer from nathan after blacklisting, should fail" ); op.amount = advanced.amount(50); @@ -270,6 +284,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) { BOOST_TEST_MESSAGE( "Changing the blacklist authority to dan" ); asset_update_operation op; + op.issuer = izzy_id; op.asset_to_update = advanced.id; op.new_options = advanced.options; op.new_options.blacklist_authorities.clear(); @@ -282,7 +297,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) BOOST_TEST_MESSAGE( "Attempting to transfer from dan back to nathan" ); trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 950); + BOOST_CHECK_EQUAL(get_balance(nathan, advanced), 1950); BOOST_CHECK_EQUAL(get_balance(dan, advanced), 50); BOOST_TEST_MESSAGE( "Blacklisting nathan by dan" ); @@ -298,7 +313,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); //Remove nathan from committee's whitelist, add him to dan's. This should not authorize him to hold ADVANCED. - wop.authorizing_account = account_id_type(); + wop.authorizing_account = izzy_id; wop.account_to_list = nathan.id; wop.new_listing = account_whitelist_operation::no_listing; trx.operations.back() = wop; From fabe83fbadd711dd8e66dd67e266d6e64fc2b074 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 19:12:05 -0400 Subject: [PATCH 20/32] database_fixture.cpp: Make GRAPHENE_TESTING_GENESIS_TIMESTAMP configurable #427 --- tests/common/database_fixture.cpp | 2 ++ tests/common/database_fixture.hpp | 2 +- tests/tests/main.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index e671aba406..676c53b55e 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -46,6 +46,8 @@ using namespace graphene::chain::test; +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; + namespace graphene { namespace chain { using std::cout; diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 4f38c60388..9bb218a90c 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -29,7 +29,7 @@ using namespace graphene::db; -#define GRAPHENE_TESTING_GENESIS_TIMESTAMP (1431700000) +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; #define PUSH_TX \ graphene::chain::test::_push_transaction diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index c3ce06314d..906bbca005 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -23,8 +23,16 @@ #include #include +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; + boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { std::srand(time(NULL)); std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; return nullptr; } From cf4efca17f7c92418a02760e8c31308aeac45ae9 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 10:28:23 -0400 Subject: [PATCH 21/32] uia_tests.cpp: Add hardfork logic to issue_whitelist_uia #415 --- tests/tests/uia_tests.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index c8a7ae05c1..41cda68fca 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -149,10 +149,13 @@ BOOST_AUTO_TEST_CASE( issue_whitelist_uia ) trx.operations.emplace_back(op); set_expiration( db, trx ); //Fail because nathan is not whitelisted, but only before hardfork time - GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); - generate_blocks( HARDFORK_415_TIME ); - generate_block(); - set_expiration( db, trx ); + if( db.head_block_time() <= HARDFORK_415_TIME ) + { + GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); + generate_blocks( HARDFORK_415_TIME ); + generate_block(); + set_expiration( db, trx ); + } PUSH_TX( db, trx, ~0 ); BOOST_CHECK(nathan_id(db).is_authorized_asset(uia_id(db), db)); From e1a692b33c95e36f4a59f5b4ca18451c695d232f Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 10:39:16 -0400 Subject: [PATCH 22/32] operation_tests2.cpp: Fix witness_create test to comply with new witness schedule (breakage revealed by #427) --- tests/tests/operation_tests2.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ee05ffd927..ecf4a1ad09 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -453,15 +453,16 @@ BOOST_AUTO_TEST_CASE( witness_create ) generate_block(); int produced = 0; - // Make sure we get scheduled exactly once in witnesses.size() blocks + // Make sure we get scheduled at least once in witnesses.size()*2 blocks + // may take this many unless we measure where in the scheduling round we are // TODO: intense_test that repeats this loop many times - for( size_t i=0; i Date: Tue, 27 Oct 2015 18:41:21 -0400 Subject: [PATCH 23/32] global_property_object.hpp: Reflect last_budget_time #414 --- .../chain/include/graphene/chain/global_property_object.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index b861e5be9f..61aecf978c 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -128,6 +128,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene:: (time) (current_witness) (next_maintenance_time) + (last_budget_time) (witness_budget) (accounts_registered_this_interval) (recently_missed_count) From ef1c721690327b80c435964ce876e17a9fbfe0b0 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 16:58:56 -0400 Subject: [PATCH 24/32] fee_tests.cpp: Implement asset_claim_fees_test #413 --- tests/tests/fee_tests.cpp | 133 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index ce69abad8e..e65cb92bad 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -67,6 +68,138 @@ BOOST_AUTO_TEST_CASE( nonzero_fee_test ) } } +BOOST_AUTO_TEST_CASE(asset_claim_fees_test) +{ + try + { + ACTORS((alice)(bob)(izzy)(jill)); + // Izzy issues asset to Alice + // Jill issues asset to Bob + // Alice and Bob trade in the market and pay fees + // Verify that Izzy and Jill can claim the fees + + const share_type core_prec = asset::scaled_precision( asset_id_type()(db).precision ); + + // Return number of core shares (times precision) + auto _core = [&]( int64_t x ) -> asset + { return asset( x*core_prec ); }; + + transfer( committee_account, alice_id, _core(1000000) ); + transfer( committee_account, bob_id, _core(1000000) ); + transfer( committee_account, izzy_id, _core(1000000) ); + transfer( committee_account, jill_id, _core(1000000) ); + + asset_id_type izzycoin_id = create_bitasset( "IZZYCOIN", izzy_id, GRAPHENE_1_PERCENT, charge_market_fee ).id; + asset_id_type jillcoin_id = create_bitasset( "JILLCOIN", jill_id, 2*GRAPHENE_1_PERCENT, charge_market_fee ).id; + + const share_type izzy_prec = asset::scaled_precision( asset_id_type(izzycoin_id)(db).precision ); + const share_type jill_prec = asset::scaled_precision( asset_id_type(jillcoin_id)(db).precision ); + + auto _izzy = [&]( int64_t x ) -> asset + { return asset( x*izzy_prec, izzycoin_id ); }; + auto _jill = [&]( int64_t x ) -> asset + { return asset( x*jill_prec, jillcoin_id ); }; + + update_feed_producers( izzycoin_id(db), { izzy_id } ); + update_feed_producers( jillcoin_id(db), { jill_id } ); + + const asset izzy_satoshi = asset(1, izzycoin_id); + const asset jill_satoshi = asset(1, jillcoin_id); + + // Izzycoin is worth 100 BTS + price_feed feed; + feed.settlement_price = price( _izzy(1), _core(100) ); + feed.maintenance_collateral_ratio = 175 * GRAPHENE_COLLATERAL_RATIO_DENOM / 100; + feed.maximum_short_squeeze_ratio = 150 * GRAPHENE_COLLATERAL_RATIO_DENOM / 100; + publish_feed( izzycoin_id(db), izzy, feed ); + + // Jillcoin is worth 30 BTS + feed.settlement_price = price( _jill(1), _core(30) ); + feed.maintenance_collateral_ratio = 175 * GRAPHENE_COLLATERAL_RATIO_DENOM / 100; + feed.maximum_short_squeeze_ratio = 150 * GRAPHENE_COLLATERAL_RATIO_DENOM / 100; + publish_feed( jillcoin_id(db), jill, feed ); + + enable_fees(); + + // Alice and Bob create some coins + borrow( alice_id, _izzy( 200), _core( 60000) ); + borrow( bob_id, _jill(2000), _core(180000) ); + + // Alice and Bob place orders which match + create_sell_order( alice_id, _izzy(100), _jill(300) ); // Alice is willing to sell her Izzy's for 3 Jill + create_sell_order( bob_id, _jill(700), _izzy(200) ); // Bob is buying up to 200 Izzy's for up to 3.5 Jill + + // 100 Izzys and 300 Jills are matched, so the fees should be + // 1 Izzy (1%) and 6 Jill (2%). + + auto claim_fees = [&]( account_id_type issuer, asset amount_to_claim ) + { + asset_claim_fees_operation claim_op; + claim_op.issuer = issuer; + claim_op.amount_to_claim = amount_to_claim; + signed_transaction tx; + tx.operations.push_back( claim_op ); + db.current_fee_schedule().set_fee( tx.operations.back() ); + set_expiration( db, tx ); + fc::ecc::private_key my_pk = (issuer == izzy_id) ? izzy_private_key : jill_private_key; + fc::ecc::private_key your_pk = (issuer == izzy_id) ? jill_private_key : izzy_private_key; + sign( tx, your_pk ); + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, tx ), fc::exception ); + tx.signatures.clear(); + sign( tx, my_pk ); + PUSH_TX( db, tx ); + }; + + { + const asset_object& izzycoin = izzycoin_id(db); + const asset_object& jillcoin = jillcoin_id(db); + + //wdump( (izzycoin)(izzycoin.dynamic_asset_data_id(db))((*izzycoin.bitasset_data_id)(db)) ); + //wdump( (jillcoin)(jillcoin.dynamic_asset_data_id(db))((*jillcoin.bitasset_data_id)(db)) ); + + // check the correct amount of fees has been awarded + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(1).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(6).amount ); + + } + + { + // can't claim before hardfork + GRAPHENE_REQUIRE_THROW( claim_fees( izzy_id, _izzy(1) ), fc::exception ); + generate_blocks( HARDFORK_413_TIME ); + while( db.head_block_time() <= HARDFORK_413_TIME ) + { + generate_block(); + } + } + + { + const asset_object& izzycoin = izzycoin_id(db); + const asset_object& jillcoin = jillcoin_id(db); + + // can't claim more than balance + GRAPHENE_REQUIRE_THROW( claim_fees( izzy_id, _izzy(1) + izzy_satoshi ), fc::exception ); + GRAPHENE_REQUIRE_THROW( claim_fees( jill_id, _jill(6) + jill_satoshi ), fc::exception ); + + // can't claim asset that doesn't belong to you + GRAPHENE_REQUIRE_THROW( claim_fees( jill_id, izzy_satoshi ), fc::exception ); + GRAPHENE_REQUIRE_THROW( claim_fees( izzy_id, jill_satoshi ), fc::exception ); + + // can claim asset in one go + claim_fees( izzy_id, _izzy(1) ); + GRAPHENE_REQUIRE_THROW( claim_fees( izzy_id, izzy_satoshi ), fc::exception ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(0).amount ); + + // can claim in multiple goes + claim_fees( jill_id, _jill(4) ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(2).amount ); + GRAPHENE_REQUIRE_THROW( claim_fees( jill_id, _jill(2) + jill_satoshi ), fc::exception ); + claim_fees( jill_id, _jill(2) ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(0).amount ); + } + } + FC_LOG_AND_RETHROW() +} /////////////////////////////////////////////////////////////// // cashback_test infrastructure // From 7c9d4584b88bbfdd9505d450b15a41a9338c0c1f Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 15:29:00 -0400 Subject: [PATCH 25/32] operation_tests2.cpp: Don't use real time for balance_object_test starting_time, breakage revealed by #427 --- tests/tests/operation_tests2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ecf4a1ad09..a799d7c988 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -1037,8 +1037,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) fc::temp_directory td( graphene::utilities::temp_directory_path() ); genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1}); genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1}); - auto starting_time = time_point_sec((time_point::now().sec_since_epoch() / GRAPHENE_DEFAULT_BLOCK_INTERVAL + 1) * - GRAPHENE_DEFAULT_BLOCK_INTERVAL); + fc::time_point_sec starting_time = genesis_state.initial_timestamp + 3000; auto n_key = generate_private_key("n"); auto x_key = generate_private_key("x"); From 28eddf1b6fd6378054a7500e94d4877c2cdcc965 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 15:37:17 -0400 Subject: [PATCH 26/32] block_tests.cpp: Fix generate_empty_blocks not working correctly when last_irreversible_block_num skipped over 200 Revealed by #427, related to #407 --- tests/tests/block_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index f61245837a..96e8d3938b 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) { database db; db.open(data_dir.path(), []{return genesis_state_type();}); - BOOST_CHECK_EQUAL( db.head_block_num(), 200 ); + BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num() ); b = cutoff_block; for( uint32_t i = 0; i < 200; ++i ) { @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) //BOOST_CHECK( cur_witness != prev_witness ); b = db.generate_block(db.get_slot_time(1), cur_witness, init_account_priv_key, database::skip_nothing); } - BOOST_CHECK_EQUAL( db.head_block_num(), 400 ); + BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num()+200 ); } } catch (fc::exception& e) { edump((e.to_detail_string())); From a126520fa3224203eee117150691e5249feefa3b Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 09:32:28 -0400 Subject: [PATCH 27/32] HARDFORK Allow creation of sub-assets #409 --- libraries/chain/asset_evaluator.cpp | 36 +++++++++++++------ .../chain/include/graphene/chain/hardfork.hpp | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 03e07e662b..0d8f299f95 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -45,20 +45,36 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o for( auto id : op.common_options.blacklist_authorities ) d.get_object(id); - auto& asset_indx = db().get_index_type().indices().get(); + auto& asset_indx = d.get_index_type().indices().get(); auto asset_symbol_itr = asset_indx.find( op.symbol ); FC_ASSERT( asset_symbol_itr == asset_indx.end() ); - auto dotpos = op.symbol.find( '.' ); - if( dotpos != std::string::npos ) { - auto prefix = op.symbol.substr( 0, dotpos ); - auto asset_symbol_itr = asset_indx.find( op.symbol ); - FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered", - ("s",op.symbol)("p",prefix) ); - FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}", - ("s",op.symbol)("p",prefix)("i", op.issuer(d).name) ); + if( d.head_block_time() <= HARDFORK_409_TIME ) + { + auto dotpos = op.symbol.find( '.' ); + if( dotpos != std::string::npos ) + { + auto prefix = op.symbol.substr( 0, dotpos ); + auto asset_symbol_itr = asset_indx.find( op.symbol ); + FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered", + ("s",op.symbol)("p",prefix) ); + FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}", + ("s",op.symbol)("p",prefix)("i", op.issuer(d).name) ); + } + } + else + { + auto dotpos = op.symbol.rfind( '.' ); + if( dotpos != std::string::npos ) + { + auto prefix = op.symbol.substr( 0, dotpos ); + auto asset_symbol_itr = asset_indx.find( prefix ); + FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered", + ("s",op.symbol)("p",prefix) ); + FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}", + ("s",op.symbol)("p",prefix)("i", op.issuer(d).name) ); + } } - core_fee_paid -= core_fee_paid.value/2; diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index 503e5f0b1c..1417855d0a 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -22,4 +22,5 @@ #define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 )) #define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 )) +#define HARDFORK_409_TIME (fc::time_point_sec( 1446652800 )) #define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 )) From f72ed2f5321bd8b56ffbccf28c88e77a3008ffac Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sat, 31 Oct 2015 14:50:11 -0400 Subject: [PATCH 28/32] uia_tests.cpp: Implement asset_name_test #409 --- tests/common/database_fixture.cpp | 2 ++ tests/tests/uia_tests.cpp | 47 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 676c53b55e..f7431f40f1 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -501,7 +501,9 @@ const asset_object& database_fixture::create_user_issued_asset( const string& na creator.common_options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; creator.common_options.flags = flags; creator.common_options.issuer_permissions = flags; + trx.operations.clear(); trx.operations.push_back(std::move(creator)); + set_expiration( db, trx ); trx.validate(); processed_transaction ptx = db.push_transaction(trx, ~0); trx.operations.clear(); diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 41cda68fca..0a7cf7781b 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -414,5 +414,52 @@ BOOST_AUTO_TEST_CASE( transfer_restricted_test ) } } +BOOST_AUTO_TEST_CASE( asset_name_test ) +{ + try + { + ACTORS( (alice)(bob) ); + + auto has_asset = [&]( std::string symbol ) -> bool + { + const auto& assets_by_symbol = db.get_index_type().indices().get(); + return assets_by_symbol.find( symbol ) != assets_by_symbol.end(); + }; + + // Alice creates asset "ALPHA" + BOOST_CHECK( !has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + create_user_issued_asset( "ALPHA", alice_id(db), 0 ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + + // Nobody can create another asset named ALPHA + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", bob_id(db), 0 ), fc::exception ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA", alice_id(db), 0 ), fc::exception ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + + // Bob can't create ALPHA.ONE + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bob_id(db), 0 ), fc::exception ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + if( db.head_block_time() <= HARDFORK_409_TIME ) + { + // Alice can't create ALPHA.ONE before hardfork + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", alice_id(db), 0 ), fc::exception ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + generate_blocks( HARDFORK_409_TIME ); + generate_block(); + // Bob can't create ALPHA.ONE after hardfork + GRAPHENE_REQUIRE_THROW( create_user_issued_asset( "ALPHA.ONE", bob_id(db), 0 ), fc::exception ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( !has_asset("ALPHA.ONE") ); + } + // Alice can create it + create_user_issued_asset( "ALPHA.ONE", alice_id(db), 0 ); + BOOST_CHECK( has_asset("ALPHA") ); BOOST_CHECK( has_asset("ALPHA.ONE") ); + } + catch(fc::exception& e) + { + edump((e.to_detail_string())); + throw; + } +} BOOST_AUTO_TEST_SUITE_END() From 55fef1b1616377e552a1f1aecca77ef9115ce18f Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 30 Oct 2015 09:57:45 -0400 Subject: [PATCH 29/32] db_update.cpp: Don't clear expired feeds for non-market-issued assets #410 --- libraries/chain/db_update.cpp | 10 ++++++---- .../chain/include/graphene/chain/asset_object.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 1fc7fc83bb..2b6ba2e72e 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -366,11 +366,13 @@ void database::clear_expired_orders() void database::update_expired_feeds() { - auto& asset_idx = get_index_type().indices(); - for( const asset_object& a : asset_idx ) + auto& asset_idx = get_index_type().indices().get(); + auto itr = asset_idx.lower_bound( true /** market issued */ ); + while( itr != asset_idx.end() ) { - if( !a.is_market_issued() ) - continue; + const asset_object& a = *itr; + ++itr; + assert( a.is_market_issued() ); const asset_bitasset_data_object& b = a.bitasset_data(*this); if( b.feed_is_expired(head_block_time()) ) diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 4496fe0355..1661fa7fac 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -213,7 +213,6 @@ namespace graphene { namespace chain { void update_median_feeds(time_point_sec current_time); }; - struct by_feed_expiration; typedef multi_index_container< asset_bitasset_data_object, @@ -227,17 +226,19 @@ namespace graphene { namespace chain { typedef flat_index asset_bitasset_data_index; struct by_symbol; + struct by_type; typedef multi_index_container< asset_object, indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, - ordered_unique< tag, member > + ordered_unique< tag, member >, + ordered_non_unique< tag, const_mem_fun > > > asset_object_multi_index_type; typedef generic_index asset_index; - } } // graphene::chain + FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_object, (graphene::db::object), (current_supply)(confidential_supply)(accumulated_fees)(fee_pool) ) @@ -260,4 +261,3 @@ FC_REFLECT_DERIVED( graphene::chain::asset_object, (graphene::db::object), (dynamic_asset_data_id) (bitasset_data_id) ) - From d588ac987ce140e7f35911b06e8bc4d4dc9e472d Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 28 Oct 2015 11:43:56 -0400 Subject: [PATCH 30/32] operation_tests2.cpp: Implement zero_second_vbo test for issue #390 --- tests/tests/operation_tests2.cpp | 116 +++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ee05ffd927..730b6b847b 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1207,6 +1208,121 @@ BOOST_AUTO_TEST_CASE(transfer_with_memo) { } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE(zero_second_vbo) +{ + try + { + ACTOR(alice); + // don't pay witnesses so we have some worker budget to work with + + transfer(account_id_type(), alice_id, asset(int64_t(100000) * 1100 * 1000 * 1000)); + { + asset_reserve_operation op; + op.payer = alice_id; + op.amount_to_reserve = asset(int64_t(100000) * 1000 * 1000 * 1000); + transaction tx; + tx.operations.push_back( op ); + set_expiration( db, tx ); + db.push_transaction( tx, database::skip_authority_check | database::skip_tapos_check | database::skip_transaction_signatures ); + } + enable_fees(); + upgrade_to_lifetime_member(alice_id); + generate_block(); + + auto check_vesting_1b = [&](vesting_balance_id_type vbid) + { + // this function checks that Alice can't draw any right now, + // but one block later, she can withdraw it all. + + vesting_balance_withdraw_operation withdraw_op; + withdraw_op.vesting_balance = vbid; + withdraw_op.owner = alice_id; + withdraw_op.amount = asset(1); + + signed_transaction withdraw_tx; + withdraw_tx.operations.push_back( withdraw_op ); + sign(withdraw_tx, alice_private_key); + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, withdraw_tx ), fc::exception ); + + generate_block(); + withdraw_tx = signed_transaction(); + withdraw_op.amount = asset(500); + withdraw_tx.operations.push_back( withdraw_op ); + set_expiration( db, withdraw_tx ); + sign(withdraw_tx, alice_private_key); + PUSH_TX( db, withdraw_tx ); + }; + + // This block creates a zero-second VBO with a vesting_balance_create_operation. + { + cdd_vesting_policy_initializer pinit; + pinit.vesting_seconds = 0; + + vesting_balance_create_operation create_op; + create_op.creator = alice_id; + create_op.owner = alice_id; + create_op.amount = asset(500); + create_op.policy = pinit; + + signed_transaction create_tx; + create_tx.operations.push_back( create_op ); + set_expiration( db, create_tx ); + sign(create_tx, alice_private_key); + + processed_transaction ptx = PUSH_TX( db, create_tx ); + vesting_balance_id_type vbid = ptx.operation_results[0].get(); + check_vesting_1b( vbid ); + } + + // This block creates a zero-second VBO with a worker_create_operation. + { + worker_create_operation create_op; + create_op.owner = alice_id; + create_op.work_begin_date = db.head_block_time(); + create_op.work_end_date = db.head_block_time() + fc::days(1000); + create_op.daily_pay = share_type( 10000 ); + create_op.name = "alice"; + create_op.url = ""; + create_op.initializer = vesting_balance_worker_initializer(0); + signed_transaction create_tx; + create_tx.operations.push_back(create_op); + set_expiration( db, create_tx ); + sign(create_tx, alice_private_key); + processed_transaction ptx = PUSH_TX( db, create_tx ); + worker_id_type wid = ptx.operation_results[0].get(); + + // vote it in + account_update_operation vote_op; + vote_op.account = alice_id; + vote_op.new_options = alice_id(db).options; + vote_op.new_options->votes.insert(wid(db).vote_for); + signed_transaction vote_tx; + vote_tx.operations.push_back(vote_op); + set_expiration( db, vote_tx ); + sign( vote_tx, alice_private_key ); + PUSH_TX( db, vote_tx ); + + // vote it in, wait for one maint. for vote to take effect + vesting_balance_id_type vbid = wid(db).worker.get().balance; + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + generate_block(); + // wait for another maint. for worker to be paid + generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(0) ); + generate_block(); + BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(10000) ); + + /* + db.get_index_type< simple_index >().inspect_all_objects( + [&](const object& o) + { + ilog( "budget: ${brec}", ("brec", static_cast(o)) ); + }); + */ + } + } FC_LOG_AND_RETHROW() +} + // TODO: Write linear VBO tests BOOST_AUTO_TEST_SUITE_END() From e845def98c096670473d46845003173c148f6cfc Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Sun, 1 Nov 2015 11:34:26 -0500 Subject: [PATCH 31/32] Add hardfork logic to transfer_whitelist_uia test #419 --- tests/tests/uia_tests.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index 75a401aa0c..ae241fa483 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -268,8 +268,16 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia ) op.amount = advanced.amount(50); trx.operations.back() = op; //Fail because nathan is blacklisted - GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_from_account_not_whitelisted ); - + if( db.head_block_time() <= HARDFORK_419_TIME ) + { + // before the hardfork time, it fails because the whitelist check fails + GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_from_account_not_whitelisted ); + } + else + { + // after the hardfork time, it fails because the fees are not in a whitelisted asset + GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception ); + } BOOST_TEST_MESSAGE( "Attempting to burn from nathan after blacklisting, should fail" ); asset_reserve_operation burn; From 75d1bb39a384ed5b0cfeebe52183858d0e5cf6c4 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Mon, 2 Nov 2015 10:22:46 -0500 Subject: [PATCH 32/32] Re-bump fc after inadvertently reverted by #367 --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index 6495004302..1e10d3dc47 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 6495004302239ae0c775f05a0e78780c3b189502 +Subproject commit 1e10d3dc4774426e735eb6aabd8e0aa43799fe30