Skip to content

Commit

Permalink
Allow witnesses to recall a hard fork vote and the witness majority v…
Browse files Browse the repository at this point in the history
…ersion to downgrade.

Changed payout test to output rewards per account.
  • Loading branch information
Michael Vandeberg committed May 24, 2016
1 parent d247df8 commit 1672f91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
34 changes: 18 additions & 16 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,16 +716,23 @@ signed_block database::_generate_block(
pending_block.witness = witness_owner;
if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) )
{
if( get_witness( witness_owner ).running_version != STEEMIT_BLOCKCHAIN_VERSION ) // TODO: Hardfork requirement can be removed after hardfork time
const auto& witness = get_witness( witness_owner );

if( witness.running_version != STEEMIT_BLOCKCHAIN_VERSION ) // TODO: Hardfork requirement can be removed after hardfork time
pending_block.extensions.insert( future_extensions( STEEMIT_BLOCKCHAIN_VERSION ) );

const auto& hfp = hardfork_property_id_type()( *this );

if( STEEMIT_NUM_HARDFORKS > hfp.last_hardfork )
if( STEEMIT_NUM_HARDFORKS > hfp.last_hardfork ) // Binary knows of a new hardfork
{
pending_block.extensions.insert( future_extensions( _hardfork_versions[ hfp.last_hardfork + 1 ] ) );
pending_block.extensions.insert( future_extensions( _hardfork_times[ hfp.last_hardfork + 1 ] ) );
}
else if( witness.hardfork_version_vote > _hardfork_versions[ hfp.last_hardfork ] ) // Don't know about the new hardfork and have previously voted for it
{
pending_block.extensions.insert( future_extensions( _hardfork_versions[ hfp.last_hardfork ] ) );
pending_block.extensions.insert( future_extensions( _hardfork_times[ hfp.last_hardfork ] ) );
}
}

if( !(skip & skip_witness_signature) )
Expand Down Expand Up @@ -994,21 +1001,16 @@ void database::update_witness_schedule4() {
for( uint32_t i = 0; i < wso.current_shuffled_witnesses.size(); i++ )
{
auto witness = get_witness( wso.current_shuffled_witnesses[ i ] );
if( witness_versions.find( witness.running_version ) == witness_versions.end() )
witness_versions[ witness.running_version ] = 1;
else
witness_versions[ witness.running_version ] += 1;

if( witness.pow_worker == 0 && witness.running_version > majority_version )
{
if( witness_versions.find( witness.running_version ) == witness_versions.end() )
witness_versions[ witness.running_version ] = 1;
else
witness_versions[ witness.running_version ] += 1;

auto version_vote = std::make_tuple( witness.hardfork_version_vote, witness.hardfork_time_vote );

if( hardfork_version_votes.find( version_vote ) == hardfork_version_votes.end() )
hardfork_version_votes[ version_vote ] = 1;
else
hardfork_version_votes[ version_vote ] += 1;
}
auto version_vote = std::make_tuple( witness.hardfork_version_vote, witness.hardfork_time_vote );
if( hardfork_version_votes.find( version_vote ) == hardfork_version_votes.end() )
hardfork_version_votes[ version_vote ] = 1;
else
hardfork_version_votes[ version_vote ] += 1;
}

int witnesses_on_version = 0;
Expand Down
30 changes: 28 additions & 2 deletions python_scripts/tests/test_payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,47 @@ def run_steemd_tests( debug_node ):

print( "Triggering payouts" )
sys.stdout.flush()
debug_node.debug_generate_blocks_until( 1467590400 )
debug_node.debug_generate_blocks_until( 1467590400 - 3 )
rpc = SteemNodeRPC( 'ws://127.0.0.1:8095', '', '' )
ret = rpc.lookup_accounts( '', str( 0xFFFFFFFF ) )
account_balances = {}
for acc_name in ret:
acc = rpc.get_accounts( [ acc_name ] )
steemd = float( acc[0][ 'balance' ].split( ' ' )[0] )
sbd = float( acc[0][ 'sbd_balance' ].split( ' ' )[0] )
vests = float( acc[0][ 'vesting_shares' ].split( ' ' )[0] )
account_balances[ acc_name ] = ( steemd, sbd, vests )

debug_node.debug_generate_blocks( 1 )

account_rewards = {}
for acc_name, bal in account_balances.items():
acc = rpc.get_accounts( [ acc_name ] )
steemd = float( acc[0][ 'balance' ].split( ' ' )[0] ) - bal[0]
sbd = float( acc[0][ 'sbd_balance' ].split( ' ' )[0] ) - bal[1]
vests = float( acc[0][ 'vesting_shares' ].split( ' ' )[0] ) - bal[2]
account_rewards[ acc_name ] = ( steemd, sbd, vests )

print( "Generating blocks to verify nothing broke" )
assert( debug_node.debug_generate_blocks( 10 ) == 10 )

'''
print( "Done!" )
print( "Getting comment dump:" )
sys.stdout.flush()
rpc = SteemNodeRPC( 'ws://127.0.0.1:8095', '', '' )
ret = rpc.get_discussions_by_cashout_time( '', '', str( 0xFFFFFFFF ) );
print( 'author, url, total_payout_value, abs_rshares, num_active_votes' )
for comment in ret:
print( comment[ 'author' ] + ', ' + comment[ 'url' ] + ', ' + comment[ 'total_payout_value' ] + ', ' + comment[ 'cashout_time' ] )
'''

print( "Printing account reward dump:" )
print( "account, steem, sbd, vests" )
for acc_name, rew in account_rewards.items():
print( acc_name + ', ' + str( rew[0] ) + ' STEEM, ' + str( rew[1] ) + ' SBD, ' + str( rew[2] ) + ' VESTS' )

except ValueError as val_err:
print( str( val_err ) )
Expand Down

0 comments on commit 1672f91

Please sign in to comment.