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

Add genesis export/init for marker deny send lists #1662

Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
The id info is still included by default, but will be excluded if `exclude_id_info` is `true`.
* Removed the quicksilver upgrade handlers [PR 1648](https://github.com/provenance-io/provenance/pull/1648).
* Bump cometbft to v0.34.29 (from v0.34.28) [PR 1649](https://github.com/provenance-io/provenance/pull/1649).
* Add genesis/init for Marker module send deny list addresses. [#1660](https://github.com/provenance-io/provenance/issues/1660)

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
DefaultWeightMsgAddAccess int = 10
DefaultWeightMsgAddFinalizeActivateMarker int = 10
DefaultWeightMsgAddMarkerProposal int = 40
DefaultWeightMsgUpdateDenySendList int = 10
// MsgFees
DefaultWeightAddMsgFeeProposalContent int = 75
DefaultWeightRemoveMsgFeeProposalContent int = 25
Expand Down
20 changes: 19 additions & 1 deletion docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
- [MarkerType](#provenance.marker.v1.MarkerType)

- [provenance/marker/v1/genesis.proto](#provenance/marker/v1/genesis.proto)
- [DenySendAddress](#provenance.marker.v1.DenySendAddress)
- [GenesisState](#provenance.marker.v1.GenesisState)
- [MarkerNetAssetValues](#provenance.marker.v1.MarkerNetAssetValues)

Expand Down Expand Up @@ -2021,6 +2022,22 @@ MarkerType defines the types of marker



<a name="provenance.marker.v1.DenySendAddress"></a>

### DenySendAddress
DenySendAddress defines addresses that are denied sends for marker denom


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `marker_address` | [string](#string) | | marker_address is the marker's address for denied address |
| `deny_address` | [string](#string) | | deny_address defines all wallet addresses that are denied sends for the marker |






<a name="provenance.marker.v1.GenesisState"></a>

### GenesisState
Expand All @@ -2031,7 +2048,8 @@ GenesisState defines the account module's genesis state.
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#provenance.marker.v1.Params) | | params defines all the parameters of the module. |
| `markers` | [MarkerAccount](#provenance.marker.v1.MarkerAccount) | repeated | A collection of marker accounts to create on start |
| `net_asset_values` | [MarkerNetAssetValues](#provenance.marker.v1.MarkerNetAssetValues) | repeated | |
| `net_asset_values` | [MarkerNetAssetValues](#provenance.marker.v1.MarkerNetAssetValues) | repeated | list of marker net asset values |
| `deny_send_addresses` | [DenySendAddress](#provenance.marker.v1.DenySendAddress) | repeated | list of denom based denied send addresses |



Expand Down
15 changes: 15 additions & 0 deletions proto/provenance/marker/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ message GenesisState {
// A collection of marker accounts to create on start
repeated MarkerAccount markers = 2 [(gogoproto.nullable) = false];

// list of marker net asset values
repeated MarkerNetAssetValues net_asset_values = 3 [(gogoproto.nullable) = false];

// list of denom based denied send addresses
repeated DenySendAddress deny_send_addresses = 4 [(gogoproto.nullable) = false];
}

// DenySendAddress defines addresses that are denied sends for marker denom
message DenySendAddress {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// marker_address is the marker's address for denied address
string marker_address = 1;
// deny_address defines all wallet addresses that are denied sends for the marker
string deny_address = 3;
iramiller marked this conversation as resolved.
Show resolved Hide resolved
}

// MarkerNetAssetValues defines the net asset values for a marker
Expand Down
15 changes: 14 additions & 1 deletion x/marker/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
}
}

for _, denyAddress := range data.DenySendAddresses {
markerAddr := sdk.MustAccAddressFromBech32(denyAddress.MarkerAddress)
denyAddress := sdk.MustAccAddressFromBech32(denyAddress.DenyAddress)
k.AddSendDeny(ctx, markerAddr, denyAddress)
}

Check warning on line 51 in x/marker/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/marker/keeper/genesis.go#L48-L51

Added lines #L48 - L51 were not covered by tests
for _, mNavs := range data.NetAssetValues {
for _, nav := range mNavs.NetAssetValues {
navCopy := nav
Expand Down Expand Up @@ -85,6 +90,14 @@
}
k.IterateMarkers(ctx, appendToMarkers)

var denyAddresses []types.DenySendAddress
handleDenyList := func(key []byte) bool {
markerAddr, denyAddr := types.GetDenySendAddresses(key)
denyAddresses = append(denyAddresses, types.DenySendAddress{MarkerAddress: markerAddr.String(), DenyAddress: denyAddr.String()})
return false
}
k.IterateSendDeny(ctx, handleDenyList)

Check warning on line 100 in x/marker/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/marker/keeper/genesis.go#L93-L100

Added lines #L93 - L100 were not covered by tests
markerNetAssetValues := make([]types.MarkerNetAssetValues, len(markers))
for i := range markers {
var markerNavs types.MarkerNetAssetValues
Expand All @@ -101,5 +114,5 @@
markerNetAssetValues[i] = markerNavs
}

return types.NewGenesisState(params, markers, markerNetAssetValues)
return types.NewGenesisState(params, markers, denyAddresses, markerNetAssetValues)

Check warning on line 117 in x/marker/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/marker/keeper/genesis.go#L117

Added line #L117 was not covered by tests
}
15 changes: 14 additions & 1 deletion x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
store.Delete(types.MarkerStoreKey(marker.GetAddress()))
}

// IterateMarkers iterates all markers with the given handler function.
// IterateMarkers iterates all markers with the given handler function.
func (k Keeper) IterateMarkers(ctx sdk.Context, cb func(marker types.MarkerAccountI) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.MarkerStoreKeyPrefix)
Expand Down Expand Up @@ -221,6 +221,19 @@
store.Delete(types.DenySendKey(markerAddr, senderAddr))
}

// IterateMarkers iterates all markers with the given handler function.
func (k Keeper) IterateSendDeny(ctx sdk.Context, handler func(key []byte) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.DenySendKeyPrefix)

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
if handler(iterator.Key()) {
break

Check warning on line 232 in x/marker/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/marker/keeper/keeper.go#L225-L232

Added lines #L225 - L232 were not covered by tests
}
}
}

// AddSetNetAssetValues adds a set of net asset values to a marker
func (k Keeper) AddSetNetAssetValues(ctx sdk.Context, marker types.MarkerAccountI, netAssetValues []types.NetAssetValue, source string) error {
for _, nav := range netAssetValues {
Expand Down
62 changes: 47 additions & 15 deletions x/marker/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,10 @@
OpWeightMsgAddMarkerProposal = "op_weight_msg_add_marker_proposal"
//nolint:gosec // not credentials
OpWeightMsgSetAccountData = "op_weight_msg_set_account_data"
//nolint:gosec // not credentials
OpWeightMsgUpdateSendDenyList = "op_weight_msg_update_send_deny_list"
)

/*

AddAccess
DeleteAccess

Withdraw

Mint
Burn
Transfer

SetDenomMetadata
*/

// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec, protoCodec *codec.ProtoCodec,
Expand All @@ -76,6 +64,7 @@
weightMsgAddFinalizeActivateMarker int
weightMsgAddMarkerProposal int
weightMsgSetAccountData int
weightMsgUpdateSendDenyList int
)

appParams.GetOrGenerate(cdc, OpWeightMsgAddMarker, &weightMsgAddMarker, nil,
Expand Down Expand Up @@ -114,6 +103,12 @@
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgUpdateSendDenyList, &weightMsgUpdateSendDenyList, nil,
func(_ *rand.Rand) {
weightMsgUpdateSendDenyList = simappparams.DefaultWeightMsgUpdateDenySendList
},
)

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightMsgAddMarker,
Expand All @@ -139,10 +134,14 @@
weightMsgSetAccountData,
SimulateMsgSetAccountData(k, args),
),
simulation.NewWeightedOperation(
weightMsgUpdateSendDenyList,
SimulateMsgUpdateSendDenyList(k, args),
),
}
}

// SimulateMsgAddMarker will bind a NAME under an existing name using a 40% probability of restricting it.
// SimulateMsgAddMarker will Add a random marker with random configuration.
func SimulateMsgAddMarker(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand All @@ -168,6 +167,7 @@
}
}

// SimulateMsgChangeStatus will randomly change the status of the marker depending on it's current state.
func SimulateMsgChangeStatus(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -217,6 +217,7 @@
}
}

// SimulateMsgAddAccess will Add a random access to an account.
func SimulateMsgAddAccess(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -269,6 +270,7 @@
}
}

// SimulateMsgAddMarkerProposal will broadcast a Add random Marker Proposal.
func SimulateMsgAddMarkerProposal(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -343,6 +345,7 @@
}
}

// SimulateMsgSetAccountData will set randomized account data to a marker.
func SimulateMsgSetAccountData(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -372,6 +375,32 @@
}
}

// SimulateMsgUpdateSendDenyList will update random marker with denied send addresses.
func SimulateMsgUpdateSendDenyList(k keeper.Keeper, args *WeightedOpsArgs) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
msg := &types.MsgUpdateSendDenyListRequest{}

marker, signer := randomMarkerWithAccessSigner(r, ctx, k, accs, types.Access_Transfer)
if marker == nil {
return simtypes.NoOpMsg(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), "unable to find marker with a transfer signer"), nil, nil
}

Check warning on line 388 in x/marker/simulation/operations.go

View check run for this annotation

Codecov / codecov/patch

x/marker/simulation/operations.go#L387-L388

Added lines #L387 - L388 were not covered by tests

rDenyAccounts := simtypes.RandomAccounts(r, 10)
addDenyAddresses := make([]string, len(rDenyAccounts))
iramiller marked this conversation as resolved.
Show resolved Hide resolved
for i := range rDenyAccounts {
addDenyAddresses[i] = rDenyAccounts[i].Address.String()
}

msg.Denom = marker.GetDenom()
msg.AddDeniedAddresses = addDenyAddresses
msg.Authority = signer.Address.String()

return Dispatch(r, app, ctx, args.AK, args.BK, signer, chainID, msg, nil)
}
}

// Dispatch sends an operation to the chain using a given account/funds on account for fees. Failures on the server side
// are handled as no-op msg operations with the error string as the status/response.
func Dispatch(
Expand Down Expand Up @@ -435,6 +464,7 @@
return simtypes.NewOperationMsg(msg, true, "", &codec.ProtoCodec{}), futures, nil
}

// randomUnrestrictedDenom returns a randomized unrestricted denom string value.
func randomUnrestrictedDenom(r *rand.Rand, unrestrictedDenomExp string) string {
exp := regexp.MustCompile(`\{(\d+),(\d+)\}`)
matches := exp.FindStringSubmatch(unrestrictedDenomExp)
Expand Down Expand Up @@ -478,6 +508,7 @@
return
}

// randomMarker returns a randomly selected marker from store
func randomMarker(r *rand.Rand, ctx sdk.Context, k keeper.Keeper) types.MarkerAccountI {
var markers []types.MarkerAccountI
k.IterateMarkers(ctx, func(marker types.MarkerAccountI) (stop bool) {
Expand All @@ -491,6 +522,7 @@
return markers[idx]
}

// randomMarkerWithAccessSigner returns a randomly selected marker and account that has specified access.
func randomMarkerWithAccessSigner(r *rand.Rand, ctx sdk.Context, k keeper.Keeper, accs []simtypes.Account, access types.Access) (types.MarkerAccountI, simtypes.Account) {
var markers []types.MarkerAccountI
k.IterateMarkers(ctx, func(marker types.MarkerAccountI) (stop bool) {
Expand Down
55 changes: 54 additions & 1 deletion x/marker/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (s *SimTestSuite) TestWeightedOperations() {
{simappparams.DefaultWeightMsgAddFinalizeActivateMarker, sdk.MsgTypeURL(&types.MsgAddFinalizeActivateMarkerRequest{}), sdk.MsgTypeURL(&types.MsgAddFinalizeActivateMarkerRequest{})},
{simappparams.DefaultWeightMsgAddMarkerProposal, "gov", sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{})},
{simappparams.DefaultWeightMsgSetAccountData, sdk.MsgTypeURL(&types.MsgSetAccountDataRequest{}), sdk.MsgTypeURL(&types.MsgSetAccountDataRequest{})},
{simappparams.DefaultWeightMsgUpdateDenySendList, sdk.MsgTypeURL(&types.MsgUpdateSendDenyListRequest{}), sdk.MsgTypeURL(&types.MsgUpdateSendDenyListRequest{})},
}

expNames := make([]string, len(expected))
Expand Down Expand Up @@ -351,7 +352,7 @@ func (s *SimTestSuite) TestSimulateMsgAddMarkerProposal() {
}
}

func (s *SimTestSuite) TestSSimulateMsgSetAccountData() {
func (s *SimTestSuite) TestSimulateMsgSetAccountData() {
// setup 3 accounts
src := rand.NewSource(1)
r := rand.New(src)
Expand Down Expand Up @@ -403,6 +404,58 @@ func (s *SimTestSuite) TestSSimulateMsgSetAccountData() {
s.Assert().Len(futureOperations, 0, "futureOperations")
}

func (s *SimTestSuite) TestSimulateMsgUpdateSendDenyList() {
// setup 3 accounts
src := rand.NewSource(1)
r := rand.New(src)
accounts := s.getTestingAccounts(r, 3)

// Add a marker with deposit permissions so that it can be found by the sim.
newMarker := &types.MsgAddFinalizeActivateMarkerRequest{
Amount: sdk.NewInt64Coin("simcoin", 1000),
Manager: accounts[1].Address.String(),
FromAddress: accounts[1].Address.String(),
MarkerType: types.MarkerType_RestrictedCoin,
AccessList: []types.AccessGrant{
{
Address: accounts[1].Address.String(),
Permissions: types.AccessList{
types.Access_Mint, types.Access_Burn, types.Access_Deposit, types.Access_Withdraw,
types.Access_Delete, types.Access_Admin, types.Access_Transfer,
},
},
},
SupplyFixed: true,
AllowGovernanceControl: true,
AllowForcedTransfer: false,
RequiredAttributes: nil,
}
markerMsgServer := keeper.NewMsgServerImpl(s.app.MarkerKeeper)
_, err := markerMsgServer.AddFinalizeActivateMarker(s.ctx, newMarker)
s.Require().NoError(err, "AddFinalizeActivateMarker")

// begin a new block
s.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: s.app.LastBlockHeight() + 1, AppHash: s.app.LastCommitID().Hash}})

args := s.getWeightedOpsArgs()
// execute operation
op := simulation.SimulateMsgUpdateSendDenyList(s.app.MarkerKeeper, &args)
operationMsg, futureOperations, err := op(r, s.app.BaseApp, s.ctx, accounts, "")
s.Require().NoError(err, "SimulateMsgUpdateSendDenyList op(...) error")
s.LogOperationMsg(operationMsg)

var msg types.MsgUpdateSendDenyListRequest
s.Require().NoError(s.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)")

s.Assert().True(operationMsg.OK, "operationMsg.OK")
s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name")
s.Assert().Equal("simcoin", msg.Denom, "msg.Denom")
s.Assert().Len(msg.AddDeniedAddresses, 10, "msg.AddDeniedAddresses")
s.Assert().Equal(accounts[1].Address.String(), msg.Authority, "msg.Authority")
s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Route, "operationMsg.Route")
s.Assert().Len(futureOperations, 0, "futureOperations")
}

func (s *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
accounts := simtypes.RandomAccounts(r, n)

Expand Down
11 changes: 6 additions & 5 deletions x/marker/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
)

// NewGenesisState creates a new GenesisState object
func NewGenesisState(params Params, markers []MarkerAccount, netAssetValues []MarkerNetAssetValues) *GenesisState {
func NewGenesisState(params Params, markers []MarkerAccount, denySendAddresses []DenySendAddress, netAssetValues []MarkerNetAssetValues) *GenesisState {
return &GenesisState{
Params: params,
Markers: markers,
NetAssetValues: netAssetValues,
Params: params,
Markers: markers,
DenySendAddresses: denySendAddresses,
NetAssetValues: netAssetValues,
}
}

Expand All @@ -35,7 +36,7 @@ func (state GenesisState) Validate() error {

// DefaultGenesisState returns the initial module genesis state.
func DefaultGenesisState() *GenesisState {
return NewGenesisState(DefaultParams(), []MarkerAccount{}, []MarkerNetAssetValues{})
return NewGenesisState(DefaultParams(), []MarkerAccount{}, []DenySendAddress{}, []MarkerNetAssetValues{})
}

// GetGenesisStateFromAppState returns x/marker GenesisState given raw application
Expand Down
Loading
Loading