From 3d6e7303683251715d672b5f92f12fa4fd84644a Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Thu, 4 Feb 2021 11:35:24 -0700 Subject: [PATCH] address issues from audit (#793) --- x/issuance/keeper/issuance.go | 4 +--- x/issuance/keeper/supply.go | 21 +++++++++++++-------- x/issuance/types/params.go | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/x/issuance/keeper/issuance.go b/x/issuance/keeper/issuance.go index 3eed68d7..695f4107 100644 --- a/x/issuance/keeper/issuance.go +++ b/x/issuance/keeper/issuance.go @@ -136,9 +136,7 @@ func (k Keeper) UnblockAddress(ctx sdk.Context, denom string, owner, addr sdk.Ac } blocked, i := k.checkBlockedAddress(asset, addr) if !blocked { - if blocked { - return sdkerrors.Wrapf(types.ErrAccountAlreadyUnblocked, "address: %s", addr) - } + return sdkerrors.Wrapf(types.ErrAccountAlreadyUnblocked, "address: %s", addr) } blockedAddrs := k.removeBlockedAddress(asset.BlockedAddresses, i) diff --git a/x/issuance/keeper/supply.go b/x/issuance/keeper/supply.go index 89e6bbc3..9ae24159 100644 --- a/x/issuance/keeper/supply.go +++ b/x/issuance/keeper/supply.go @@ -56,17 +56,22 @@ func (k Keeper) UpdateTimeBasedSupplyLimits(ctx sdk.Context) { if !found { supply = k.CreateNewAssetSupply(ctx, asset.Denom) } - if asset.RateLimit.Active { - if asset.RateLimit.TimePeriod <= supply.TimeElapsed+timeElapsed { - supply.TimeElapsed = time.Duration(0) - supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt()) - } else { - supply.TimeElapsed = supply.TimeElapsed + timeElapsed - } - } else { + if !asset.RateLimit.Active { + // rate limiting is not active, reset supply supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt()) supply.TimeElapsed = time.Duration(0) + k.SetAssetSupply(ctx, supply, asset.Denom) + continue } + if asset.RateLimit.TimePeriod > supply.TimeElapsed+timeElapsed { + // rate limiting is active, the rate-limiting period has not expired + supply.TimeElapsed = supply.TimeElapsed + timeElapsed + k.SetAssetSupply(ctx, supply, asset.Denom) + continue + } + // rate limiting is active, the rate-limiting period has expired, and is now reset + supply.TimeElapsed = time.Duration(0) + supply.CurrentSupply = sdk.NewCoin(asset.Denom, sdk.ZeroInt()) k.SetAssetSupply(ctx, supply, asset.Denom) } k.SetPreviousBlockTime(ctx, ctx.BlockTime()) diff --git a/x/issuance/types/params.go b/x/issuance/types/params.go index e14e7bef..e4720de4 100644 --- a/x/issuance/types/params.go +++ b/x/issuance/types/params.go @@ -114,7 +114,7 @@ func (a Asset) String() string { a.Owner, a.Paused, a.Denom, a.BlockedAddresses, a.RateLimit) } -// Assets array of Asset +// Assets slice of Asset type Assets []Asset // Validate checks if all assets are valid and there are no duplicate entries