diff --git a/cmd/ship_receiver_plugin.cpp b/cmd/ship_receiver_plugin.cpp index 1ea17162..286d8e5b 100644 --- a/cmd/ship_receiver_plugin.cpp +++ b/cmd/ship_receiver_plugin.cpp @@ -52,7 +52,10 @@ class ship_receiver_plugin_impl : std::enable_shared_from_thisasync_read(*buff, appbase::app().get_priority_queue().wrap(80, [buff, func](const auto ec, auto) { if (ec) { - SILK_CRIT << "SHiP read failed : " << ec.message(); - sys::error(); - } else { - func(buff); - } + SILK_ERROR << "SHiP read failed : " << ec.message(); + } + func(ec, buff); }) ); } @@ -232,7 +233,31 @@ class ship_receiver_plugin_impl : std::enable_shared_from_thisclose(websocket::close_reason(websocket::close_code::normal),ec2); + + // Reconnect and restart sync. + SILK_INFO << "Trying to reconnect."; + num_messages = 0; + stream = std::make_shared>(appbase::app().get_io_service()); + stream->binary(true); + stream->read_message_max(0x1ull << 36); + connect_stream(); + initial_read(); + SILK_INFO << "Trying to sync again."; + sync(true); + return; + } auto block = to_native(std::get(get_result(buff))); if(!block) { sys::error("Unable to generate native block"); @@ -250,7 +275,7 @@ class ship_receiver_plugin_impl : std::enable_shared_from_thismix_hash.bytes) + 1; SILK_INFO << "Canonical header start from block: " << start_from; - if( start_from_block_id ) { - uint32_t block_num = utils::to_block_num(*start_from_block_id); - SILK_INFO << "Using specified start block number:" << block_num; - start_from = block_num; + if (restart) { + // Always start from early blocks to handle potential forks. + // Clearly this approach will introduce overhaad, but since this piece of code + // will only execute during recovery, it should be fine. + if (head_header->number > 250) { + start_from -= 500; + } + } + else { + // Only take care of input option when it's initial sync. + if( start_from_block_id ) { + uint32_t block_num = utils::to_block_num(*start_from_block_id); + SILK_INFO << "Using specified start block number:" << block_num; + start_from = block_num; + } } + if( res.trace_begin_block > start_from ) { SILK_ERROR << "Block #" << start_from << " not available in SHiP";