-
Notifications
You must be signed in to change notification settings - Fork 10
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
[1.0] Limit sync-fetch-span by max-reversible-blocks if needed #545
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4bc6ef6
GH-528 Limit fetch-sync-span by max-reversible-blocks if needed
heifner 145cadb
Merge remote-tracking branch 'spring/release/1.0' into GH-528-limit-sync
heifner 78fa2c1
GH-528 chain_plug->chain_config() not available after plugin_initialize
heifner 1d07ecd
Merge branch 'release/1.0' into GH-528-limit-sync
heifner a6defa1
GH-528 Avoid negative sync fetch
heifner 57ffbcc
GH-528 Use already retrieved value for log
heifner 3b153de
GH-528 Add reversible_remaining to log statement
heifner 1a8327f
Merge branch 'release/1.0' into GH-528-limit-sync
heifner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -225,8 +225,9 @@ namespace eosio { | |||||
uint32_t sync_next_expected_num GUARDED_BY(sync_mtx) {0}; // the next block number we need from peer | ||||||
connection_ptr sync_source GUARDED_BY(sync_mtx); // connection we are currently syncing from | ||||||
|
||||||
const uint32_t sync_req_span {0}; | ||||||
const uint32_t sync_fetch_span {0}; | ||||||
const uint32_t sync_peer_limit {0}; | ||||||
const size_t max_reversible_blocks {0}; | ||||||
|
||||||
alignas(hardware_destructive_interference_sz) | ||||||
std::atomic<stages> sync_state{in_sync}; | ||||||
|
@@ -249,13 +250,13 @@ namespace eosio { | |||||
connection_ptr find_next_sync_node(); // call with locked mutex | ||||||
void start_sync( const connection_ptr& c, uint32_t target ); // locks mutex | ||||||
bool verify_catchup( const connection_ptr& c, uint32_t num, const block_id_type& id ); // locks mutex | ||||||
|
||||||
uint32_t active_sync_fetch_span() const; | ||||||
public: | ||||||
enum class closing_mode { | ||||||
immediately, // closing connection immediately | ||||||
handshake // sending handshake message | ||||||
}; | ||||||
explicit sync_manager( uint32_t span, uint32_t sync_peer_limit, uint32_t min_blocks_distance ); | ||||||
explicit sync_manager( uint32_t span, uint32_t sync_peer_limit, size_t max_reversible_blocks, uint32_t min_blocks_distance ); | ||||||
static void send_handshakes(); | ||||||
bool syncing_from_peer() const { return sync_state == lib_catchup; } | ||||||
bool is_in_sync() const { return sync_state == in_sync; } | ||||||
|
@@ -1994,18 +1995,30 @@ namespace eosio { | |||||
} | ||||||
//----------------------------------------------------------- | ||||||
|
||||||
sync_manager::sync_manager( uint32_t span, uint32_t sync_peer_limit, uint32_t min_blocks_distance ) | ||||||
sync_manager::sync_manager( uint32_t span, uint32_t sync_peer_limit, size_t max_reversible_blocks, uint32_t min_blocks_distance ) | ||||||
:sync_known_lib_num( 0 ) | ||||||
,sync_last_requested_num( 0 ) | ||||||
,sync_next_expected_num( 1 ) | ||||||
,sync_source() | ||||||
,sync_req_span( span ) | ||||||
,sync_fetch_span( span ) | ||||||
,sync_peer_limit( sync_peer_limit ) | ||||||
,max_reversible_blocks(max_reversible_blocks) | ||||||
,sync_state(in_sync) | ||||||
,min_blocks_distance(min_blocks_distance) | ||||||
{ | ||||||
} | ||||||
|
||||||
uint32_t sync_manager::active_sync_fetch_span() const { | ||||||
auto fork_db_size = my_impl->chain_plug->chain().fork_db_size(); | ||||||
auto reversible_remaining = max_reversible_blocks - fork_db_size; | ||||||
if (reversible_remaining < sync_fetch_span) { | ||||||
fc_wlog(logger, "sync-fetch-span ${sfs} restricted by max-reversible-blocks ${m}, fork_db_size ${fs}", | ||||||
("sfs", sync_fetch_span)("m", max_reversible_blocks)("fs", fork_db_size)); | ||||||
return reversible_remaining; | ||||||
} | ||||||
return sync_fetch_span; | ||||||
} | ||||||
|
||||||
constexpr auto sync_manager::stage_str(stages s) { | ||||||
switch (s) { | ||||||
case in_sync : return "in sync"; | ||||||
|
@@ -2113,8 +2126,8 @@ namespace eosio { | |||||
void sync_manager::request_next_chunk( const connection_ptr& conn ) REQUIRES(sync_mtx) { | ||||||
auto chain_info = my_impl->get_chain_info(); | ||||||
|
||||||
fc_dlog( logger, "sync_last_requested_num: ${r}, sync_next_expected_num: ${e}, sync_known_lib_num: ${k}, sync_req_span: ${s}, fhead: ${h}, lib: ${lib}", | ||||||
("r", sync_last_requested_num)("e", sync_next_expected_num)("k", sync_known_lib_num)("s", sync_req_span)("h", chain_info.fork_head_num)("lib", chain_info.lib_num) ); | ||||||
fc_dlog( logger, "sync_last_requested_num: ${r}, sync_next_expected_num: ${e}, sync_known_lib_num: ${k}, sync-fetch-span: ${s}, fhead: ${h}, lib: ${lib}", | ||||||
("r", sync_last_requested_num)("e", sync_next_expected_num)("k", sync_known_lib_num)("s", sync_fetch_span)("h", chain_info.fork_head_num)("lib", chain_info.lib_num) ); | ||||||
|
||||||
if (conn) { | ||||||
// p2p_high_latency_test.py test depends on this exact log statement. | ||||||
|
@@ -2149,7 +2162,8 @@ namespace eosio { | |||||
bool request_sent = false; | ||||||
if( sync_last_requested_num != sync_known_lib_num ) { | ||||||
uint32_t start = sync_next_expected_num; | ||||||
uint32_t end = start + sync_req_span - 1; | ||||||
auto fetch_span = active_sync_fetch_span(); | ||||||
uint32_t end = start + fetch_span - 1; | ||||||
if( end > sync_known_lib_num ) | ||||||
end = sync_known_lib_num; | ||||||
if( end > 0 && end >= start ) { | ||||||
|
@@ -2529,20 +2543,24 @@ namespace eosio { | |||||
} else { | ||||||
// use chain head instead of fork head so we do not get too far ahead of applied blocks | ||||||
uint32_t head = my_impl->get_chain_head_num(); | ||||||
greg7mdp marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// do not allow to get too far ahead (one sync_req_span) of chain head | ||||||
if (blk_num >= sync_last_requested_num && blk_num < head + sync_req_span) { | ||||||
// block was not applied, possibly because we already have the block | ||||||
fc_dlog(logger, "Requesting blocks ahead, head: ${h} fhead ${fh} blk_num: ${bn} sync_next_expected_num ${nen} " | ||||||
"sync_last_requested_num: ${lrn}, sync_last_requested_block: ${lrb}", | ||||||
("h", my_impl->get_chain_head_num())("fh", my_impl->get_fork_head_num()) | ||||||
("bn", blk_num)("nen", sync_next_expected_num) | ||||||
("lrn", sync_last_requested_num)("lrb", c->sync_last_requested_block)); | ||||||
request_next_chunk(); | ||||||
if (blk_num >= sync_last_requested_num) { | ||||||
auto fetch_span = active_sync_fetch_span(); | ||||||
// do not allow to get too far ahead (one sync_fetch_span) of chain head | ||||||
if (blk_num < head + fetch_span) { | ||||||
// block was not applied, possibly because we already have the block | ||||||
fc_dlog(logger, "Requesting ${fs} blocks ahead, head: ${h} fhead ${fh} blk_num: ${bn} sync_next_expected_num ${nen} " | ||||||
"sync_last_requested_num: ${lrn}, sync_last_requested_block: ${lrb}", | ||||||
("fs", fetch_span)("h", my_impl->get_chain_head_num())("fh", my_impl->get_fork_head_num()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
("bn", blk_num)("nen", sync_next_expected_num) | ||||||
("lrn", sync_last_requested_num)("lrb", c->sync_last_requested_block)); | ||||||
request_next_chunk(); | ||||||
} | ||||||
} | ||||||
} | ||||||
} else { // blk_applied | ||||||
if (blk_num >= sync_last_requested_num) { | ||||||
// Did not request blocks ahead, likely because too far ahead of head | ||||||
// Do not restrict sync_fetch_span as we want max-reversible-blocks to shut down the node for applied blocks | ||||||
fc_dlog(logger, "Requesting blocks, head: ${h} fhead ${fh} blk_num: ${bn} sync_next_expected_num ${nen} " | ||||||
"sync_last_requested_num: ${lrn}, sync_last_requested_block: ${lrb}", | ||||||
("h", my_impl->get_chain_head_num())("fh", my_impl->get_fork_head_num()) | ||||||
|
@@ -4228,6 +4246,9 @@ namespace eosio { | |||||
try { | ||||||
fc_ilog( logger, "Initialize net plugin" ); | ||||||
|
||||||
chain_plug = app().find_plugin<chain_plugin>(); | ||||||
EOS_ASSERT( chain_plug, chain::missing_chain_plugin_exception, "" ); | ||||||
|
||||||
peer_log_format = options.at( "peer-log-format" ).as<string>(); | ||||||
|
||||||
txn_exp_period = def_txn_expire_wait; | ||||||
|
@@ -4249,6 +4270,7 @@ namespace eosio { | |||||
sync_master = std::make_unique<sync_manager>( | ||||||
options.at( "sync-fetch-span" ).as<uint32_t>(), | ||||||
options.at( "sync-peer-limit" ).as<uint32_t>(), | ||||||
chain_plug->chain_config().max_reversible_blocks, | ||||||
min_blocks_distance); | ||||||
|
||||||
connections.init( std::chrono::milliseconds( options.at("p2p-keepalive-interval-ms").as<int>() * 2 ), | ||||||
|
@@ -4345,8 +4367,6 @@ namespace eosio { | |||||
} | ||||||
} | ||||||
|
||||||
chain_plug = app().find_plugin<chain_plugin>(); | ||||||
EOS_ASSERT( chain_plug, chain::missing_chain_plugin_exception, "" ); | ||||||
chain_id = chain_plug->get_chain_id(); | ||||||
fc::rand_pseudo_bytes( node_id.data(), node_id.data_size()); | ||||||
const controller& cc = chain_plug->chain(); | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shutdown when
fork_db_size() >= max_reversible_blocks
, so really we should have:I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check
max_reversible_blocks > fork_db_size
before doing subtract?