-
Notifications
You must be signed in to change notification settings - Fork 300
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
blockchain: Generalize and optimize chain reorg. #997
blockchain: Generalize and optimize chain reorg. #997
Conversation
5130733
to
1a42300
Compare
blockchain/chain.go
Outdated
@@ -1286,8 +1346,11 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List, flags | |||
// at least a couple of ways accomplish that rollback, but both involve | |||
// tweaking the chain and/or database. This approach catches these | |||
// issues before ever modifying the chain. | |||
var topBlock *blockNode | |||
for e := attachNodes.Front(); e != nil; e = e.Next() { | |||
for i, e := 0, attachNodes.Front(); e != nil; i, e = i+1, e.Next() { |
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.
Why is i necessary here?
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.
Nice catch. It's actually used in the next PR. I originally wrote the whole series together, but then split them up for easier review. I'll move it to the proper commit that uses it.
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.
Gotcha, thanks for the clarification.
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.
Done
69a8ee1
to
0d12de8
Compare
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.
tOK
This generalizes and optimizes the reorganize chain function to take advantage of the linear structure of the nodes being attached and detached in order to avoid reloading the parent blocks as well as allow it to rewind the chain in the case no attach nodes are provided or extend the chain in the case no detach nodes are provided. It also adds several assertions to ensure the assumptions about the state hold and generally cleans up the function for code consistency.
0d12de8
to
31caca1
Compare
This generalizes and optimizes the reorganize chain function to take advantage of the linear structure of the nodes being attached and detached in order to avoid reloading the parent blocks as well as allow it to rewind the chain in the case no attach nodes are provided or extend the chain in the case no detach nodes are provided.
It also adds several assertions to ensure the assumptions about the state hold and generally cleans up the function for code consistency.