Skip to content

Commit

Permalink
Merge branch 'main' into taztingo/1468-docgen-command
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Witkowski committed Sep 18, 2023
2 parents 8beeafb + c24e1de commit 46ed503
Show file tree
Hide file tree
Showing 26 changed files with 364 additions and 178 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
Funds with a hold on them cannot be transferred until the hold is removed.
Management of holds is internal, but there are queries for looking up holds on accounts.
Holds are also reflected in the `x/bank` module's `SpendableBalances` query.
* Add new MaxSupply param to marker module and deprecate MaxTotalSupply. [#1292](https://github.com/provenance-io/provenance/issues/1292).

### Improvements

Expand All @@ -70,6 +71,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Fix for incorrect resource-id type casting on contract specification [#1647](https://github.com/provenance-io/provenance/issues/1647).
* Allow restricted coins to be quarantined [#1626](https://github.com/provenance-io/provenance/issues/1626).
* Prevent marker forced transfers from module accounts [#1626](https://github.com/provenance-io/provenance/issues/1626).
* Change config load order so custom.toml can override other config. [#1262](https://github.com/provenance-io/provenance/issues/1262)

### Client Breaking

Expand Down
1 change: 1 addition & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
// Adjusted marker operations to a cumulative weight of 100
DefaultWeightMsgAddMarker int = 30
DefaultWeightMsgChangeStatus int = 10
DefaultWeightMsgFinalize int = 10
DefaultWeightMsgAddAccess int = 10
DefaultWeightMsgAddFinalizeActivateMarker int = 10
DefaultWeightMsgAddMarkerProposal int = 40
Expand Down
14 changes: 14 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

icqtypes "github.com/strangelove-ventures/async-icq/v6/types"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/baseapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -110,6 +112,7 @@ var upgrades = map[string]appUpgrade{

removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)

return vm, nil
},
Expand All @@ -128,6 +131,7 @@ var upgrades = map[string]appUpgrade{

removeInactiveValidatorDelegations(ctx, app)
setupICQ(ctx, app)
updateMaxSupply(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -326,3 +330,13 @@ func setupICQ(ctx sdk.Context, app *App) {
app.ICQKeeper.SetParams(ctx, icqtypes.NewParams(true, []string{"/provenance.oracle.v1.Query/Oracle"}))
ctx.Logger().Info("Done updating ICQ params")
}

// updateMaxSupply sets the value of max supply to the current value of MaxTotalSupply
func updateMaxSupply(ctx sdk.Context, app *App) {
ctx.Logger().Info("Updating MaxSupply marker param")
params := app.MarkerKeeper.GetParams(ctx)
//nolint:staticcheck // Populate new param with deprecated param
params.MaxSupply = math.NewIntFromUint64(params.MaxTotalSupply)
app.MarkerKeeper.SetParams(ctx, params)
ctx.Logger().Info("Done updating MaxSupply marker param")
}
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ func (s *UpgradeTestSuite) TestSaffronRC1() {
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Updating ICQ params",
"INF Done updating ICQ params",
"INF Updating MaxSupply marker param",
"INF Done updating MaxSupply marker param",
}

s.AssertUpgradeHandlerLogs("saffron-rc1", expInLog, nil)
Expand All @@ -438,6 +440,8 @@ func (s *UpgradeTestSuite) TestSaffron() {
"INF removing all delegations from validators that have been inactive (unbonded) for 21 days",
"INF Updating ICQ params",
"INF Done updating ICQ params",
"INF Updating MaxSupply marker param",
"INF Done updating MaxSupply marker param",
}

s.AssertUpgradeHandlerLogs("saffron", expInLog, nil)
Expand Down
14 changes: 8 additions & 6 deletions cmd/provenanced/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,16 @@ func unquote(str string) string {
}

// LoadConfigFromFiles loads configurations appropriately.
func LoadConfigFromFiles(cmd *cobra.Command) error {
if err := loadUnmanagedConfig(cmd); err != nil {
return err
}
func LoadConfigFromFiles(cmd *cobra.Command) (err error) {
if IsPacked(cmd) {
return loadPackedConfig(cmd)
err = loadPackedConfig(cmd)
} else {
err = loadUnpackedConfig(cmd)
}
if err != nil {
return err
}
return loadUnpackedConfig(cmd)
return loadUnmanagedConfig(cmd)
}

// loadUnmanagedConfig reads the unmanaged config file into viper. It does not apply anything to any contexts though.
Expand Down
27 changes: 24 additions & 3 deletions cmd/provenanced/config/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
assert.Equal(t, "bananas", actual, "unmanaged field value")
})

s.T().Run("unmanaged config entry does not override other config", func(t *testing.T) {
s.T().Run("unmanaged config entry overrides other config", func(t *testing.T) {
dCmd := s.makeDummyCmd()
configDir := GetFullPathToConfigDir(dCmd)
uFile := GetFullPathToUnmanagedConf(dCmd)
Expand All @@ -180,8 +180,8 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
ctx := client.GetClientContextFromCmd(dCmd)
vpr := ctx.Viper
actual := vpr.GetString("db_backend")
assert.NotEqual(t, "still bananas", actual, "unmanaged field value")
assert.Equal(t, DefaultTmConfig().DBBackend, actual, "unmanaged field default value")
assert.Equal(t, "still bananas", actual, "unmanaged field value")
assert.NotEqual(t, DefaultTmConfig().DBBackend, actual, "unmanaged field default value")
})

s.T().Run("unmanaged config is read with unpacked files", func(t *testing.T) {
Expand All @@ -196,6 +196,27 @@ func (s *ConfigManagerTestSuite) TestUnmanagedConfig() {
assert.Equal(t, "stuff", actual, "unmanaged field value")
})

s.T().Run("unmanaged config is read with invalid packed files", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
pFile := GetFullPathToPackedConf(dCmd)
SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false)
require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config")
require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to packed config")
require.EqualError(t, LoadConfigFromFiles(dCmd), "packed config file parse error: invalid character 'k' looking for beginning of value", "should throw error with invalid packed config")
require.NoError(t, os.Remove(pFile), "removing packed config")
})

s.T().Run("unmanaged config is read with invalid unpacked files", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
pFile := GetFullPathToAppConf(dCmd)
SaveConfigs(dCmd, DefaultAppConfig(), DefaultTmConfig(), DefaultClientConfig(), false)
require.NoError(t, os.WriteFile(uFile, []byte("my-custom-entry = \"stuff\"\n"), 0o644), "writing unmanaged config")
require.NoError(t, os.WriteFile(pFile, []byte("kl234508923u5jl"), 0o644), "writing invalid data to app config")
require.EqualError(t, LoadConfigFromFiles(dCmd), "app config file merge error: While parsing config: toml: expected = after a key, but the document ends there", "should throw error with invalid packed config")
})

s.T().Run("unmanaged config is read with packed config", func(t *testing.T) {
dCmd := s.makeDummyCmd()
uFile := GetFullPathToUnmanagedConf(dCmd)
Expand Down
3 changes: 2 additions & 1 deletion docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1968,9 +1968,10 @@ Params defines the set of params for the account module.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `max_total_supply` | [uint64](#uint64) | | maximum amount of supply to allow a marker to be created with |
| `max_total_supply` | [uint64](#uint64) | | **Deprecated.** Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with |
| `enable_governance` | [bool](#bool) | | indicates if governance based controls of markers is allowed. |
| `unrestricted_denom_regex` | [string](#string) | | a regular expression used to validate marker denom values from normal create requests (governance requests are only subject to platform coin validation denom expression) |
| `max_supply` | [string](#string) | | maximum amount of supply to allow a marker to be created with |



Expand Down
10 changes: 8 additions & 2 deletions proto/provenance/marker/v1/marker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ message Params {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;

// maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false];
// Deprecated: Prefer to use `max_supply` instead. Maximum amount of supply to allow a marker to be created with
uint64 max_total_supply = 1 [(gogoproto.customtype) = "uint64", (gogoproto.nullable) = false, deprecated = true];
// indicates if governance based controls of markers is allowed.
bool enable_governance = 2;
// a regular expression used to validate marker denom values from normal create requests (governance
// requests are only subject to platform coin validation denom expression)
string unrestricted_denom_regex = 3;
// maximum amount of supply to allow a marker to be created with
string max_supply = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "json:\"max_supply\" yaml:\"max_supply\""
];
}

// MarkerAccount holds the marker configuration information in addition to a base account structure.
Expand Down
3 changes: 2 additions & 1 deletion x/marker/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
var markerData markertypes.GenesisState
markerData.Params.EnableGovernance = true
markerData.Params.MaxTotalSupply = 1000000
markerData.Params.MaxSupply = sdk.NewInt(1000000)
// Note: These account numbers get ignored.
markerData.Markers = []markertypes.MarkerAccount{
{
Expand Down Expand Up @@ -455,7 +456,7 @@ func (s *IntegrationTestSuite) TestMarkerQueryCommands() {
[]string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":""}`,
`{"max_total_supply":"1000000","enable_governance":true,"unrestricted_denom_regex":"","max_supply":"1000000"}`,
},
{
"get testcoin marker json",
Expand Down
4 changes: 3 additions & 1 deletion x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/tendermint/tendermint/libs/log"

"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -268,7 +270,7 @@ func (k Keeper) SetNetAssetValue(ctx sdk.Context, marker types.MarkerAccountI, n

key := types.NetAssetValueKey(marker.GetAddress(), netAssetValue.Price.Denom)
store := ctx.KVStore(k.storeKey)
if netAssetValue.Volume > marker.GetSupply().Amount.Uint64() {
if math.NewIntFromUint64(netAssetValue.Volume).GT(marker.GetSupply().Amount) {
return fmt.Errorf("volume(%v) cannot exceed marker %q supply(%v) ", netAssetValue.Volume, marker.GetDenom(), marker.GetSupply())
}

Expand Down
21 changes: 21 additions & 0 deletions x/marker/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,16 @@ func TestMsgSupplyIncreaseProposalRequest(t *testing.T) {
err = app.MarkerKeeper.AddMarkerAccount(ctx, nonActiveDenom)
require.NoError(t, err)

// exceed max supply
kneesBees := types.NewEmptyMarkerAccount(
"knees-bees",
user.String(),
[]types.AccessGrant{})
kneesBees.Status = types.StatusActive

err = app.MarkerKeeper.AddMarkerAccount(ctx, kneesBees)
require.NoError(t, err)

// all good
beesKnees := types.NewEmptyMarkerAccount(
"bees-knees",
Expand Down Expand Up @@ -1168,6 +1178,17 @@ func TestMsgSupplyIncreaseProposalRequest(t *testing.T) {
shouldFail: false,
expectedError: "",
},
{
name: "supply increase exceeds max supply",
amount: sdk.Coin{
Amount: types.StringToBigInt("1000000000000000000000"),
Denom: kneesBees.Denom,
},
targetAddress: authority,
authority: authority,
shouldFail: true,
expectedError: "requested supply 1000000000000000000000 exceeds maximum allowed value 100000000000000000000",
},
}

for _, tc := range testCases {
Expand Down
4 changes: 2 additions & 2 deletions x/marker/keeper/marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ func (k Keeper) IncreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coi

inCirculation := sdk.NewCoin(marker.GetDenom(), k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount)
total := inCirculation.Add(coin)
maxAllowed := sdk.NewCoin(marker.GetDenom(), sdk.NewIntFromUint64(k.GetParams(ctx).MaxTotalSupply))
maxAllowed := sdk.NewCoin(marker.GetDenom(), k.GetParams(ctx).MaxSupply)
if total.Amount.GT(maxAllowed.Amount) {
return fmt.Errorf(
"requested supply %d exceeds maximum allowed value %d", total.Amount, maxAllowed.Amount)
"requested supply %s exceeds maximum allowed value %s", total.Amount.String(), maxAllowed.Amount.String())
}

// If the marker has a fixed supply then adjust the supply to match the new total
Expand Down
15 changes: 14 additions & 1 deletion x/marker/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"regexp"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/provenance-io/provenance/x/marker/types"
Expand All @@ -15,6 +17,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
MaxTotalSupply: k.GetMaxTotalSupply(ctx),
EnableGovernance: k.GetEnableGovernance(ctx),
UnrestrictedDenomRegex: k.GetUnrestrictedDenomRegex(ctx),
MaxSupply: k.GetMaxSupply(ctx),
}
}

Expand All @@ -23,7 +26,8 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// GetMaxTotalSupply return the current parameter value for the max allowed total supply (or default if unset)
// GetMaxTotalSupply is deprecated.
// Deprecated: GetMaxTotalSupply is kept for backwards compatibility.
func (k Keeper) GetMaxTotalSupply(ctx sdk.Context) (max uint64) {
max = types.DefaultMaxTotalSupply
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxTotalSupply) {
Expand All @@ -32,6 +36,15 @@ func (k Keeper) GetMaxTotalSupply(ctx sdk.Context) (max uint64) {
return
}

// GetMaxSupply return the current parameter value for the max allowed supply (or default if unset)
func (k Keeper) GetMaxSupply(ctx sdk.Context) (max math.Int) {
max = types.StringToBigInt(types.DefaultMaxSupply)
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxSupply) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxSupply, &max)
}
return
}

// GetEnableGovernance returns the current parameter value for enabling governance control (or default if unset)
func (k Keeper) GetEnableGovernance(ctx sdk.Context) (enabled bool) {
enabled = types.DefaultEnableGovernance
Expand Down
19 changes: 11 additions & 8 deletions x/marker/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"math/rand"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -16,14 +18,15 @@ import (

// Simulation parameter constants
const (
MaxTotalSupply = "max_total_supply"
MaxSupply = "max_supply"
EnableGovernance = "enable_governance"
UnrestrictedDenomRegex = "unresticted_denom_regex"
)

// GenMaxTotalSupply randomized Maximum amount of supply to allow for markers
func GenMaxTotalSupply(r *rand.Rand) uint64 {
return r.Uint64()
// GenMaxSupply randomized Maximum amount of supply to allow for markers
func GenMaxSupply(r *rand.Rand) math.Int {
maxSupply := fmt.Sprintf("%d%d", r.Uint64(), r.Uint64())
return types.StringToBigInt(maxSupply)
}

// GenEnableGovernance returns a randomized EnableGovernance parameter.
Expand All @@ -40,10 +43,10 @@ func GenUnrestrictedDenomRegex(r *rand.Rand) string {

// RandomizedGenState generates a random GenesisState for marker
func RandomizedGenState(simState *module.SimulationState) {
var maxTotalSupply uint64
var maxSupply math.Int
simState.AppParams.GetOrGenerate(
simState.Cdc, MaxTotalSupply, &maxTotalSupply, simState.Rand,
func(r *rand.Rand) { maxTotalSupply = GenMaxTotalSupply(r) },
simState.Cdc, MaxSupply, &maxSupply, simState.Rand,
func(r *rand.Rand) { maxSupply = GenMaxSupply(r) },
)

var enableGovernance bool
Expand All @@ -60,7 +63,7 @@ func RandomizedGenState(simState *module.SimulationState) {

markerGenesis := types.GenesisState{
Params: types.Params{
MaxTotalSupply: maxTotalSupply,
MaxSupply: maxSupply,
EnableGovernance: enableGovernance,
UnrestrictedDenomRegex: unrestrictedDenomRegex,
},
Expand Down
6 changes: 4 additions & 2 deletions x/marker/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ func TestRandomizedGenState(t *testing.T) {
var markerGenesis types.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &markerGenesis)

expectedMaxSupply := types.StringToBigInt("10667007354186551956894385949183117216")

require.Equal(t, true, markerGenesis.Params.EnableGovernance)
require.Equal(t, uint64(0x9408d2ac22c4d294), markerGenesis.Params.MaxTotalSupply)
require.Equal(t, `[a-zA-Z][a-zA-Z0-9\\-\\.]{7,60}`, markerGenesis.Params.UnrestrictedDenomRegex)
require.Equal(t, expectedMaxSupply, markerGenesis.Params.MaxSupply)
require.Equal(t, `[a-zA-Z][a-zA-Z0-9\\-\\.]{9,20}`, markerGenesis.Params.UnrestrictedDenomRegex)
}

// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
Expand Down
Loading

0 comments on commit 46ed503

Please sign in to comment.