-
Notifications
You must be signed in to change notification settings - Fork 203
[Access & Execution] Add flag to disable bitswap bloom cache #8227
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
base: master
Are you sure you want to change the base?
Changes from all commits
9c3c5d9
8e70d15
15450bf
bbc700f
01324d6
27f6a59
21f130f
46a2a81
9e034c8
3a43344
1752bbd
4d370bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ var _ component.Component = (*blobService)(nil) | |
| type BlobServiceConfig struct { | ||
| ReprovideInterval time.Duration // the interval at which the DHT provider entries are refreshed | ||
| BitswapOptions []bitswap.Option // options to pass to the Bitswap service | ||
| UseBloomCache bool // if true, use the bloom cache (cached blockstore), otherwise use plain blockstore | ||
| } | ||
|
Comment on lines
55
to
59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cd network/p2p/blob && wc -l blob_service.goRepository: onflow/flow-go Length of output: 77 🏁 Script executed: cat -n network/p2p/blob/blob_service.go | head -160Repository: onflow/flow-go Length of output: 6605 🏁 Script executed: # Verify the exact line where blockStore is used in CachedBlockstore call
sed -n '141,151p' network/p2p/blob/blob_service.goRepository: onflow/flow-go Length of output: 354 🏁 Script executed: # Double-check WithRateLimit implementation to confirm it modifies bs.blockStore
sed -n '95,100p' network/p2p/blob/blob_service.goRepository: onflow/flow-go Length of output: 303 🏁 Script executed: # Verify WithParentBlobService also modifies bs.blockStore
sed -n '75,80p' network/p2p/blob/blob_service.goRepository: onflow/flow-go Length of output: 334 Fix CachedBlockstore to wrap the final blockstore after applying options When
Change line 144 to use Proposed fix if bs.config.UseBloomCache {
cachedBlockStore, err := blockstore.CachedBlockstore(
context.Background(),
- blockStore,
+ bs.blockStore,
blockstore.DefaultCacheOpts(),
)
if err != nil {
return nil, fmt.Errorf("failed to create cached blockstore: %w", err)
}
bs.blockStore = cachedBlockStore
}
🤖 Prompt for AI Agents |
||
|
|
||
| // WithReprovideInterval sets the interval at which DHT provider entries are refreshed | ||
|
|
@@ -98,6 +99,17 @@ func WithRateLimit(r float64, b int) network.BlobServiceOption { | |
| } | ||
| } | ||
|
|
||
| // WithUseBloomCache enables or disables the bloom cache. | ||
| // When enabled (true), uses a cached blockstore with bloom filter (default behavior). | ||
| // When disabled (false), uses a plain blockstore instead, avoiding the CPU cost of building | ||
| // the bloom filter on startup by scanning all keys. Pebble's built-in bloom filters | ||
| // (persisted in SSTables) are still used for efficient lookups. | ||
| func WithUseBloomCache(use bool) network.BlobServiceOption { | ||
| return func(bs network.BlobService) { | ||
| bs.(*blobService).config.UseBloomCache = use | ||
| } | ||
| } | ||
|
|
||
| // NewBlobService creates a new BlobService. | ||
| func NewBlobService( | ||
| host host.Host, | ||
|
|
@@ -109,26 +121,35 @@ func NewBlobService( | |
| opts ...network.BlobServiceOption, | ||
| ) (*blobService, error) { | ||
| bsNetwork := bsnet.NewFromIpfsHost(host, r, bsnet.Prefix(protocol.ID(prefix))) | ||
| blockStore, err := blockstore.CachedBlockstore( | ||
| context.Background(), | ||
| blockstore.NewBlockstore(ds), | ||
| blockstore.DefaultCacheOpts(), | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create cached blockstore: %w", err) | ||
| } | ||
|
|
||
| blockStore := blockstore.NewBlockstore(ds) | ||
|
|
||
| bs := &blobService{ | ||
| prefix: prefix, | ||
| config: &BlobServiceConfig{ | ||
| ReprovideInterval: DefaultReprovideInterval, | ||
| UseBloomCache: true, // default: use bloom cache | ||
| }, | ||
| blockStore: blockStore, | ||
| } | ||
|
|
||
| // Apply options before creating blockstore, as UseBloomCache affects blockstore creation | ||
| for _, opt := range opts { | ||
| opt(bs) | ||
| } | ||
|
|
||
| if bs.config.UseBloomCache { | ||
| cachedBlockStore, err := blockstore.CachedBlockstore( | ||
| context.Background(), | ||
| blockStore, | ||
| blockstore.DefaultCacheOpts(), | ||
| ) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create cached blockstore: %w", err) | ||
| } | ||
| bs.blockStore = cachedBlockStore | ||
| } | ||
|
|
||
| cm := component.NewComponentManagerBuilder(). | ||
| AddWorker(func(ctx irrecoverable.SignalerContext, ready component.ReadyFunc) { | ||
| btswp := bitswap.New(ctx, bsNetwork, bs.blockStore, bs.config.BitswapOptions...) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases also passed when I changed the default to
false.