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

x/globalfee/ante: CombinedFeeRequirement could be simplified from many redundant else clauses by a simple composite check #1915

Closed
1 of 5 tasks
odeke-em opened this issue Nov 21, 2022 · 0 comments · Fixed by #1917

Comments

@odeke-em
Copy link
Contributor

Summary

Noticed during an audit that this code

for _, fee := range globalFees {
// min_gas_price denom in global fee
ok, c := minGasPrices.Find(fee.Denom)
if ok {
if c.Amount.GT(fee.Amount) {
allFees = append(allFees, c)
} else {
allFees = append(allFees, fee)
}
} else {
allFees = append(allFees, fee)
}
}
got a bunch of else clauses that translate essentially to:

if we already have a value c inside minGasPrices sharing the same denomination as the current fee, and if that value is greater than the current fee use c else just use fee

However, that expression is in a long winded check and makes code much harder to read unnecessarily
image

Suggestion

Just simply do

	for _, fee := range globalFees {
		// Check if there is already a global fee value denominated
     // in min_gas_price and greater than the current fee.
		ok, c := minGasPrices.Find(fee.Denom)
		if ok && c.Amount.GT(fee.Amount) {
			allFees = append(allFees, c)
		} else {
			allFees = append(allFees, fee)
		}
	}

Type

Impact

Less complex code, much easier to read, understand and maintain code

/cc @elias-orijtech


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
  • Is a spike necessary to map out how the issue should be approached?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant