Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes for 4.0 #2134

Merged
merged 14 commits into from
Apr 8, 2020
Merged
14 changes: 0 additions & 14 deletions libraries/chain/committee_member_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ void_result committee_member_update_global_parameters_evaluator::do_evaluate(
{ try {
FC_ASSERT(trx_state->_is_proposed_trx);

auto now = db().head_block_time();
FC_ASSERT( now > HARDFORK_CORE_1468_TIME || !o.new_parameters.extensions.value.updatable_htlc_options.valid(),
"Unable to set HTLC parameters until hardfork." );
if (!HARDFORK_BSIP_40_PASSED( now )) {
FC_ASSERT( !o.new_parameters.extensions.value.custom_authority_options.valid(),
"Unable to set Custom Authority Options until hardfork BSIP 40." );
FC_ASSERT( !o.new_parameters.current_fees->exists<custom_authority_create_operation>(),
"Unable to set Custom Authority operation fees until hardfork BSIP 40." );
FC_ASSERT( !o.new_parameters.current_fees->exists<custom_authority_update_operation>(),
"Unable to set Custom Authority operation fees until hardfork BSIP 40." );
FC_ASSERT( !o.new_parameters.current_fees->exists<custom_authority_delete_operation>(),
"Unable to set Custom Authority operation fees until hardfork BSIP 40." );
}

return void_result();
} FC_CAPTURE_AND_RETHROW( (o) ) }

Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/db_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ vector<authority> database::get_viable_custom_authorities(
else if (rejected_authorities != nullptr)
rejected_authorities->insert(std::make_pair(cust_auth.get().id, std::move(result)));
} catch (fc::exception& e) {
rejected_authorities->insert(std::make_pair(cust_auth.get().id, std::move(e)));
if (rejected_authorities != nullptr)
rejected_authorities->insert(std::make_pair(cust_auth.get().id, std::move(e)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ namespace graphene { namespace chain {
composite_key<custom_authority_object,
member<custom_authority_object, time_point_sec, &custom_authority_object::valid_to>,
member<object, object_id_type, &object::id>
>,
composite_key_compare<std::greater<time_point_sec>, std::less<object_id_type>>
>
>
>
> custom_authority_multi_index_type;
Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
9 changes: 5 additions & 4 deletions libraries/plugins/custom_operations/custom_evaluators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ custom_generic_evaluator::custom_generic_evaluator(database& db, const account_i

vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_map& op)
{
auto &index = _db->get_index_type<account_storage_index>().indices().get<by_account_catalog_key>();
const auto &index = _db->get_index_type<account_storage_index>().indices().get<by_account_catalog_key>();
vector<object_id_type> results;
results.reserve( op.key_values.size() );

if (op.remove)
{
Expand All @@ -61,9 +62,10 @@ vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_
if(itr == index.end())
{
try {
auto created = _db->create<account_storage_object>( [&op, this, &row]( account_storage_object& aso ) {
aso.catalog = op.catalog;
const auto& created = _db->create<account_storage_object>(
[&op, this, &row]( account_storage_object& aso ) {
aso.account = _account;
aso.catalog = op.catalog;
aso.key = row.first;
if(row.second.valid())
aso.value = fc::json::from_string(*row.second);
Expand All @@ -76,7 +78,6 @@ vector<object_id_type> custom_generic_evaluator::do_apply(const account_storage_
{
try {
_db->modify(*itr, [&op, this, &row](account_storage_object &aso) {
aso.key = row.first;
if(row.second.valid())
aso.value = fc::json::from_string(*row.second);
else
Expand Down
17 changes: 17 additions & 0 deletions libraries/protocol/custom_authority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace graphene { namespace protocol {

share_type custom_authority_create_operation::calculate_fee(const fee_parameters_type& k)const {
share_type core_fee_required = k.basic_fee;
// Note: practically the `*` won't cause an integer overflow, because k.price_per_byte is 32 bit
// and the results of pack_size() won't be too big
core_fee_required += k.price_per_byte * (fc::raw::pack_size(restrictions) + fc::raw::pack_size(auth));
return core_fee_required;
}
Expand Down Expand Up @@ -58,6 +60,8 @@ void custom_authority_create_operation::validate()const {

share_type custom_authority_update_operation::calculate_fee(const fee_parameters_type& k)const {
share_type core_fee_required = k.basic_fee;
// Note: practically the `*` won't cause an integer overflow, because k.price_per_byte is 32 bit
// and the results of pack_size() won't be too big
core_fee_required += k.price_per_byte * fc::raw::pack_size(restrictions_to_add);
if (new_auth)
core_fee_required += k.price_per_byte * fc::raw::pack_size(*new_auth);
Expand All @@ -78,6 +82,19 @@ void custom_authority_update_operation::validate()const {
FC_ASSERT(!new_auth->is_impossible(), "Cannot use an impossible authority threshold");
FC_ASSERT(new_auth->address_auths.size() == 0, "Address auth is not supported");
}
FC_ASSERT( new_enabled.valid() || new_valid_from.valid() || new_valid_to.valid() || new_auth.valid()
|| !restrictions_to_remove.empty() || !restrictions_to_add.empty(),
"Must update something" );
}

void custom_authority_delete_operation::validate()const {
FC_ASSERT(fee.amount >= 0, "Fee amount can not be negative");

FC_ASSERT(account != GRAPHENE_TEMP_ACCOUNT
&& account != GRAPHENE_COMMITTEE_ACCOUNT
&& account != GRAPHENE_WITNESS_ACCOUNT
&& account != GRAPHENE_RELAXED_COMMITTEE_ACCOUNT,
"Can not delete custom authority for special accounts");
}

} } // graphene::protocol
4 changes: 2 additions & 2 deletions libraries/protocol/fee_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace graphene { namespace protocol {
fee_schedule fee_schedule::get_default()
{
fee_schedule result;
for( int i = 0; i < fee_parameters().count(); ++i )
for( size_t i = 0; i < fee_parameters().count(); ++i )
{
fee_parameters x; x.set_which(i);
result.parameters.insert(x);
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace graphene { namespace protocol {
{
auto f = calculate_fee( op, core_exchange_rate );
auto f_max = f;
for( int i=0; i<MAX_FEE_STABILIZATION_ITERATION; i++ )
for( size_t i=0; i<MAX_FEE_STABILIZATION_ITERATION; i++ )
{
op.visit( set_fee_visitor( f_max ) );
auto f2 = calculate_fee( op, core_exchange_rate );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace graphene { namespace protocol {
extensions_type extensions;

account_id_type fee_payer()const { return account; }
void validate()const {}
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const { return k.fee; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ namespace graphene { namespace protocol {
* @param sigs a set of public keys
* @param get_active callback function to retrieve active authorities of a given account
* @param get_owner callback function to retrieve owner authorities of a given account
* @param get_custom callback function to retrieve viable custom authorities for a given account and operation
* @param allow_non_immediate_owner whether to allow owner authority of non-immediately
* required accounts to authorize operations
* @param ignore_custom_operation_required_auths See issue #210; whether to ignore the
Expand Down
1 change: 1 addition & 0 deletions libraries/protocol/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ set<public_key_type> signed_transaction::minimize_required_signatures(
uint32_t max_recursion )const
{
set< public_key_type > s = get_required_signatures( chain_id, available_keys, get_active, get_owner,
allow_non_immediate_owner,
ignore_custom_operation_required_auths, max_recursion );
flat_set< public_key_type > result( s.begin(), s.end() );

Expand Down
3 changes: 2 additions & 1 deletion libraries/wallet/wallet_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ namespace graphene { namespace wallet { namespace detail {
void wallet_api_impl::init_prototype_ops()
{
operation op;
for( int t=0; t<op.count(); t++ )
int64_t op_count = op.count();
for( int64_t t=0; t<op_count; t++ )
{
op.set_which( t );
op.visit( op_prototype_visitor(t, _prototype_ops) );
Expand Down
44 changes: 40 additions & 4 deletions tests/tests/authority_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,10 +1885,8 @@ BOOST_AUTO_TEST_CASE( custom_operation_required_auths_before_fork ) {
fund(alice, asset(10000000));
enable_fees();

if (db.head_block_time() >= HARDFORK_CORE_210_TIME) {
wlog("Unable to test custom_operation required auths before fork: hardfork already passed");
return;
}
// Unable to test custom_operation required auths before fork if hardfork already passed
BOOST_REQUIRE(db.head_block_time() < HARDFORK_CORE_210_TIME);

signed_transaction trx;
custom_operation op;
Expand Down Expand Up @@ -2003,6 +2001,44 @@ BOOST_AUTO_TEST_CASE( custom_operation_required_auths_after_fork ) {
}
}

BOOST_FIXTURE_TEST_CASE( owner_delegation_test, database_fixture )
{ try {
ACTORS( (alice)(bob) );

fc::ecc::private_key bob_active_key = fc::ecc::private_key::regenerate(fc::digest("bob_active"));
fc::ecc::private_key bob_owner_key = fc::ecc::private_key::regenerate(fc::digest("bob_owner"));

trx.clear();

// Make sure Bob has different keys
account_update_operation auo;
auo.account = bob_id;
auo.active = authority( 1, public_key_type(bob_active_key.get_public_key()), 1 );
auo.owner = authority( 1, public_key_type(bob_owner_key.get_public_key()), 1 );
trx.operations.push_back( auo );
sign( trx, bob_private_key );
PUSH_TX( db, trx );
trx.clear();

// Delegate Alice's owner auth to herself and active auth to Bob
auo.account = alice_id;
auo.active = authority( 1, bob_id, 1 );
auo.owner = authority( 1, alice_id, 1 );
trx.operations.push_back( auo );
sign( trx, alice_private_key );
PUSH_TX( db, trx );
trx.clear();

// Now Bob has full control over Alice's account
auo.account = alice_id;
auo.active.reset();
auo.owner = authority( 1, bob_id, 1 );
trx.operations.push_back( auo );
sign( trx, bob_active_key );
PUSH_TX( db, trx );
trx.clear();
} FC_LOG_AND_RETHROW() }

/// This test case reproduces https://github.com/bitshares/bitshares-core/issues/944
/// and https://github.com/bitshares/bitshares-core/issues/580
BOOST_FIXTURE_TEST_CASE( missing_owner_auth_test, database_fixture )
Expand Down