Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] P2P: Pause net_plugin during snapshot write #2029

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ struct controller_impl {
named_thread_pool<chain> thread_pool;
deep_mind_handler* deep_mind_logger = nullptr;
bool okay_to_print_integrity_hash_on_stop = false;
std::atomic<bool> writing_snapshot = false;

thread_local static platform_timer timer; // a copy for main thread and each read-only thread
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
Expand Down Expand Up @@ -3246,7 +3247,15 @@ fc::sha256 controller::calculate_integrity_hash() { try {

void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) {
EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" );
return my->add_to_snapshot(snapshot);
my->writing_snapshot.store(true, std::memory_order_release);
fc::scoped_exit<std::function<void()>> e = [&] {
my->writing_snapshot.store(false, std::memory_order_release);
};
my->add_to_snapshot(snapshot);
}

bool controller::is_writing_snapshot() const {
return my->writing_snapshot.load(std::memory_order_acquire);
}

int64_t controller::set_proposed_producers( vector<producer_authority> producers ) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ namespace eosio { namespace chain {

fc::sha256 calculate_integrity_hash();
void write_snapshot( const snapshot_writer_ptr& snapshot );
// thread-safe
bool is_writing_snapshot()const;

bool sender_avoids_whitelist_blacklist_enforcement( account_name sender )const;
void check_actor_list( const flat_set<account_name>& actors )const;
Expand Down
10 changes: 10 additions & 0 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ namespace eosio {
void start_expire_timer();
void start_monitors();

// we currently pause on snapshot generation
void wait_if_paused() const {
controller& cc = chain_plug->chain();
while (cc.is_writing_snapshot()) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}

void expire();
/** \name Peer Timestamps
* Time message handling
Expand Down Expand Up @@ -2897,6 +2905,8 @@ namespace eosio {
return;
}

my_impl->wait_if_paused();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I would even move this before the watermark thing above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better after the max_write_queue_size check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of max_write_queue_size check, I guess this change will cause a node making a snapshot to ultimately be disconnected from peers since it isn't consuming any network traffic from its peers. It's seemingly not a problem since everything will reconnect anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, that disconnect is less than ideal. See AntelopeIO/spring#592


boost::asio::async_read( *socket,
pending_message_buffer.get_buffer_sequence_for_boost_async_read(), completion_handler,
boost::asio::bind_executor( strand,
Expand Down
Loading