-
Notifications
You must be signed in to change notification settings - Fork 992
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
fix: find common header between the header chain and the current body chain #3033
Conversation
I don't fully understand what you mean here by "implicit meaning of current header chain". We check for
i.e. If block |
chain/src/chain.rs
Outdated
current = self.get_previous_header(&header); | ||
} | ||
|
||
// Go through the header chain reversely to get all those headers after oldest_height. | ||
if let Some(hs) = hashes { | ||
let mut current = self.get_block_header(&header_head.last_block_h); |
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 see we are redefining current in this PR here, but I don't think we need to do this. Earlier this is body_head
and now this is redefined based on header_head
.
Edit: We do need to do this, but I think we should make it explicit in terms of naming - current
is too ambiguous, particularly when we reuse it later on for a different purpose.
I think it should consistently be based on a header from the db starting at header_head
and working back until we find one that also refers to a full block in our db.
Ok I think I get it now. Let me think through what you are doing here a bit more.
@@ -791,11 +791,11 @@ impl Chain { | |||
let mut oldest_height = 0; | |||
let mut oldest_hash = ZERO_HASH; | |||
|
|||
let mut current = self.get_block_header(&header_head.last_block_h); | |||
let mut current = self.get_block_header(&body_head.last_block_h); |
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.
Lets rename this usage of current to make it clearer that we want to check for headers in our db based on body_head
.
This is a 2 step process.
- start with
head
(head of the full block chain)- if we do not have a full block in the db for this
head
then its an error - if we do not have the header in the db for this
head
then its an error
- if we do not have a full block in the db for this
- traverse back through the full block chain from
head
until we find a header that "is on current chain"- this is our "fork point" between existing header chain and full block chain
- now we want to traverse back through our header chain from
header_head
back to this fork point- these are the blocks that we need to request (we have the header but not the full block)
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 put some of yours comments to the source code comments, and renamed the 2nd current
.
pls let me whether it's better now.
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.
Yes - thanks for finding and fixing this.
This PR fixes the issue and better explains how we are identifying which blocks to request.
Fix of #3030
The current
is_on_current_chain()
function has an implicit meaning of currentheader
chain, don't remember when we did this change, anyway it impacts the logic here to find the header common between the header chain and the current body chain.