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

LRU block cache #88

Merged
merged 14 commits into from
Aug 23, 2018
Merged

LRU block cache #88

merged 14 commits into from
Aug 23, 2018

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Aug 22, 2018

This PR builds on top of #72, adding an in-memory block cache for block received from peers.

@halseth

neutrino.go Outdated
@@ -500,6 +500,11 @@ type ChainService struct {
BlockHeaders *headerfs.BlockHeaderStore
RegFilterHeaders *headerfs.FilterHeaderStore

// queryPeers will be called to send messages to one or more peers,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good initial start. Ideally in the end we make the set of query methods into an interface so we can easily mock them out if needed. It'll also allow us to test the set of query behavior w/o actually having an active network connection.


// Size returns size of this block in bytes.
func (c *CacheableBlock) Size() (uint64, error) {
f, err := c.Block.Bytes()
Copy link
Member Author

Choose a reason for hiding this comment

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

Can instead use SerializeSize here in order to not have to re-encode the entire thing.

query.go Outdated
@@ -905,9 +905,21 @@ func (s *ChainService) GetBlockFromNetwork(blockHash chainhash.Hash,
invType = wire.InvTypeBlock
}

// Create an inv vector for getting this block.
inv := wire.NewInvVect(invType, &blockHash)
Copy link
Member Author

Choose a reason for hiding this comment

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

Why use an inv vector rather than the hash of the block for the cache?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 70.041% when pulling e89b367 on Roasbeef:block-filter-cache into 3894831 on lightninglabs:master.

@Roasbeef Roasbeef merged commit d24ca51 into lightninglabs:master Aug 23, 2018
This was referenced Aug 23, 2018
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