Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10611 from EOSIO/state-history-weak-dev-boxed
Browse files Browse the repository at this point in the history
SHiP: Use shared_ptr instead of weak_ptr (explicit and implicit) 📦
  • Loading branch information
heifner authored Aug 11, 2021
2 parents e0bada9 + 4e2f769 commit 805c9f3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
uint32_t current =
block_req.irreversible_only ? result.last_irreversible.block_num : result.head.block_num;

if (to_send_block_num > current || to_send_block_num >= block_req.end_block_num)
if (to_send_block_num > current || to_send_block_num >= block_req.end_block_num) {
fc_dlog( _log, "Not sending, to_send_block_num: ${s}, current: ${c} block_req.end_block_num: ${b}",
("s", to_send_block_num)("c", current)("b", block_req.end_block_num) );
return;
}

auto block_id = plugin->get_block_id(to_send_block_num);

Expand Down Expand Up @@ -277,15 +280,9 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
(void)this; // avoid unused lambda warning
// send get_blocks_result_v1 when the request is get_blocks_request_v0 and
// send send_block_result_v2 when the request is get_blocks_request_v1.
if (head_block_state->block) {
typename std::decay_t<decltype(req)>::response_type result;
result.head = {head_block_state->block_num, head_block_state->id};
if (::fc::zipkin_config::is_enabled() && !span) {
span.emplace("send-update-0", fc::zipkin_span::to_id(head_block_state->id),
"ship"_n.to_uint64_t());
}
send_update(head_block_state, std::move(result), std::move(span));
}
typename std::decay_t<decltype(req)>::response_type result;
result.head = {head_block_state->block_num, head_block_state->id};
send_update(head_block_state, std::move(result), std::move(span));
},
*current_request);
}
Expand Down Expand Up @@ -332,18 +329,15 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl

template <typename T>
void send(T obj, fc::zipkin_span::token token) {
boost::asio::post(this->plugin->work_strand, [this, obj = std::move(obj), token ]() {
send_queue.emplace_back(fc::raw::pack(state_result{std::move(obj)}), token);
send();
boost::asio::post(this->plugin->work_strand, [self = this->shared_from_this(), obj = std::move(obj), token ]() {
self->send_queue.emplace_back(fc::raw::pack(state_result{std::move(obj)}), token);
self->send();
});
}

void close() override {
boost::asio::post(this->plugin->work_strand, [p = std::weak_ptr(this->weak_from_this())]() {
auto self = p.lock();
if (self) {
self->close_i();
}
boost::asio::post(this->plugin->work_strand, [self = this->shared_from_this()]() {
self->close_i();
});
}

Expand Down

0 comments on commit 805c9f3

Please sign in to comment.