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

Validate posting auth and check for account auth existence as a soft … #466

Merged
merged 3 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@ void database::apply_block( const signed_block& next_block, uint32_t skip )
| skip_block_size_check
| skip_tapos_check
| skip_authority_check
| skip_merkle_check
/* | skip_merkle_check While blockchain is being downloaded, txs need to be validated against block headers */
| skip_undo_history_check
| skip_witness_schedule_check
| skip_validate
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steemit/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
#pragma once

#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 14, 2) )
#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 14, 3) )
#define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION ( hardfork_version( STEEMIT_BLOCKCHAIN_VERSION ) )

#ifdef IS_TEST_NET
Expand Down
28 changes: 28 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ void account_update_evaluator::do_apply( const account_update_operation& o )
{
if( db().has_hardfork( STEEMIT_HARDFORK_0_1 ) ) FC_ASSERT( o.account != STEEMIT_TEMP_ACCOUNT, "cannot update temp account" );

if( db().is_producing() && o.posting ) // TODO: Add HF 15
o.posting->validate();

const auto& account = db().get_account( o.account );

if( o.owner )
Expand All @@ -158,9 +161,34 @@ void account_update_evaluator::do_apply( const account_update_operation& o )
FC_ASSERT( db().head_block_time() - account.last_owner_update > STEEMIT_OWNER_UPDATE_LIMIT, "can only update owner authority once a minute" );
#endif

if( db().is_producing() ) // TODO: Add HF 15
{
for( auto a: o.owner->account_auths )
{
db().get_account( a.first );
}
}


db().update_owner_authority( account, *o.owner );
}

if( o.active && db().is_producing() ) // TODO: Add HF 15
{
for( auto a: o.active->account_auths )
{
db().get_account( a.first );
}
}

if( o.posting && db().is_producing() ) // TODO: Add HF 15
{
for( auto a: o.posting->account_auths )
{
db().get_account( a.first );
}
}

db().modify( account, [&]( account_object& acc )
{
if( o.active ) acc.active = *o.active;
Expand Down
38 changes: 37 additions & 1 deletion tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ BOOST_AUTO_TEST_CASE( account_update_validate )
{
BOOST_TEST_MESSAGE( "Testing: account_update_validate" );

ACTORS( (alice) )

account_update_operation op;
op.account = "alice";
op.posting = authority();
op.posting->weight_threshold = 1;
op.posting->add_authorities( "abcdefghijklmnopq", 1 );

try
{
op.validate();

signed_transaction tx;
tx.set_expiration( db.head_block_time() + STEEMIT_MAX_TIME_UNTIL_EXPIRATION );
tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

BOOST_FAIL( "An exception was not thrown for an invalid account name" );
}
catch( fc::assert_exception& ) {}

validate_database();
}
FC_LOG_AND_RETHROW()
Expand Down Expand Up @@ -314,6 +336,19 @@ BOOST_AUTO_TEST_CASE( account_update_apply )
tx.sign( new_private_key, db.get_chain_id() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception )
validate_database();


BOOST_TEST_MESSAGE( "--- Test failure when account authority does not exist" );
tx.clear();
op = account_update_operation();
op.account = "alice";
op.posting = authority();
op.posting->weight_threshold = 1;
op.posting->add_authorities( "dave", 1 );
tx.operations.push_back( op );
tx.sign( new_private_key, db.get_chain_id() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception );
validate_database();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -781,7 +816,6 @@ BOOST_AUTO_TEST_CASE( vote_apply )
new_cashout_time = db.head_block_time().sec_since_epoch() + STEEMIT_CASHOUT_WINDOW_SECONDS;
int64_t regenerated_power = (STEEMIT_100_PERCENT * ( db.head_block_time() - db.get_account( "alice").last_vote_time ).to_seconds() ) / STEEMIT_VOTE_REGENERATION_SECONDS;
int64_t used_power = ( db.get_account( "alice" ).voting_power + regenerated_power + max_vote_denom - 1 ) / max_vote_denom;
idump( (db.get_account( "alice" ).voting_power)(used_power) );

comment_op.author = "sam";
comment_op.permlink = "foo";
Expand Down Expand Up @@ -3555,6 +3589,8 @@ BOOST_AUTO_TEST_CASE( pow2_op )

ACTORS( (bob) )

target = db.get_pow_summary_target();

do
{
nonce++;
Expand Down