Skip to content

Commit

Permalink
added connectivity check to bv sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gundlach committed Dec 5, 2020
1 parent 5788c11 commit bf3854b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace eosio { namespace chain { namespace plugin_interface {
namespace methods {
// synchronously push a block/trx to a single provider
using block_sync = method_decl<chain_plugin_interface, bool(const signed_block_ptr&, const std::optional<block_id_type>&), first_provider_policy>;
using blockvault_sync = method_decl<chain_plugin_interface, bool(const signed_block_ptr&), first_provider_policy>;
using blockvault_sync = method_decl<chain_plugin_interface, bool(const signed_block_ptr&, bool), first_provider_policy>;
using transaction_async = method_decl<chain_plugin_interface, void(const packed_transaction_ptr&, bool, next_function<transaction_trace_ptr>), first_provider_policy>;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct blockvault_sync_strategy : public sync_callback {

try {
++_num_blocks_received;
EOS_ASSERT(_blockchain_provider.incoming_blockvault_sync_method(block), plugin_exception,
EOS_ASSERT(_blockchain_provider.incoming_blockvault_sync_method(block, (1 != _num_blocks_received)), plugin_exception,
"Unable to sync block from blockvault, block num=${bnum}, block id=${bid}",
("bnum", block->block_num())("bid", block->calculate_id()));
} catch (unlinkable_block_exception& e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct mock_chain_plugin_t {
chain = std::make_unique<mock_chain_t>();
}

bool incoming_blockvault_sync_method(const chain::signed_block_ptr& block) {
bool incoming_blockvault_sync_method(const chain::signed_block_ptr& block, bool check_connectivity) {
_block = block;
return _accept_block_rc;
}
Expand Down
15 changes: 12 additions & 3 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,23 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
}
};

bool on_sync_block(const signed_block_ptr& block) {
bool on_sync_block(const signed_block_ptr& block, bool check_connectivity) {
auto& chain = chain_plug->chain();

const auto& id = block->calculate_id();
auto blk_num = block->block_num();

fc_dlog(_log, "syncing blockvault block ${n} ${id}", ("n", blk_num)("id", id));

if (check_connectivity) {
auto previous = chain.fetch_block_by_id(block->previous);
if (!previous) {
dlog("Don't have previous block for block number ${bn}, looking for block id ${pbi}",
("bn", block->block_num())("pbi", block->previous));
return true;
}
}

// start processing of block
auto bsf = chain.create_block_state_future( id, block );

Expand Down Expand Up @@ -858,8 +867,8 @@ void producer_plugin::plugin_initialize(const boost::program_options::variables_
});

my->_incoming_blockvault_sync_provider = app().get_method<incoming::methods::blockvault_sync>().register_provider(
[this](const signed_block_ptr& block) {
return my->on_sync_block(block);
[this](const signed_block_ptr& block, bool check_connectivity) {
return my->on_sync_block(block, check_connectivity);
});

my->_incoming_transaction_async_provider = app().get_method<incoming::methods::transaction_async>().register_provider(
Expand Down

0 comments on commit bf3854b

Please sign in to comment.