Skip to content

Commit

Permalink
Finish implementation for reporting witness version and tested steemi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed May 16, 2016
1 parent 1055930 commit e29fb7a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_library( steemit_chain
protocol/transaction.cpp
protocol/block.cpp
protocol/asset.cpp
protocol/version.cpp

get_config.cpp

Expand Down
10 changes: 3 additions & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ signed_block database::_generate_block(
pending_block.timestamp = when;
pending_block.transaction_merkle_root = pending_block.calculate_merkle_root();
pending_block.witness = witness_owner;
if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) ) // TODO: Can be removed after hardfork time
if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) && get_witness( witness_owner ).running_version != STEEMIT_BLOCKCHAIN_VERSION ) // TODO: Hardfork requirement can be removed after hardfork time
pending_block.extensions.insert( future_extensions( STEEMIT_BLOCKCHAIN_VERSION ) );

if( !(skip & skip_witness_signature) )
Expand Down Expand Up @@ -1928,7 +1928,7 @@ void database::_apply_block( const signed_block& next_block )
/// parse witness version reporting
auto ext_itr = next_block.extensions.begin();

if( ext_itr != next_block.extensions.end() )
if( ext_itr != next_block.extensions.end() && has_hardfork( STEEMIT_HARDFORK_0_5__54 ) )
{
try
{
Expand All @@ -1940,11 +1940,7 @@ void database::_apply_block( const signed_block& next_block )
wo.running_version = reported_version;
});
}
catch( fc::assert_exception )
{
if( has_hardfork( STEEMIT_HARDFORK_0_5__54 ) )
wlog( "Expected blockchain version number from witness ${w} on block ${b}", ("w", signing_witness.owner)("b", next_block_num) );
}
catch( fc::assert_exception ) {}
}

for( const auto& trx : next_block.transactions )
Expand Down
12 changes: 12 additions & 0 deletions libraries/chain/hardfork.d/0_5.hf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef STEEMIT_HARDFORK_0_5
#define STEEMIT_HARDFORK_0_5 5
#define STEEMIT_HARDFORK_0_5__22 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__54 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__55 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__56 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__57 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__58 ( STEEMIT_HARDFORK_0_5 )
#define STEEMIT_HARDFORK_0_5__59 ( STEEMIT_HARDFORK_0_5 )

#define STEEMIT_HARDFORK_0_5_TIME 2462028400
#endif
6 changes: 0 additions & 6 deletions libraries/chain/hardfork.d/0_5_0.hf

This file was deleted.

6 changes: 3 additions & 3 deletions libraries/chain/include/steemit/chain/witness_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ namespace steemit { namespace chain {

digest_type last_work;

/* This field represents the hardforking version the witness is running. This equates to
the ID of the last hardfork that the witness knows about, regardless of whether it has
been applied or not */
/**
* This field represents the Steem blockchain version the witness is running.
*/
version running_version;

witness_id_type get_id()const { return id; }
Expand Down
28 changes: 21 additions & 7 deletions python_scripts/tests/debug_hardforks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This test module will only run on a POSIX system. Windows support *may* be added at some point in the future.
"""
# Global imports
import json, operator, os, sys
import json, operator, os, signal, sys

from argparse import ArgumentParser
from pathlib import Path
Expand All @@ -12,8 +12,10 @@
from steemdebugnode import DebugNode
from steemapi.steemnoderpc import SteemNodeRPC

WAITING = True

def main( ):
global WAITING
if( os.name != "posix" ):
print( "This script only works on POSIX systems" )
return
Expand Down Expand Up @@ -47,14 +49,20 @@ def main( ):
if( not data_dir.is_dir() ):
print( 'Error: data_dir is not a directory' )

debug_node = DebugNode( str( steemd ), str( data_dir ), steemd_err=sys.stderr )
signal.signal( signal.SIGINT, sigint_handler )

debug_node = DebugNode( str( steemd ), str( data_dir ), steemd_out=sys.stdout, steemd_err=sys.stderr )

with debug_node :

run_steemd_tests( debug_node )

# Term on completion?
while( args.pause_node ):
if( args.pause_node ):
print( "Letting the node hang for manual inspection..." )
else:
WAITING = False

while( WAITING ):
sleep( 1 )


Expand All @@ -72,13 +80,13 @@ def run_steemd_tests( debug_node ):

print( "Setting the hardfork now" ) # TODO: Grab most recent hardfork num from build directory
sys.stdout.flush()
debug_node.debug_set_hardfork( 4 )
debug_node.debug_set_hardfork( 5 )

print( "Generating blocks after the hardfork" )
assert( debug_node.debug_generate_blocks( 5000 ) == 5000 )

print( "Done!" )
print( "Calculating block producer distribution:" )
'''print( "Calculating block producer distribution:" )
sys.stdout.flush()
rpc = SteemNodeRPC( 'ws://127.0.0.1:8090', '', '' )
block_producers = {}
Expand All @@ -92,9 +100,15 @@ def run_steemd_tests( debug_node ):
sorted_block_producers = sorted( block_producers.items(), key=operator.itemgetter( 1 ) )
for (k, v) in sorted_block_producers:
ret = rpc.rpcexec( json.loads( '{"jsonrpc": "2.0", "method": "call", "params": [0,"get_witness_by_account",["' + k + '"]], "id":5}' ) )
print( '{"witness":"' + k + '","votes":' + str( ret["votes"] ) + ',"blocks":' + str( v ) + '}' )
print( '{"witness":"' + k + '","votes":' + str( ret["votes"] ) + ',"blocks":' + str( v ) + '}' )'''

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

def sigint_handler( signum, frame ):
global WAITING
WAITING = False
sleep( 3 )
sys.exit( 0 )

main()
1 change: 0 additions & 1 deletion python_scripts/tests/test_payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def main( ):

run_steemd_tests( debug_node )

# Term on completion?
if( args.pause_node ):
print( "Letting the node hang for manual inspection..." )
else:
Expand Down

0 comments on commit e29fb7a

Please sign in to comment.