Clear all request internal cache when node is stopped

This commit is contained in:
Dmitry 2019-02-26 14:55:01 +02:00 committed by Dmitry Shulyak
parent f47187b00b
commit ccce8b9a80
2 changed files with 13 additions and 4 deletions

View File

@ -22,11 +22,11 @@ type requestMeta struct {
// NewRequestsRegistry creates instance of the RequestsRegistry and returns pointer to it.
func NewRequestsRegistry(delay time.Duration) *RequestsRegistry {
return &RequestsRegistry{
delay: delay,
uidToTopics: map[common.Hash]common.Hash{},
byTopicsHash: map[common.Hash]requestMeta{},
r := &RequestsRegistry{
delay: delay,
}
r.Clear()
return r
}
// RequestsRegistry keeps map for all requests with timestamp when they were made.
@ -73,6 +73,14 @@ func (r *RequestsRegistry) Unregister(uid common.Hash) {
}
}
// Clear recreates all structures used for caching requests.
func (r *RequestsRegistry) Clear() {
r.mu.Lock()
defer r.mu.Unlock()
r.uidToTopics = map[common.Hash]common.Hash{}
r.byTopicsHash = map[common.Hash]requestMeta{}
}
// topicsToHash returns non-cryptographic hash of the topics.
func topicsToHash(topics []whisper.TopicType) common.Hash {
hash := fnv.New32()

View File

@ -302,6 +302,7 @@ func (s *Service) Stop() error {
if s.config.EnableLastUsedMonitor {
s.lastUsedMonitor.Stop()
}
s.requestsRegistry.Clear()
s.envelopesMonitor.Stop()
s.mailMonitor.Stop()
return nil