Skip to content

Commit

Permalink
Merge pull request steemit#1933 from steemit/1782-temp-recovery-account
Browse files Browse the repository at this point in the history
Temp Account Creation Recovery Account
  • Loading branch information
Michael Vandeberg authored May 21, 2018
2 parents ee82da3 + c508345 commit 5fd82d7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
5 changes: 5 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4365,6 +4365,11 @@ bool database::has_hardfork( uint32_t hardfork )const
return get_hardfork_property_object().processed_hardforks.size() > hardfork;
}

uint32_t database::get_hardfork()const
{
return get_hardfork_property_object().processed_hardforks.size() - 1;
}

void database::set_hardfork( uint32_t hardfork, bool apply_now )
{
auto const& hardforks = get_hardfork_property_object();
Expand Down
4 changes: 3 additions & 1 deletion libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ namespace steem { namespace chain {

bool has_hardfork( uint32_t hardfork )const;

uint32_t get_hardfork()const;

/* For testing and debugging only. Given a hardfork
with id N, applies all hardforks with id <= N */
void set_hardfork( uint32_t hardfork, bool process_now = true );
Expand Down Expand Up @@ -468,7 +470,7 @@ namespace steem { namespace chain {
* @return a list of available NAIs.
*/
vector< asset_symbol_type > get_smt_next_identifier();

///@}
#endif

Expand Down
34 changes: 24 additions & 10 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,26 @@ void verify_authority_accounts_exist(
}

void initialize_account_object( account_object& acc, const account_name_type& name, const public_key_type& key,
const dynamic_global_property_object& props, bool mined, const account_name_type& recovery_account )
const dynamic_global_property_object& props, bool mined, const account_name_type& recovery_account, uint32_t hardfork )
{
acc.name = name;
acc.memo_key = key;
acc.created = props.time;
acc.last_vote_time = props.time;
acc.mined = mined;
acc.recovery_account = recovery_account;

if( hardfork >= STEEM_HARDFORK_0_11 )
{
FC_TODO( "If after HF 20, there are no temp account creations, the HF check can be removed." )
if( ( hardfork < STEEM_HARDFORK_0_20__1782 ) || ( recovery_account != STEEM_TEMP_ACCOUNT ) )
{
acc.recovery_account = recovery_account;
}
}
else
{
acc.recovery_account = "steem";
}
}

void account_create_evaluator::do_apply( const account_create_operation& o )
Expand Down Expand Up @@ -296,8 +308,7 @@ void account_create_evaluator::do_apply( const account_create_operation& o )

const auto& new_account = _db.create< account_object >( [&]( account_object& acc )
{
initialize_account_object( acc, o.new_account_name, o.memo_key, props, false /*mined*/,
_db.has_hardfork( STEEM_HARDFORK_0_11__169 ) ? o.creator : "steem" );
initialize_account_object( acc, o.new_account_name, o.memo_key, props, false /*mined*/, o.creator, _db.get_hardfork() );
#ifndef IS_LOW_MEM
from_string( acc.json_metadata, o.json_metadata );
#endif
Expand Down Expand Up @@ -370,7 +381,7 @@ void account_create_with_delegation_evaluator::do_apply( const account_create_wi

const auto& new_account = _db.create< account_object >( [&]( account_object& acc )
{
initialize_account_object( acc, o.new_account_name, o.memo_key, props, false /*mined*/, o.creator );
initialize_account_object( acc, o.new_account_name, o.memo_key, props, false /*mined*/, o.creator, _db.get_hardfork() );
acc.received_vesting_shares = o.delegation;

#ifndef IS_LOW_MEM
Expand Down Expand Up @@ -1226,7 +1237,7 @@ void calculate_power_shares( i_voting_helper* voting_helper, t_voter_asset_info*
int64_t elapsed_seconds = (db.head_block_time() - last_vote_time).to_seconds();

if( db.has_hardfork( STEEM_HARDFORK_0_11 ) )
FC_ASSERT( elapsed_seconds >= voting_helper->get_minimal_vote_interval(),
FC_ASSERT( elapsed_seconds >= voting_helper->get_minimal_vote_interval(),
"Can only vote once every ${sec} seconds.", ("sec", voting_helper->get_minimal_vote_interval()) );

int64_t regenerated_power = (STEEM_100_PERCENT * elapsed_seconds) / voting_helper->get_vote_regeneration_period();
Expand Down Expand Up @@ -1356,7 +1367,7 @@ void cast_vote( i_voting_helper* voting_helper, const t_voter_asset_info& info,
}
voting_helper->update_comment_vote_object( cvo, vote_weight, rshares );


if( max_vote_weight ) // Optimization
{
voting_helper->increase_comment_total_vote_weight( comment, max_vote_weight );
Expand Down Expand Up @@ -1568,8 +1579,7 @@ void pow_apply( database& db, Operation o )
{
db.create< account_object >( [&]( account_object& acc )
{
initialize_account_object( acc, o.get_worker_account(), o.work.worker, dgp, true /*mined*/,
db.has_hardfork( STEEM_HARDFORK_0_11__169 ) ? "" : "steem" );
initialize_account_object( acc, o.get_worker_account(), o.work.worker, dgp, true /*mined*/, account_name_type(), db.get_hardfork() );
// ^ empty recovery account parameter means highest voted witness at time of recovery
});

Expand Down Expand Up @@ -1682,7 +1692,7 @@ void pow2_evaluator::do_apply( const pow2_operation& o )
FC_ASSERT( o.new_owner_key.valid(), "New owner key is not valid." );
db.create< account_object >( [&]( account_object& acc )
{
initialize_account_object( acc, worker_account, *o.new_owner_key, dgp, true /*mined*/, "" );
initialize_account_object( acc, worker_account, *o.new_owner_key, dgp, true /*mined*/, account_name_type(), _db.get_hardfork() );
// ^ empty recovery account parameter means highest voted witness at time of recovery
});

Expand Down Expand Up @@ -1834,7 +1844,11 @@ void request_account_recovery_evaluator::do_apply( const request_account_recover
const auto& account_to_recover = _db.get_account( o.account_to_recover );

if ( account_to_recover.recovery_account.length() ) // Make sure recovery matches expected recovery account
{
FC_ASSERT( account_to_recover.recovery_account == o.recovery_account, "Cannot recover an account that does not have you as there recovery partner." );
if( o.recovery_account == STEEM_TEMP_ACCOUNT )
wlog( "Recovery by temp account" );
}
else // Empty string recovery account defaults to top witness
FC_ASSERT( _db.get_index< witness_index >().indices().get< by_vote_name >().begin()->owner == o.recovery_account, "Top witness must recover an account with no recovery partner." );

Expand Down
1 change: 1 addition & 0 deletions libraries/protocol/hardfork.d/0_20.hf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define STEEM_HARDFORK_0_20__1760 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1764 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1765 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1782 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1811 (STEEM_HARDFORK_0_20)
#define STEEM_HARDFORK_0_20__1815 (STEEM_HARDFORK_0_20)

Expand Down
14 changes: 14 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ BOOST_AUTO_TEST_CASE( account_create_apply )
tx.sign( init_account_priv_key, db->get_chain_id() );
STEEM_REQUIRE_THROW( db->push_transaction( tx, 0 ), fc::exception );
validate_database();

BOOST_TEST_MESSAGE( "--- Test account creation with temp account does not set recovery account" );
fund( STEEM_TEMP_ACCOUNT, ASSET( "310.000 TESTS" ) );
vest( STEEM_TEMP_ACCOUNT, ASSET( "10.000 TESTS" ) );
op.creator = STEEM_TEMP_ACCOUNT;
op.fee = ASSET( "300.000 TESTS" );
op.new_account_name = "bob";
tx.clear();
tx.operations.push_back( op );
db->push_transaction( tx, 0 );

BOOST_REQUIRE( db->get_account( "bob" ).recovery_account == account_name_type() );
validate_database();

}
FC_LOG_AND_RETHROW()
}
Expand Down

0 comments on commit 5fd82d7

Please sign in to comment.