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 9 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 @@ -55,6 +55,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
18 changes: 18 additions & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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)

- [provenance/marker/v1/proposals.proto](#provenance/marker/v1/proposals.proto)
Expand Down Expand Up @@ -1737,6 +1738,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 @@ -1747,6 +1764,7 @@ 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 |
| `deny_send_addresses` | [DenySendAddress](#provenance.marker.v1.DenySendAddress) | repeated | list of denom based denied send addresses |



Expand Down
14 changes: 14 additions & 0 deletions proto/provenance/marker/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,18 @@ message GenesisState {

// A collection of marker accounts to create on start
repeated MarkerAccount markers = 2 [(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
}
17 changes: 16 additions & 1 deletion x/marker/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
k.SetMarker(ctx, &data.Markers[i])
}
}

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

// ExportGenesis exports the current keeper state of the marker module.ExportGenesis
Expand Down Expand Up @@ -73,5 +79,14 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
}

k.IterateMarkers(ctx, appendToMarkers)
return types.NewGenesisState(params, markers)

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)

return types.NewGenesisState(params, markers, denyAddresses)
}
15 changes: 14 additions & 1 deletion x/marker/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (k Keeper) RemoveMarker(ctx sdk.Context, marker types.MarkerAccountI) {
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 @@ -217,6 +217,19 @@ func (k Keeper) RemoveSendDeny(ctx sdk.Context, markerAddr, senderAddr sdk.AccAd
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
}
}
}

// GetReqAttrBypassAddrs returns a deep copy of the addresses that bypass the required attributes checking.
func (k Keeper) GetReqAttrBypassAddrs() []sdk.AccAddress {
return k.reqAttrBypassAddrs.GetSlice()
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 @@ const (
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 @@ func WeightedOperations(
weightMsgAddFinalizeActivateMarker int
weightMsgAddMarkerProposal int
weightMsgSetAccountData int
weightMsgUpdateSendDenyList int
)

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

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

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightMsgAddMarker,
Expand All @@ -139,10 +134,14 @@ func WeightedOperations(
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 @@ -166,6 +165,7 @@ func SimulateMsgAddMarker(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk bank
}
}

// 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 @@ -215,6 +215,7 @@ func SimulateMsgChangeStatus(k keeper.Keeper, ak authkeeper.AccountKeeperI, bk b
}
}

// 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 @@ -265,6 +266,7 @@ func SimulateMsgAddFinalizeActivateMarker(k keeper.Keeper, ak authkeeper.Account
}
}

// 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 @@ -339,6 +341,7 @@ func SimulateMsgAddMarkerProposal(k keeper.Keeper, args *WeightedOpsArgs) simtyp
}
}

// 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 @@ -368,6 +371,32 @@ func SimulateMsgSetAccountData(k keeper.Keeper, args *WeightedOpsArgs) simtypes.
}
}

// 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
}

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 @@ -431,6 +460,7 @@ func Dispatch(
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 @@ -474,6 +504,7 @@ func randomAccessTypes(r *rand.Rand, markerType types.MarkerType) (result []type
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 @@ -487,6 +518,7 @@ func randomMarker(r *rand.Rand, ctx sdk.Context, k keeper.Keeper) types.MarkerAc
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
9 changes: 5 additions & 4 deletions x/marker/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

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

Expand All @@ -26,7 +27,7 @@ func (state GenesisState) Validate() error {

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

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