Skip to content

Commit

Permalink
feat: close pov api goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen221 committed Apr 19, 2021
1 parent 98b3aa4 commit 89a7a26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rpc/api/pov.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type PovApi struct {
dayIndex uint32
trieMap *sync.Map
cc *chainctx.ChainContext
ctx context.Context
}

type PovStatus struct {
Expand Down Expand Up @@ -178,6 +179,7 @@ func NewPovApi(ctx context.Context, cfg *config.Config, l ledger.Store, eb event
cc: cc,
trieMap: new(sync.Map),
dayIndex: 0,
ctx: ctx,
}
go api.initTrieMap()
return api
Expand All @@ -190,6 +192,8 @@ func (api *PovApi) initTrieMap() {
select {
case <-vTicker.C:
api.initTrie()
case <-api.ctx.Done():
return
}
}
}
Expand Down Expand Up @@ -223,6 +227,7 @@ func (api *PovApi) initTrie() {
notStatHeightEnd := latestHeader.GetHeight()
var height uint64
loopCount := 0
simpleTrie := trie.NewSimpleTrieNodePool()
for height = notStatHeightStart; height <= notStatHeightEnd; height += common.DPosOnlinePeriod {
loopCount++
header, _ := api.l.GetPovHeaderByHeight(height)
Expand All @@ -232,7 +237,7 @@ func (api *PovApi) initTrie() {

stateHash := header.GetStateHash()
if _, ok := api.trieMap.Load(stateHash); !ok {
stateTrie := trie.NewTrie(api.l.DBStore(), &stateHash, nil)
stateTrie := trie.NewTrie(api.l.DBStore(), &stateHash, simpleTrie)
if stateTrie != nil {
api.trieMap.Store(stateHash, stateTrie)
}
Expand Down

0 comments on commit 89a7a26

Please sign in to comment.