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.
This commit is contained in:
parent
873cf4dcf8
commit
391b0bec45
6 changed files with 27 additions and 34 deletions
|
|
@ -164,7 +164,7 @@ asset asset_object::amount_from_string(string amount_string) const
|
||||||
satoshis += std::stoll( rhs );
|
satoshis += std::stoll( rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
FC_ASSERT( satoshis <= GRAPHENE_BLOCKCHAIN_MAX_SHARES );
|
FC_ASSERT( satoshis <= GRAPHENE_MAX_SHARE_SUPPLY );
|
||||||
|
|
||||||
if( negative_found )
|
if( negative_found )
|
||||||
satoshis *= -1;
|
satoshis *= -1;
|
||||||
|
|
|
||||||
|
|
@ -166,8 +166,8 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
create<key_object>( [&null_private_key](key_object& k) {
|
create<key_object>( [&null_private_key](key_object& k) {
|
||||||
k.key_data = public_key_type(null_private_key.get_public_key());
|
k.key_data = public_key_type(null_private_key.get_public_key());
|
||||||
});
|
});
|
||||||
create<account_balance_object>( [](account_balance_object& b) {
|
create<account_balance_object>([](account_balance_object& b) {
|
||||||
b.balance = GRAPHENE_INITIAL_SUPPLY;
|
b.balance = GRAPHENE_MAX_SHARE_SUPPLY;
|
||||||
});
|
});
|
||||||
const account_object& committee_account =
|
const account_object& committee_account =
|
||||||
create<account_object>( [&](account_object& n) {
|
create<account_object>( [&](account_object& n) {
|
||||||
|
|
@ -223,13 +223,13 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
|
|
||||||
// Create core asset
|
// Create core asset
|
||||||
const asset_dynamic_data_object& dyn_asset =
|
const asset_dynamic_data_object& dyn_asset =
|
||||||
create<asset_dynamic_data_object>( [&]( asset_dynamic_data_object& a ) {
|
create<asset_dynamic_data_object>([&](asset_dynamic_data_object& a) {
|
||||||
a.current_supply = GRAPHENE_INITIAL_SUPPLY;
|
a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY;
|
||||||
});
|
});
|
||||||
const asset_object& core_asset =
|
const asset_object& core_asset =
|
||||||
create<asset_object>( [&]( asset_object& a ) {
|
create<asset_object>( [&]( asset_object& a ) {
|
||||||
a.symbol = GRAPHENE_SYMBOL;
|
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.precision = GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS;
|
||||||
a.options.flags = 0;
|
a.options.flags = 0;
|
||||||
a.options.issuer_permissions = 0;
|
a.options.issuer_permissions = 0;
|
||||||
|
|
@ -258,31 +258,26 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
||||||
});
|
});
|
||||||
create<block_summary_object>([&](block_summary_object&) {});
|
create<block_summary_object>([&](block_summary_object&) {});
|
||||||
|
|
||||||
// Create genesis balances
|
// Create initial balances
|
||||||
if( !genesis_state.initial_balances.empty() )
|
if( !genesis_state.initial_balances.empty() )
|
||||||
{
|
{
|
||||||
share_type total_allocation = 0;
|
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 )
|
for( const auto& handout : genesis_state.initial_balances )
|
||||||
total_allocation += handout.amount;
|
total_allocation += handout.amount;
|
||||||
|
|
||||||
const auto& asset_idx = get_index_type<asset_index>().indices().get<by_symbol>();
|
const auto& asset_idx = get_index_type<asset_index>().indices().get<by_symbol>();
|
||||||
for( const auto& handout : genesis_state.initial_balances )
|
for( const auto& handout : genesis_state.initial_balances )
|
||||||
{
|
{
|
||||||
final_allocation += create<balance_object>([&handout,&asset_idx,total_allocation](balance_object& b) {
|
create<balance_object>([&handout,&asset_idx,total_allocation](balance_object& b) {
|
||||||
b.balance = asset(handout.amount, asset_idx.find(handout.asset_symbol)->get_id());
|
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;
|
b.owner = handout.owner;
|
||||||
}).balance.amount;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(final_allocation <= dyn_asset.current_supply);
|
modify(dyn_asset, [total_allocation](asset_dynamic_data_object& d) {
|
||||||
if( final_allocation < dyn_asset.current_supply )
|
d.current_supply = total_allocation;
|
||||||
modify(dyn_asset, [final_allocation](asset_dynamic_data_object& d) {
|
});
|
||||||
d.current_supply = final_allocation;
|
adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create initial accounts
|
// Create initial accounts
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#define GRAPHENE_MAX_ASSET_NAME_LENGTH 127
|
#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_PAY_RATE 10000 /* 100% */
|
||||||
#define GRAPHENE_MAX_SIG_CHECK_DEPTH 2
|
#define GRAPHENE_MAX_SIG_CHECK_DEPTH 2
|
||||||
#define GRAPHENE_MIN_WITNESS_COUNT 10
|
#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_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_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 100000
|
||||||
#define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS 5
|
#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_DEFAULT_TRANSFER_FEE (1*GRAPHENE_BLOCKCHAIN_PRECISION)
|
||||||
#define GRAPHENE_MAX_INSTANCE_ID (uint64_t(-1)>>16)
|
#define GRAPHENE_MAX_INSTANCE_ID (uint64_t(-1)>>16)
|
||||||
/** percentage fields are fixed point with a denominator of 10,000 */
|
/** percentage fields are fixed point with a denominator of 10,000 */
|
||||||
|
|
|
||||||
|
|
@ -351,7 +351,7 @@ void asset_burn_operation::get_required_auth(flat_set<account_id_type>& active_a
|
||||||
void asset_burn_operation::validate()const
|
void asset_burn_operation::validate()const
|
||||||
{
|
{
|
||||||
FC_ASSERT( fee.amount >= 0 );
|
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 );
|
FC_ASSERT( amount_to_burn.amount.value > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -368,7 +368,7 @@ void asset_issue_operation::get_required_auth(flat_set<account_id_type>& active_
|
||||||
void asset_issue_operation::validate()const
|
void asset_issue_operation::validate()const
|
||||||
{
|
{
|
||||||
FC_ASSERT( fee.amount >= 0 );
|
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.amount.value > 0 );
|
||||||
FC_ASSERT( asset_to_issue.asset_id != 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(fee.amount >= 0);
|
||||||
FC_ASSERT(work_end_date > work_begin_date);
|
FC_ASSERT(work_end_date > work_begin_date);
|
||||||
FC_ASSERT(daily_pay > 0);
|
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(name.size() < GRAPHENE_MAX_WORKER_NAME_LENGTH );
|
||||||
FC_ASSERT(url.size() < GRAPHENE_MAX_URL_LENGTH );
|
FC_ASSERT(url.size() < GRAPHENE_MAX_URL_LENGTH );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench )
|
||||||
db.open(data_dir.path(), genesis_state);
|
db.open(data_dir.path(), genesis_state);
|
||||||
|
|
||||||
for( int i = 11; i < account_count + 11; ++i)
|
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();
|
fc::time_point start_time = fc::time_point::now();
|
||||||
db.close();
|
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));
|
ilog("Opened database in ${t} milliseconds.", ("t", (fc::time_point::now() - start_time).count() / 1000));
|
||||||
|
|
||||||
for( int i = 11; i < account_count + 11; ++i)
|
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;
|
int blocks_out = 0;
|
||||||
auto delegate_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
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));
|
ilog("Replayed database in ${t} milliseconds.", ("t", (fc::time_point::now() - start_time).count() / 1000));
|
||||||
|
|
||||||
for( int i = 0; i < blocks_to_produce; ++i )
|
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) {
|
} catch(fc::exception& e) {
|
||||||
|
|
|
||||||
|
|
@ -579,7 +579,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test )
|
||||||
{
|
{
|
||||||
asset_burn_operation op;
|
asset_burn_operation op;
|
||||||
op.payer = account_id_type();
|
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);
|
trx.operations.push_back(op);
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
trx.clear();
|
trx.clear();
|
||||||
|
|
@ -692,7 +692,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test )
|
||||||
{
|
{
|
||||||
asset_burn_operation op;
|
asset_burn_operation op;
|
||||||
op.payer = account_id_type();
|
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);
|
trx.operations.push_back(op);
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
trx.clear();
|
trx.clear();
|
||||||
|
|
@ -766,7 +766,7 @@ BOOST_AUTO_TEST_CASE( burn_worker_test )
|
||||||
// refund some asset to fill up the pool
|
// refund some asset to fill up the pool
|
||||||
asset_burn_operation op;
|
asset_burn_operation op;
|
||||||
op.payer = account_id_type();
|
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);
|
trx.operations.push_back(op);
|
||||||
PUSH_TX( db, trx, ~0 );
|
PUSH_TX( db, trx, ~0 );
|
||||||
trx.clear();
|
trx.clear();
|
||||||
|
|
@ -954,12 +954,12 @@ BOOST_AUTO_TEST_CASE( balance_object_test )
|
||||||
|
|
||||||
db.open(td.path(), genesis_state);
|
db.open(td.path(), genesis_state);
|
||||||
const balance_object& balance = *db.get_index_type<balance_index>().indices().find(balance_id_type());
|
const balance_object& balance = *db.get_index_type<balance_index>().indices().find(balance_id_type());
|
||||||
BOOST_CHECK_EQUAL(balance.balance.amount.value, GRAPHENE_INITIAL_SUPPLY / 2);
|
BOOST_CHECK_EQUAL(balance.balance.amount.value, 1);
|
||||||
BOOST_CHECK_EQUAL(db.get_index_type<balance_index>().indices().find(balance_id_type())->balance.amount.value, GRAPHENE_INITIAL_SUPPLY / 2);
|
BOOST_CHECK_EQUAL(db.get_index_type<balance_index>().indices().find(balance_id_type())->balance.amount.value, 1);
|
||||||
|
|
||||||
balance_claim_operation op;
|
balance_claim_operation op;
|
||||||
op.deposit_to_account = db.get_index_type<account_index>().indices().get<by_name>().find("n")->get_id();
|
op.deposit_to_account = db.get_index_type<account_index>().indices().get<by_name>().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);
|
op.owners.insert(genesis_state.initial_balances.back().owner);
|
||||||
trx.operations = {op};
|
trx.operations = {op};
|
||||||
trx.sign(*op.owners.begin(), generate_private_key("n"));
|
trx.sign(*op.owners.begin(), generate_private_key("n"));
|
||||||
|
|
@ -975,7 +975,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test )
|
||||||
db.push_transaction(trx);
|
db.push_transaction(trx);
|
||||||
|
|
||||||
// Not using fixture's get_balance() here because it uses fixture's db, not my override
|
// 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() }
|
} FC_LOG_AND_RETHROW() }
|
||||||
|
|
||||||
// TODO: Write linear VBO tests
|
// TODO: Write linear VBO tests
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue