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: Reconstruct headers from block nodes. #913

Merged
merged 1 commit into from
Feb 1, 2017

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Jan 31, 2017

This PR requires #911

This modifies the block node structure to include a couple of extra fields needed to be able to reconstruct the block header from a node, and exposes a new function from chain to fetch the block headers which takes advantage of the new functionality to reconstruct the headers from memory when possible. Finally, it updates both the p2p and RPC servers to make use of the new function.

This is useful since many of the block header fields need to be kept in order to form the block index anyways and storing the extra fields means the database does not have to be consulted when headers are requested if the associated node is still in memory.

The following timings show representative performance gains as measured from one system:

new: Time to fetch 100000 headers:   59ms
old: Time to fetch 100000 headers: 4783ms

@davecgh davecgh force-pushed the blockchain_blocknode_headers branch 2 times, most recently from d90458c to 10750f4 Compare January 31, 2017 22:24
@davecgh davecgh modified the milestone: 0.13.0 Jan 31, 2017
@davecgh davecgh force-pushed the blockchain_blocknode_headers branch from 10750f4 to 53d1270 Compare January 31, 2017 23:52
Copy link
Member

@dajohi dajohi left a comment

Choose a reason for hiding this comment

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

Nice! OK

@davecgh davecgh force-pushed the blockchain_blocknode_headers branch 5 times, most recently from 5f3ef4b to 5916954 Compare February 1, 2017 18:27
This modifies the block node structure to include a couple of extra
fields needed to be able to reconstruct the block header from a node,
and exposes a new function from chain to fetch the block headers which
takes advantage of the new functionality to reconstruct the headers from
memory when possible.  Finally, it updates both the p2p and RPC servers
to make use of the new function.

This is useful since many of the block header fields need to be kept in
order to form the block index anyways and storing the extra fields means
the database does not have to be consulted when headers are requested if
the associated node is still in memory.

The following timings show representative performance gains as measured
from one system:

new: Time to fetch 100000 headers:   59ms
old: Time to fetch 100000 headers: 4783ms
@davecgh davecgh merged commit 5916954 into btcsuite:master Feb 1, 2017
@davecgh davecgh deleted the blockchain_blocknode_headers branch February 1, 2017 18:30
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.

2 participants