From 391b0bec45187f55c1bb06bc8cfdac3e9c6b6ef1 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Mon, 29 Jun 2015 17:50:27 -0400 Subject: [PATCH] Progress #17: Remove GRAPHENE_INITIAL_SUPPLY The INITIAL_SUPPLY macro is generally not useful, and there's no good way to fulfill the promise it creates. By removing it, I can skip the scaling on the genesis values. Now, if there is an allocation at genesis, the supply is determined by that allocation. Otherwise, the supply is GRAPHENE_MAX_SHARE_SUPPLY and it all belongs to GRAPHENE_COMMITTEE_ACCOUNT. Also, remove one of the redundant and confusing MAX_SUPPLY macros and unify the usage to always be GRAPHENE_MAX_SHARE_SUPPLY. --- libraries/chain/asset_object.cpp | 2 +- libraries/chain/db_init.cpp | 29 ++++++++----------- .../chain/include/graphene/chain/config.hpp | 4 +-- libraries/chain/operations.cpp | 6 ++-- tests/benchmarks/genesis_allocation.cpp | 6 ++-- tests/tests/operation_tests2.cpp | 14 ++++----- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index d72da15b..db855d9f 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -164,7 +164,7 @@ asset asset_object::amount_from_string(string amount_string) const satoshis += std::stoll( rhs ); } - FC_ASSERT( satoshis <= GRAPHENE_BLOCKCHAIN_MAX_SHARES ); + FC_ASSERT( satoshis <= GRAPHENE_MAX_SHARE_SUPPLY ); if( negative_found ) satoshis *= -1; diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 3cd0f519..8c3bc627 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -166,8 +166,8 @@ void database::init_genesis(const genesis_state_type& genesis_state) create( [&null_private_key](key_object& k) { k.key_data = public_key_type(null_private_key.get_public_key()); }); - create( [](account_balance_object& b) { - b.balance = GRAPHENE_INITIAL_SUPPLY; + create([](account_balance_object& b) { + b.balance = GRAPHENE_MAX_SHARE_SUPPLY; }); const account_object& committee_account = create( [&](account_object& n) { @@ -223,13 +223,13 @@ void database::init_genesis(const genesis_state_type& genesis_state) // Create core asset const asset_dynamic_data_object& dyn_asset = - create( [&]( asset_dynamic_data_object& a ) { - a.current_supply = GRAPHENE_INITIAL_SUPPLY; + create([&](asset_dynamic_data_object& a) { + a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY; }); const asset_object& core_asset = create( [&]( asset_object& a ) { a.symbol = GRAPHENE_SYMBOL; - a.options.max_supply = GRAPHENE_INITIAL_SUPPLY; + a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; a.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS; a.options.flags = 0; a.options.issuer_permissions = 0; @@ -258,31 +258,26 @@ void database::init_genesis(const genesis_state_type& genesis_state) }); create([&](block_summary_object&) {}); - // Create genesis balances + // Create initial balances if( !genesis_state.initial_balances.empty() ) { share_type total_allocation = 0; - // Because we do scaling on balances, the final sum may not quite reach total_allocation - // Store the actual number of shares created here - share_type final_allocation = 0; for( const auto& handout : genesis_state.initial_balances ) total_allocation += handout.amount; const auto& asset_idx = get_index_type().indices().get(); for( const auto& handout : genesis_state.initial_balances ) { - final_allocation += create([&handout,&asset_idx,total_allocation](balance_object& b) { + create([&handout,&asset_idx,total_allocation](balance_object& b) { b.balance = asset(handout.amount, asset_idx.find(handout.asset_symbol)->get_id()); - b.balance.amount = ((fc::uint128(b.balance.amount.value) * GRAPHENE_INITIAL_SUPPLY)/total_allocation.value).to_uint64(); b.owner = handout.owner; - }).balance.amount; + }); } - assert(final_allocation <= dyn_asset.current_supply); - if( final_allocation < dyn_asset.current_supply ) - modify(dyn_asset, [final_allocation](asset_dynamic_data_object& d) { - d.current_supply = final_allocation; - }); + modify(dyn_asset, [total_allocation](asset_dynamic_data_object& d) { + d.current_supply = total_allocation; + }); + adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{})); } // Create initial accounts diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index b7b2c3b2..6e56ecbf 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -28,7 +28,7 @@ #define GRAPHENE_MAX_ASSET_NAME_LENGTH 127 -#define GRAPHENE_MAX_SHARE_SUPPLY int64_t(1000000000000ll) +#define GRAPHENE_MAX_SHARE_SUPPLY int64_t(1000000000000000ll) #define GRAPHENE_MAX_PAY_RATE 10000 /* 100% */ #define GRAPHENE_MAX_SIG_CHECK_DEPTH 2 #define GRAPHENE_MIN_WITNESS_COUNT 10 @@ -49,10 +49,8 @@ #define GRAPHENE_MIN_BLOCK_SIZE_LIMIT (GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT*5) // 5 transactions per block #define GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT (GRAPHENE_MAX_BLOCK_INTERVAL * 5) // 5 transactions per block -#define GRAPHENE_BLOCKCHAIN_MAX_SHARES (1000*1000*int64_t(1000)*1000*int64_t(1000)) #define GRAPHENE_BLOCKCHAIN_PRECISION 100000 #define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS 5 -#define GRAPHENE_INITIAL_SUPPLY GRAPHENE_BLOCKCHAIN_MAX_SHARES #define GRAPHENE_DEFAULT_TRANSFER_FEE (1*GRAPHENE_BLOCKCHAIN_PRECISION) #define GRAPHENE_MAX_INSTANCE_ID (uint64_t(-1)>>16) /** percentage fields are fixed point with a denominator of 10,000 */ diff --git a/libraries/chain/operations.cpp b/libraries/chain/operations.cpp index 3b598cb3..983b6174 100644 --- a/libraries/chain/operations.cpp +++ b/libraries/chain/operations.cpp @@ -351,7 +351,7 @@ void asset_burn_operation::get_required_auth(flat_set& active_a void asset_burn_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); - FC_ASSERT( amount_to_burn.amount.value <= GRAPHENE_BLOCKCHAIN_MAX_SHARES ); + FC_ASSERT( amount_to_burn.amount.value <= GRAPHENE_MAX_SHARE_SUPPLY ); FC_ASSERT( amount_to_burn.amount.value > 0 ); } @@ -368,7 +368,7 @@ void asset_issue_operation::get_required_auth(flat_set& active_ void asset_issue_operation::validate()const { FC_ASSERT( fee.amount >= 0 ); - FC_ASSERT( asset_to_issue.amount.value <= GRAPHENE_BLOCKCHAIN_MAX_SHARES ); + FC_ASSERT( asset_to_issue.amount.value <= GRAPHENE_MAX_SHARE_SUPPLY ); FC_ASSERT( asset_to_issue.amount.value > 0 ); FC_ASSERT( asset_to_issue.asset_id != 0 ); } @@ -849,7 +849,7 @@ void worker_create_operation::validate() const FC_ASSERT(fee.amount >= 0); FC_ASSERT(work_end_date > work_begin_date); FC_ASSERT(daily_pay > 0); - FC_ASSERT(daily_pay < GRAPHENE_BLOCKCHAIN_MAX_SHARES); + FC_ASSERT(daily_pay < GRAPHENE_MAX_SHARE_SUPPLY); FC_ASSERT(name.size() < GRAPHENE_MAX_WORKER_NAME_LENGTH ); FC_ASSERT(url.size() < GRAPHENE_MAX_URL_LENGTH ); } diff --git a/tests/benchmarks/genesis_allocation.cpp b/tests/benchmarks/genesis_allocation.cpp index 9bc63769..f01d7955 100644 --- a/tests/benchmarks/genesis_allocation.cpp +++ b/tests/benchmarks/genesis_allocation.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) db.open(data_dir.path(), genesis_state); for( int i = 11; i < account_count + 11; ++i) - BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_INITIAL_SUPPLY / account_count); + BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_MAX_SHARE_SUPPLY / account_count); fc::time_point start_time = fc::time_point::now(); db.close(); @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) ilog("Opened database in ${t} milliseconds.", ("t", (fc::time_point::now() - start_time).count() / 1000)); for( int i = 11; i < account_count + 11; ++i) - BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_INITIAL_SUPPLY / account_count); + BOOST_CHECK(db.get_balance(account_id_type(i), asset_id_type()).amount == GRAPHENE_MAX_SHARE_SUPPLY / account_count); int blocks_out = 0; auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); @@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) ilog("Replayed database in ${t} milliseconds.", ("t", (fc::time_point::now() - start_time).count() / 1000)); for( int i = 0; i < blocks_to_produce; ++i ) - BOOST_CHECK(db.get_balance(account_id_type(i + 11), asset_id_type()).amount == GRAPHENE_INITIAL_SUPPLY / account_count - 2); + BOOST_CHECK(db.get_balance(account_id_type(i + 11), asset_id_type()).amount == GRAPHENE_MAX_SHARE_SUPPLY / account_count - 2); } } catch(fc::exception& e) { diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 064a5517..c541f44f 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -579,7 +579,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) { asset_burn_operation op; op.payer = account_id_type(); - op.amount_to_burn = asset(GRAPHENE_INITIAL_SUPPLY/2); + op.amount_to_burn = asset(GRAPHENE_MAX_SHARE_SUPPLY/2); trx.operations.push_back(op); PUSH_TX( db, trx, ~0 ); trx.clear(); @@ -692,7 +692,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test ) { asset_burn_operation op; op.payer = account_id_type(); - op.amount_to_burn = asset(GRAPHENE_INITIAL_SUPPLY/2); + op.amount_to_burn = asset(GRAPHENE_MAX_SHARE_SUPPLY/2); trx.operations.push_back(op); PUSH_TX( db, trx, ~0 ); trx.clear(); @@ -766,7 +766,7 @@ BOOST_AUTO_TEST_CASE( burn_worker_test ) // refund some asset to fill up the pool asset_burn_operation op; op.payer = account_id_type(); - op.amount_to_burn = asset(GRAPHENE_INITIAL_SUPPLY/2); + op.amount_to_burn = asset(GRAPHENE_MAX_SHARE_SUPPLY/2); trx.operations.push_back(op); PUSH_TX( db, trx, ~0 ); trx.clear(); @@ -954,12 +954,12 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) db.open(td.path(), genesis_state); const balance_object& balance = *db.get_index_type().indices().find(balance_id_type()); - BOOST_CHECK_EQUAL(balance.balance.amount.value, GRAPHENE_INITIAL_SUPPLY / 2); - BOOST_CHECK_EQUAL(db.get_index_type().indices().find(balance_id_type())->balance.amount.value, GRAPHENE_INITIAL_SUPPLY / 2); + BOOST_CHECK_EQUAL(balance.balance.amount.value, 1); + BOOST_CHECK_EQUAL(db.get_index_type().indices().find(balance_id_type())->balance.amount.value, 1); balance_claim_operation op; op.deposit_to_account = db.get_index_type().indices().get().find("n")->get_id(); - op.total_claimed = asset(GRAPHENE_INITIAL_SUPPLY / 2); + op.total_claimed = asset(1); op.owners.insert(genesis_state.initial_balances.back().owner); trx.operations = {op}; trx.sign(*op.owners.begin(), generate_private_key("n")); @@ -975,7 +975,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) db.push_transaction(trx); // Not using fixture's get_balance() here because it uses fixture's db, not my override - BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, GRAPHENE_INITIAL_SUPPLY / 2); + BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, 1); } FC_LOG_AND_RETHROW() } // TODO: Write linear VBO tests