Skip to content

Commit

Permalink
Merge branch 'master' into steem-prerelease-v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Jun 9, 2017
2 parents b938762 + 3b13879 commit b42a5de
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 34 deletions.
5 changes: 3 additions & 2 deletions contrib/startpaassteemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ fi

NOW=`date +%s`
STEEMD_FEED_START_TIME=`expr $NOW - 1209600`
STEEMD_FEED_START_TIMESTAMP=`date --date=@$STEEMD_FEED_START_TIME +%Y-%m-%d:%H:%M:%S`

ARGS+=" --follow-start-feeds=\"$STEEMD_FEED_START_TIMESTAMP\""
ARGS+=" --follow-start-feeds=$STEEMD_FEED_START_TIME"

ARGS+=" --disable-get-block"

# overwrite local config with image one
cp /etc/steemd/fullnode.config.ini $HOME/config.ini
Expand Down
3 changes: 1 addition & 2 deletions contrib/steemd.run
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ fi

NOW=`date +%s`
STEEMD_FEED_START_TIME=`expr $NOW - 1209600`
STEEMD_FEED_START_TIMESTAMP=`date --date=@$STEEMD_FEED_START_TIME +%Y-%m-%d:%H:%M:%S`

ARGS+=" --follow-start-feeds=\"$STEEMD_FEED_START_TIMESTAMP\""
ARGS+=" --follow-start-feeds=$STEEMD_FEED_START_TIME"

# overwrite local config with image one
if [[ "$USE_FULL_WEB_NODE" ]]; then
Expand Down
2 changes: 2 additions & 0 deletions doc/seednodes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ seed.bitcoiner.me:2001 # bitcoiner
88.99.33.113:2001 # cervantes
seed.bhuz.info:2001 # bhuz
78.46.95.157:2001 # pcste
seed.steemviz.com:2001 # ausbitbank
45.76.13.167:2001 # chitty
4 changes: 4 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ namespace detail {
else
_shared_dir = _data_dir / "blockchain";

if( _options->count( "disable_get_block" ) )
_self->_disable_get_block = true;

if( !read_only )
{
_self->_read_only = false;
Expand Down Expand Up @@ -989,6 +992,7 @@ void application::set_program_options(boost::program_options::options_descriptio
("force-validate", "Force validation of all transactions")
("read-only", "Node will not connect to p2p network and can only read from the chain state" )
("check-locks", "Check correctness of chainbase locking")
("disable-get-block", "Disable get_block API call" )
;
command_line_options.add(_cli_options);
configuration_file_options.add(_cfg_options);
Expand Down
8 changes: 8 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
std::shared_ptr< steemit::follow::follow_api > _follow_api;

boost::signals2::scoped_connection _block_applied_connection;

bool _disable_get_block = false;
};

applied_operation::applied_operation() {}
Expand Down Expand Up @@ -202,6 +204,8 @@ database_api_impl::database_api_impl( const steemit::app::api_context& ctx )
{
wlog("creating database api ${x}", ("x",int64_t(this)) );

_disable_get_block = ctx.app._disable_get_block;

try
{
ctx.app.get_plugin< follow::follow_plugin >( FOLLOW_PLUGIN_NAME );
Expand All @@ -225,6 +229,8 @@ void database_api::on_api_startup() {}

optional<block_header> database_api::get_block_header(uint32_t block_num)const
{
FC_ASSERT( !my->_disable_get_block, "get_block_header is disabled on this node." );

return my->_db.with_read_lock( [&]()
{
return my->get_block_header( block_num );
Expand All @@ -241,6 +247,8 @@ optional<block_header> database_api_impl::get_block_header(uint32_t block_num) c

optional<signed_block_api_obj> database_api::get_block(uint32_t block_num)const
{
FC_ASSERT( !my->_disable_get_block, "get_block is disabled on this node." );

return my->_db.with_read_lock( [&]()
{
return my->get_block( block_num );
Expand Down
1 change: 1 addition & 0 deletions libraries/app/include/steemit/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace steemit { namespace app {
void connect_to_write_node();

bool _read_only = true;
bool _disable_get_block = false;
fc::optional< string > _remote_endpoint;
fc::optional< fc::api< network_broadcast_api > > _remote_net_api;
fc::optional< fc::api< login_api > > _remote_login;
Expand Down
79 changes: 49 additions & 30 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,46 @@ bool database::is_known_transaction( const transaction_id_type& id )const
return trx_idx.find( id ) != trx_idx.end();
} FC_CAPTURE_AND_RETHROW() }

block_id_type database::get_block_id_for_num( uint32_t block_num )const
block_id_type database::find_block_id_for_num( uint32_t block_num )const
{
try
{
if( block_num == 0 )
return block_id_type();

// Reversible blocks are *usually* in the TAPOS buffer. Since this
// is the fastest check, we do it first.
block_summary_id_type bsid = block_num & 0xFFFF;
const block_summary_object* bs = find< block_summary_object, by_id >( bsid );
if( bs != nullptr )
{
if( protocol::block_header::num_from_id(bs->block_id) == block_num )
return bs->block_id;
}

// Next we query the block log. Irreversible blocks are here.
auto b = _block_log.read_block_by_num( block_num );
if( b.valid() )
return b->id();

auto results = _fork_db.fetch_block_by_number( block_num );
FC_ASSERT( results.size() == 1 );
return results[0]->data.id();
// Finally we query the fork DB.
shared_ptr< fork_item > fitem = _fork_db.fetch_block_on_main_branch_by_number( block_num );
if( fitem )
return fitem->id;

return block_id_type();
}
FC_CAPTURE_AND_RETHROW( (block_num) )
}

block_id_type database::get_block_id_for_num( uint32_t block_num )const
{
block_id_type bid = find_block_id_for_num( block_num );
FC_ASSERT( bid != block_id_type() );
return bid;
}


optional<signed_block> database::fetch_block_by_id( const block_id_type& id )const
{ try {
auto b = _fork_db.fetch_block( id );
Expand Down Expand Up @@ -500,6 +524,22 @@ bool database::push_block(const signed_block& new_block, uint32_t skip)
return result;
}

void database::_maybe_warn_multiple_production( uint32_t height )const
{
auto blocks = _fork_db.fetch_block_by_number( height );
if( blocks.size() > 1 )
{
vector< std::pair< account_name_type, fc::time_point_sec > > witness_time_pairs;
for( const auto& b : blocks )
{
witness_time_pairs.push_back( std::make_pair( b->data.witness, b->data.timestamp ) );
}

ilog( "Encountered block num collision at block ${n} due to a fork, witnesses are:", ("n", height)("w", witness_time_pairs) );
}
return;
}

bool database::_push_block(const signed_block& new_block)
{ try {
uint32_t skip = get_node_properties().skip_flags;
Expand All @@ -508,6 +548,8 @@ bool database::_push_block(const signed_block& new_block)
if( !(skip&skip_fork_db) )
{
shared_ptr<fork_item> new_head = _fork_db.push_block(new_block);
_maybe_warn_multiple_production( new_head->num );

//If the head block from the longest chain does not build off of the current head, we need to switch forks.
if( new_head->data.previous != head_block_id() )
{
Expand Down Expand Up @@ -3075,32 +3117,9 @@ void database::update_last_irreversible_block()
{
while( log_head_num < dpo.last_irreversible_block_num )
{
signed_block* block_ptr;
auto blocks = _fork_db.fetch_block_by_number( log_head_num + 1 );

if( blocks.size() == 1 )
block_ptr = &( blocks[0]->data );
else
{
vector< std::pair< account_name_type, fc::time_point_sec > > witness_time_pairs;
for( const auto& b : blocks )
{
witness_time_pairs.push_back( std::make_pair( b->data.witness, b->data.timestamp ) );
}

ilog( "Encountered a block num collision due to a fork. Walking the current fork to determine the correct block. block_num:${n}", ("n", log_head_num + 1) );
ilog( "Colliding blocks produced by witnesses at times: ${w}", ("w", witness_time_pairs) );

auto next = _fork_db.head();
while( next.get() != nullptr && next->num > log_head_num + 1 )
next = next->prev.lock();

FC_ASSERT( next.get() != nullptr, "Current fork in the fork database does not contain the last_irreversible_block" );

block_ptr = &( next->data );
}

_block_log.append( *block_ptr );
shared_ptr< fork_item > block = _fork_db.fetch_block_on_main_branch_by_number( log_head_num+1 );
FC_ASSERT( block, "Current fork in the fork database does not contain the last_irreversible_block" );
_block_log.append( block->data );
log_head_num++;
}

Expand Down
21 changes: 21 additions & 0 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,27 @@ pair<fork_database::branch_type,fork_database::branch_type>
return result;
} FC_CAPTURE_AND_RETHROW( (first)(second) ) }

shared_ptr<fork_item> fork_database::walk_main_branch_to_num( uint32_t block_num )const
{
shared_ptr<fork_item> next = head();
if( block_num > next->num )
return shared_ptr<fork_item>();

while( next.get() != nullptr && next->num > block_num )
next = next->prev.lock();
return next;
}

shared_ptr<fork_item> fork_database::fetch_block_on_main_branch_by_number( uint32_t block_num )const
{
vector<item_ptr> blocks = fetch_block_by_number(block_num);
if( blocks.size() == 1 )
return blocks[0];
if( blocks.size() == 0 )
return shared_ptr<fork_item>();
return walk_main_branch_to_num(block_num);
}

void fork_database::set_head(shared_ptr<fork_item> h)
{
_head = h;
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/steemit/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace steemit { namespace chain {
bool is_known_transaction( const transaction_id_type& id )const;
fc::sha256 get_pow_target()const;
uint32_t get_pow_summary_target()const;
block_id_type find_block_id_for_num( uint32_t block_num )const;
block_id_type get_block_id_for_num( uint32_t block_num )const;
optional<signed_block> fetch_block_by_id( const block_id_type& id )const;
optional<signed_block> fetch_block_by_number( uint32_t num )const;
Expand Down Expand Up @@ -164,6 +165,7 @@ namespace steemit { namespace chain {

bool push_block( const signed_block& b, uint32_t skip = skip_nothing );
void push_transaction( const signed_transaction& trx, uint32_t skip = skip_nothing );
void _maybe_warn_multiple_production( uint32_t height )const;
bool _push_block( const signed_block& b );
void _push_transaction( const signed_transaction& trx );

Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/steemit/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace steemit { namespace chain {
*/
pair< branch_type, branch_type > fetch_branch_from(block_id_type first,
block_id_type second)const;
shared_ptr<fork_item> walk_main_branch_to_num( uint32_t block_num )const;
shared_ptr<fork_item> fetch_block_on_main_branch_by_number( uint32_t block_num )const;

struct block_id;
struct block_num;
Expand All @@ -101,4 +103,5 @@ namespace steemit { namespace chain {
fork_multi_index_type _index;
shared_ptr<fork_item> _head;
};

} } // steemit::chain

0 comments on commit b42a5de

Please sign in to comment.