-
Notifications
You must be signed in to change notification settings - Fork 69
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
[3.1] net_plugin improve block latency calculation #676
Conversation
…atency indicates 1 block latency.
The PR title doesn't seem quite right to me. |
How so? |
Sorry if I wasn't clear. I don't find it obvious why the change reduces the amount of handshake messages. From my uninformed viewpoint, it only seem to make the message more accurate. |
Ah, good point. I'll try to add some info about how this accomplishes the stated. |
I added some additional info to the PR description. @greg7mdp |
@@ -1813,8 +1813,8 @@ namespace eosio { | |||
//----------------------------- | |||
|
|||
if (head_id == msg.head_id) { | |||
peer_ilog( c, "handshake lib ${lib}, head ${head}, head id ${id}.. sync 0", | |||
("lib", msg.last_irreversible_block_num)("head", msg.head_num)("id", msg.head_id.str().substr(8,16)) ); | |||
peer_ilog( c, "handshake lib ${lib}, head ${head}, head id ${id}.. sync 0, lib ${l}", |
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.
Can we factorize these 5 peer_ilog
as in:
auto log_handshake = [&](uint32_t sync) {
peer_ilog( c, "handshake lib ${lib}, head ${head}, head id ${id}.. sync ${sync}, head ${h}, lib ${l}",
("lib", msg.last_irreversible_block_num)("head", msg.head_num)("id", msg.head_id.str().substr(8,16))
("sync", sync)("h", head)("l", lib_num) );
};
if (head_id == msg.head_id) {
log_handshake(0);
c->syncing = false;
notice_message note;
note.known_blocks.mode = none;
note.known_trx.mode = catch_up;
note.known_trx.pending = 0;
c->enqueue( note );
return;
}
if (head < msg.last_irreversible_block_num) {
log_handshake(1);
c->syncing = false;
if (c->sent_handshake_count > 0) {
c->send_handshake();
}
return;
}
if (lib_num > msg.head_num + nblk_combined_latency) {
log_handshake(2);
if (msg.generation > 1 || c->protocol_version > proto_base) {
notice_message note;
note.known_trx.pending = lib_num;
note.known_trx.mode = last_irr_catch_up;
note.known_blocks.mode = last_irr_catch_up;
note.known_blocks.pending = head;
c->enqueue( note );
}
c->syncing = true;
return;
}
if (head + nblk_combined_latency < msg.head_num ) {
log_handshake(3);
c->syncing = false;
verify_catchup(c, msg.head_num, msg.head_id);
return;
} else if(head >= msg.head_num + nblk_combined_latency) {
log_handshake(4);
...
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.
I prefer not to as you lose line #.
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.
fair enough! Although you could replace the lambda with a macro, as in:
#define log_handshake(sync) \
peer_ilog( c, "handshake lib ${lib}, head ${head}, head id ${id}.. sync ${sync}, head ${h}, lib ${l}",\
("lib", msg.last_irreversible_block_num)("head", msg.head_num)("id", msg.head_id.str().substr(8,16))\
("sync", sync)("h", head)("l", lib_num) );
but maybe we should leave good enough alone :-).
Remove the +1 to the block latency calculation otherwise even 0ms latency indicates 1 block latency instead of 0. The +1 makes the comparisons of
head
andmsg.head
in theif-else
off by 1 when there is no latency.Added additional logging so that issues like #588 are easier to debug.
Before:
After: