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

blockchain: Generalize and optimize chain reorg. #997

Merged
merged 1 commit into from
Jan 31, 2018

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Jan 31, 2018

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.

@@ -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() {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@davecgh davecgh force-pushed the blockchain_reorganizechain_cleanup branch 3 times, most recently from 69a8ee1 to 0d12de8 Compare January 31, 2018 16:24
Copy link
Contributor

@jolan jolan left a 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.
@davecgh davecgh force-pushed the blockchain_reorganizechain_cleanup branch from 0d12de8 to 31caca1 Compare January 31, 2018 18:24
@davecgh davecgh merged commit 31caca1 into decred:master Jan 31, 2018
@davecgh davecgh deleted the blockchain_reorganizechain_cleanup branch January 31, 2018 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants