Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Municipal Inlf. Cache: null ptr in GetInflation(...) #168

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading