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

multi: Add batched cfilter fetching messages #3211

Merged
merged 4 commits into from May 13, 2024

Conversation

matheusd
Copy link
Member

@matheusd matheusd commented Nov 8, 2023

Close #3206

This adds the getcfsv2/cfiltersv2 set of messages, intended to be used by SPV clients to fetch batches of version 2 committed filters during their initial sync process.

Summary of changes:

  • Record how max (worst) cfilter sizes may be calculated for various scenarios for the current network parameters and future proof them by adding a test that breaks if any of the parameters change
  • Add getcfsv2/cfiltersv2 wire message and add a new protocol version that supports them
  • Add an internal blockchain function that fetches batches of cfilters
  • Hook the peer and server packages to respond to the getcfsv2 message

wire/message.go Outdated Show resolved Hide resolved
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Sorry it took so long to review this. I totally let it fall through the cracks.

I've reviewed the first commit and this is looking super nice overall! I really appreciate the effort put into make it easy to review and also determining all the worst case scenarios and adding tests to exercise them.

I figured I'd push the review thus far so you can start addressing the various (minor) points.

Also, please rebase this to the latest master. I've done it locally for testing, but needs to be done on the PR too.

gcs/blockcf2/maxsize_test.go Outdated Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Show resolved Hide resolved
gcs/gcs.go Outdated Show resolved Hide resolved
gcs/gcs.go Outdated Show resolved Hide resolved
wire/protocol.go Outdated Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Outdated Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Outdated Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Outdated Show resolved Hide resolved
gcs/blockcf2/maxsize_test.go Outdated Show resolved Hide resolved
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Review for the second commit "wire: Add msgs to get batch of cfilters".

wire/msgcfiltersv2.go Outdated Show resolved Hide resolved
wire/msgcfiltersv2.go Outdated Show resolved Hide resolved
wire/msgcfiltersv2.go Outdated Show resolved Hide resolved
wire/msgcfiltersv2.go Outdated Show resolved Hide resolved
wire/msgcfiltersv2.go Outdated Show resolved Hide resolved
wire/msggetcfiltersv2.go Outdated Show resolved Hide resolved
wire/msggetcfiltersv2.go Outdated Show resolved Hide resolved
wire/msggetcfiltersv2.go Outdated Show resolved Hide resolved
wire/msggetcfiltersv2.go Outdated Show resolved Hide resolved
wire/msggetcfiltersv2_test.go Outdated Show resolved Hide resolved
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Review for the third commit "blockchain: Add function to locate multiple cfilters".

internal/blockchain/chainio.go Outdated Show resolved Hide resolved
internal/blockchain/chainio.go Outdated Show resolved Hide resolved
internal/blockchain/headercmt.go Outdated Show resolved Hide resolved
internal/blockchain/headercmt.go Show resolved Hide resolved
internal/blockchain/headercmt.go Outdated Show resolved Hide resolved
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

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

Review complete. Really nice job overall. Avoiding the calls to gcs.FromBytesV2 on all of the filters will save quite a few allocs which will not only be a lot faster, but it'll put less pressure on the serving nodes as well.

This will be helpful in determining the max number of cfilters to return
in a future batched getcfilter message.

This will also nail down the maximum size of the filter based on the
constants used throughout the project, such that if any of them changes,
causing the max cfilter size to change, a test will break indicating the
need to review any code paths that assume a max cfilter size.
@matheusd
Copy link
Member Author

Thank you for the review!

I believe I addressed all the review items.

wire/msggetcfiltersv2.go Outdated Show resolved Hide resolved
@davecgh
Copy link
Member

davecgh commented May 13, 2024

Reviewed all the updates and they look good. The only thing remaining is my latest comment and then I'll get this merged. 💯

This adds the getcfsv2 and cfiltersv2 messages. These messages are
intended to allow nodes in the P2P network to request and receive a
batch of version 2 committed filters that span multiple sequential
blocks in a chain.

These messages are intended to be used when syncing SPV clients, which
require requesting all committed filters on the current main chain and
currently use a large number of getcfilter/cfilter messages.

One of the critical issues in the design for these messages is the
MaxCFiltersV2PerBatch constant, which establishes an upper bound on the
max number of cfilters requested and replied.  The current value of this
constant was decided based on the max block size for all of the
currently deployed networks, the max possible filter size for
transactions in such a block and the max P2P message size.

A runtime check is added to ensure any changes to the constants that
were involved in deciding this number trigger a panic so that this bound
is verified and, if needed, a new protocol version is introduced to
update it.  This check is meant to guard against inadvertedly changing
the assumptions that went into establishing this bound without reviewing
it.
This function will be used to reply to the recently introduced getcfsv2
P2P message.

The LocateCFiltersV2 function fetches a batch of cfilters from the
database and encodes it in a wire.CFiltersV2 message, ready to be sent
to remote peers.
This adds the appropriate processing to the peer and server structs to
respond to the recently introduced getcfsv2 message.  It also bumps the
peer and server max supported protocol versions to version 10
(BatchedCFiltersV2Version).

This message queries the chain for a batch of committed filters spanning
a set of sequential blocks and will be used by SPV clients to fetch
committed filters during their initial sync process.
@davecgh davecgh merged commit f308956 into decred:master May 13, 2024
2 checks passed
@matheusd matheusd deleted the test-multi-cf branch May 13, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wire protocol change Discussion and pull requests regarding items that require changes to the wire protocol.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GetMultipleCFiltersV2 P2P message
2 participants