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: Cleanup and optimize stake node logic. #1504

Merged

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Oct 19, 2018

This reworks the stake node handling logic a bit to clean it up, slightly optimize it, and to make it easier to decouple the chain processing and connection code from the download logic in the future.

To accomplish this, the fetchStakeNode dependence on the getReorganizeNodes function is removed in favor of directly iterating the block nodes in the function as needed. Not only is this more efficient, it also allows the function to return stake nodes for branches regardless of their validation status. Currently, this is irrelevant due to the connection and download logic being tightly coupled. However, it will be necessary in the future when those are separated.

Also, the flushing and pruning logic is modified to no longer rely on the download logic being tightly coupled to the the connection logic. In particular, a new function named flushBlockIndex is added as a wrapper to the index flush function which populates stake information in a node before flushing it to the database as needed, and all flushing invocations use the wrapper instead.

Finally, the stakeUndoData field is removed since it is only used to avoid some database loads on reorgs that are large enough to exceed the pruning depth, which never happens in practice anyway, so there is no point in using up extra memory for it.

@davecgh davecgh added this to the 1.4.0 milestone Oct 19, 2018
@davecgh davecgh force-pushed the blockchain_cleanup_optimize_stake_node_handling branch from 6ce640b to fa1e632 Compare October 19, 2018 08:33
}

// Calculate block number for where new tickets matured from and retrieve
// this block from DB or in memory if it's a sidechain.
// it block from DB.
Copy link
Member

Choose a reason for hiding this comment

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

s/it/its

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

This reworks the stake node handling logic a bit to clean it up,
slightly optimize it, and to make it easier to decouple the chain
processing and connection code from the download logic in the future.

To accomplish this, the fetchStakeNode dependence on the
getReorganizeNodes function is removed in favor of directly iterating
the block nodes in the function as needed.  Not only is this more
efficient, it also allows the function to return stake nodes for
branches regardless of their validation status.  Currently, this is
irrelevant due to the connection and download logic being tightly
coupled.  However, it will be necessary in the future when those are
separated.

Also, the flushing and pruning logic is modified to no longer rely on
the download logic being tightly coupled to the the connection logic.
In particular, a new function named flushBlockIndex is added as a
wrapper to the index flush function which populates stake information in
a node before flushing it to the database as needed, and all flushing
invocations use the wrapper instead.

Finally, the stakeUndoData field is removed since it is only used to
avoid some database loads on reorgs that are large enough to exceed the
pruning depth, which never happens in practice anyway, so there is no
point in using up extra memory for it.
@davecgh davecgh force-pushed the blockchain_cleanup_optimize_stake_node_handling branch from fa1e632 to 20631a1 Compare October 19, 2018 17:05
@davecgh davecgh merged commit 20631a1 into decred:master Oct 19, 2018
@davecgh davecgh deleted the blockchain_cleanup_optimize_stake_node_handling branch October 19, 2018 19:08
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.

4 participants