Merge pull request #1208 from cfromknecht/cache-chainview-filter-entries

routing/chainview/neutrino: cache filter entries
This commit is contained in:
Olaoluwa Osuntokun 2018-05-09 16:31:18 -07:00 committed by GitHub
commit 3d26748906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,7 +42,7 @@ type CfFilteredChainView struct {
// chainFilter is the // chainFilter is the
filterMtx sync.RWMutex filterMtx sync.RWMutex
chainFilter map[wire.OutPoint]struct{} chainFilter map[wire.OutPoint][]byte
quit chan struct{} quit chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
@ -62,7 +62,7 @@ func NewCfFilteredChainView(node *neutrino.ChainService) (*CfFilteredChainView,
blockQueue: newBlockEventQueue(), blockQueue: newBlockEventQueue(),
quit: make(chan struct{}), quit: make(chan struct{}),
rescanErrChan: make(chan error), rescanErrChan: make(chan error),
chainFilter: make(map[wire.OutPoint]struct{}), chainFilter: make(map[wire.OutPoint][]byte),
p2pNode: node, p2pNode: node,
}, nil }, nil
} }
@ -250,9 +250,8 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB
// filters. // filters.
c.filterMtx.RLock() c.filterMtx.RLock()
relevantPoints := make([][]byte, 0, len(c.chainFilter)) relevantPoints := make([][]byte, 0, len(c.chainFilter))
for op := range c.chainFilter { for _, filterEntry := range c.chainFilter {
opBytes := builder.OutPointToFilterEntry(op) relevantPoints = append(relevantPoints, filterEntry)
relevantPoints = append(relevantPoints, opBytes)
} }
c.filterMtx.RUnlock() c.filterMtx.RUnlock()
@ -324,7 +323,7 @@ func (c *CfFilteredChainView) UpdateFilter(ops []wire.OutPoint,
// UTXO's, ignoring duplicates in the process. // UTXO's, ignoring duplicates in the process.
c.filterMtx.Lock() c.filterMtx.Lock()
for _, op := range ops { for _, op := range ops {
c.chainFilter[op] = struct{}{} c.chainFilter[op] = builder.OutPointToFilterEntry(op)
} }
c.filterMtx.Unlock() c.filterMtx.Unlock()