Skip to content

Commit 4dea380

Browse files
authored
Merge pull request #194 from yaslama/chain-service-persist-to-disk
Add PersistToDisk property to ChainService
2 parents 62e95cd + 9586e92 commit 4dea380

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

neutrino.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ type Config struct {
575575
// BlockCacheSize is ignored.
576576
BlockCacheSize uint64
577577

578+
// persistToDisk indicates whether the filter should also be written
579+
// to disk in addition to the memory cache. For "normal" wallets, they'll
580+
// almost never need to re-match a filter once it's been fetched unless
581+
// they're doing something like a key import.
582+
PersistToDisk bool
583+
578584
// AssertFilterHeader is an optional field that allows the creator of
579585
// the ChainService to ensure that if any chain data exists, it's
580586
// compliant with the expected filter header state. If neutrino starts
@@ -602,6 +608,7 @@ type ChainService struct {
602608
FilterDB filterdb.FilterDatabase
603609
BlockHeaders headerfs.BlockHeaderStore
604610
RegFilterHeaders *headerfs.FilterHeaderStore
611+
persistToDisk bool
605612

606613
FilterCache *lru.Cache
607614
BlockCache *lru.Cache
@@ -694,6 +701,7 @@ func NewChainService(cfg Config) (*ChainService, error) {
694701
userAgentVersion: UserAgentVersion,
695702
nameResolver: nameResolver,
696703
dialer: dialer,
704+
persistToDisk: cfg.PersistToDisk,
697705
}
698706
s.workManager = query.New(&query.Config{
699707
ConnectedPeers: s.ConnectedPeers,

query.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ type queryOptions struct {
7878
// it's run in a goroutine.
7979
doneChan chan<- struct{}
8080

81-
// persistToDisk indicates whether the filter should also be written
82-
// to disk in addition to the memory cache. For "normal" wallets, they'll
83-
// almost never need to re-match a filter once it's been fetched unless
84-
// they're doing something like a key import.
85-
persistToDisk bool
86-
8781
// optimisticBatch indicates whether we expect more calls to follow,
8882
// and that we should attempt to batch more items with the query such
8983
// that they can be cached, avoiding the extra round trip.
@@ -179,14 +173,6 @@ func DoneChan(doneChan chan<- struct{}) QueryOption {
179173
}
180174
}
181175

182-
// PersistToDisk allows the caller to tell that the filter should be kept
183-
// on disk once it's found.
184-
func PersistToDisk() QueryOption {
185-
return func(qo *queryOptions) {
186-
qo.persistToDisk = true
187-
}
188-
}
189-
190176
// OptimisticBatch allows the caller to tell that items following the requested
191177
// one should be included in the query.
192178
func OptimisticBatch() QueryOption {
@@ -792,7 +778,7 @@ func (s *ChainService) handleCFiltersResponse(q *cfiltersQuery,
792778

793779
qo := defaultQueryOptions()
794780
qo.applyQueryOptions(q.options...)
795-
if qo.persistToDisk {
781+
if s.persistToDisk {
796782
err = s.FilterDB.PutFilter(
797783
&response.BlockHash, gotFilter, dbFilterType,
798784
)

0 commit comments

Comments
 (0)