Skip to content

Commit

Permalink
fix: Municipal Inlf. Cache: null ptr in GetInflation(...) (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbukva committed Sep 5, 2023
1 parent 43f6e51 commit 5cecd19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ golangci_lint_cmd=$(DOCKER) run --rm -v $(CURDIR):/work -w /work $(containerGola

lint: lint-go-diff
@#if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLint}$$"; then docker start -a $(containerMarkdownLint); else docker run --name $(containerMarkdownLint) -i -v "$(CURDIR):/work" $(markdownLintImage); fi
docker run -i --rm -v "$(CURDIR):/work" $(containerMarkdownLintImage) .
docker run -i --rm -v "$(CURDIR):/work" $(containerMarkdownLintImage) -- .

lint-fix:
@#if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerMarkdownLintFix}$$"; then docker start -a $(containerMarkdownLintFix); else docker run --name $(containerMarkdownLintFix) -i -v "$(CURDIR):/work" $(markdownLintImage) . --fix; fi
Expand Down
4 changes: 2 additions & 2 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func HandleMunicipalInflation(minter *types.Minter, params *types.Params, ctx *s
// gather supply value & calculate number of new tokens created from relevant inflation
totalDenomSupply := k.BankKeeper.GetSupply(*ctx, pair.Denom)

cacheItem, exists := cache.GMunicipalInflationCache.GetInflation(pair.Denom)
cacheItem := cache.GMunicipalInflationCache.GetInflation(pair.Denom)

if !exists {
if cacheItem == nil {
panic(fmt.Errorf("numicipal inflation: missing cache item for the \"%s\" denomination", pair.Denom))
}

Expand Down
11 changes: 8 additions & 3 deletions x/mint/cache/municipal_inflation_cahe.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ func (cache *MunicipalInflationCache) RefreshIfNecessary(inflations *[]*types.Mu
}
}

func (cache *MunicipalInflationCache) GetInflation(denom string) (MunicipalInflationCacheItem, bool) {
func (cache *MunicipalInflationCache) GetInflation(denom string) *MunicipalInflationCacheItem {
val := cache.internal.Load()
if val == nil {
return MunicipalInflationCacheItem{}, false
return nil
}

infl, exists := val.(*MunicipalInflationCacheInternal).inflations[denom]
return *infl, exists

if exists {
return infl
}

return nil
}

func (cache *MunicipalInflationCache) GetOriginal() *[]*types.MunicipalInflationPair {
Expand Down
4 changes: 2 additions & 2 deletions x/mint/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (k Keeper) MunicipalInflation(c context.Context, req *types.QueryMunicipalI
return &types.QueryMunicipalInflationResponse{Inflations: *cache.GMunicipalInflationCache.GetOriginal()}, nil
}

infl, exists := cache.GMunicipalInflationCache.GetInflation(denom)
if !exists {
infl := cache.GMunicipalInflationCache.GetInflation(denom)
if infl == nil {
return nil, fmt.Errorf("there is no municipal inflation defined for requested \"%s\" denomination", denom)
}

Expand Down

0 comments on commit 5cecd19

Please sign in to comment.