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

feat(x/fbridge): set target denom as module parameters #1366

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/collection) [\#1287](https://github.com/Finschia/finschia-sdk/pull/1287) add nft id validation to MsgSendNFT
* (types) [\#1314](https://github.com/Finschia/finschia-sdk/pull/1314) replace IsEqual with Equal
* (x/fswap) [\#1363](https://github.com/Finschia/finschia-sdk/pull/1363) introduce new event for MakeSwapProposal
* (x/fbridge) [\#1366](https://github.com/Finschia/finschia-sdk/pull/1366) Set target denom as module parameters

### Bug Fixes
* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue
Expand Down
48 changes: 48 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@
- [EventProvision](#lbm.fbridge.v1.EventProvision)
- [EventSuggestRole](#lbm.fbridge.v1.EventSuggestRole)
- [EventTransfer](#lbm.fbridge.v1.EventTransfer)
- [EventUpdateParams](#lbm.fbridge.v1.EventUpdateParams)

- [lbm/fbridge/v1/genesis.proto](#lbm/fbridge/v1/genesis.proto)
- [BlockSeqInfo](#lbm.fbridge.v1.BlockSeqInfo)
Expand Down Expand Up @@ -845,6 +846,8 @@
- [MsgSuggestRoleResponse](#lbm.fbridge.v1.MsgSuggestRoleResponse)
- [MsgTransfer](#lbm.fbridge.v1.MsgTransfer)
- [MsgTransferResponse](#lbm.fbridge.v1.MsgTransferResponse)
- [MsgUpdateParams](#lbm.fbridge.v1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#lbm.fbridge.v1.MsgUpdateParamsResponse)

- [Msg](#lbm.fbridge.v1.Msg)

Expand Down Expand Up @@ -11451,6 +11454,7 @@ supports positive values.
| `judge_trust_level` | [Fraction](#lbm.fbridge.v1.Fraction) | | ratio of how many judges' confirmations are needed to be valid. |
| `timelock_period` | [uint64](#uint64) | | default timelock period for each provision (unix timestamp) |
| `proposal_period` | [uint64](#uint64) | | default period of the proposal to update the role |
| `target_denom` | [string](#string) | | target denom of the bridge module. This is the base denom of Finschia normally. |



Expand Down Expand Up @@ -11719,6 +11723,21 @@ VoteOption enumerates the valid vote options for a given role proposal.




<a name="lbm.fbridge.v1.EventUpdateParams"></a>

### EventUpdateParams



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#lbm.fbridge.v1.Params) | | |





<!-- end messages -->

<!-- end enums -->
Expand Down Expand Up @@ -12682,6 +12701,34 @@ MsgTransfer is input values required for bridge transfer




<a name="lbm.fbridge.v1.MsgUpdateParams"></a>

### MsgUpdateParams



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | the authority address |
| `params` | [Params](#lbm.fbridge.v1.Params) | | params defines the x/fbridge parameters to update.

NOTE: All parameters must be supplied. |






<a name="lbm.fbridge.v1.MsgUpdateParamsResponse"></a>

### MsgUpdateParamsResponse






<!-- end messages -->

<!-- end enums -->
Expand All @@ -12696,6 +12743,7 @@ MsgTransfer is input values required for bridge transfer

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `UpdateParams` | [MsgUpdateParams](#lbm.fbridge.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#lbm.fbridge.v1.MsgUpdateParamsResponse) | UpdateParams updates the x/fbridge parameters. | |
| `Transfer` | [MsgTransfer](#lbm.fbridge.v1.MsgTransfer) | [MsgTransferResponse](#lbm.fbridge.v1.MsgTransferResponse) | Submit a transfer request to the bridge module. | |
| `Provision` | [MsgProvision](#lbm.fbridge.v1.MsgProvision) | [MsgProvisionResponse](#lbm.fbridge.v1.MsgProvisionResponse) | Submit a provision to the bridge module. | |
| `HoldTransfer` | [MsgHoldTransfer](#lbm.fbridge.v1.MsgHoldTransfer) | [MsgHoldTransferResponse](#lbm.fbridge.v1.MsgHoldTransferResponse) | Set the time lock value from default value to uint64.max for specific confirmed provision. | |
Expand Down
4 changes: 4 additions & 0 deletions proto/lbm/fbridge/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fbridge/types";
import "gogoproto/gogo.proto";
import "lbm/fbridge/v1/fbridge.proto";

message EventUpdateParams {
Params params = 1 [(gogoproto.nullable) = false];
}

message EventTransfer {
// the sequence number of the bridge request
uint64 seq = 1;
Expand Down
2 changes: 2 additions & 0 deletions proto/lbm/fbridge/v1/fbridge.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ message Params {
uint64 timelock_period = 4;
// default period of the proposal to update the role
uint64 proposal_period = 5;
// target denom of the bridge module. This is the base denom of Finschia normally.
string target_denom = 6;
}

// Provision is a struct that represents a provision internally.
Expand Down
15 changes: 15 additions & 0 deletions proto/lbm/fbridge/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import "gogoproto/gogo.proto";
import "lbm/fbridge/v1/fbridge.proto";

service Msg {
// UpdateParams updates the x/fbridge parameters.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);

// Submit a transfer request to the bridge module.
rpc Transfer(MsgTransfer) returns (MsgTransferResponse);

Expand Down Expand Up @@ -41,6 +44,18 @@ service Msg {
rpc SetBridgeStatus(MsgSetBridgeStatus) returns (MsgSetBridgeStatusResponse);
}

message MsgUpdateParams {
// the authority address
string authority = 1;

// params defines the x/fbridge parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

message MsgUpdateParamsResponse {}

// MsgTransfer is input values required for bridge transfer
message MsgTransfer {
// the sender address on the source chain
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.FbridgeKeeper = fbridgekeeper.NewKeeper(appCodec, keys[fbridgetypes.StoreKey], memKeys[fbridgetypes.MemStoreKey], app.AccountKeeper, app.BankKeeper, "stake", fbridgetypes.DefaultAuthority().String())
app.FbridgeKeeper = fbridgekeeper.NewKeeper(appCodec, keys[fbridgetypes.StoreKey], memKeys[fbridgetypes.MemStoreKey], app.AccountKeeper, app.BankKeeper, fbridgetypes.DefaultAuthority().String())

/**** Module Options ****/

Expand Down
4 changes: 2 additions & 2 deletions x/fbridge/keeper/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestAssignRole(t *testing.T) {
key, memKey, ctx, encCfg, authKeeper, bankKeeper, addrs := testutil.PrepareFbridgeTest(t, 3)
auth := types.DefaultAuthority()
k := NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", auth.String())
k := NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, auth.String())
err := k.InitGenesis(ctx, types.DefaultGenesisState())
require.NoError(t, err)

Expand Down Expand Up @@ -61,7 +61,7 @@ func TestAssignRole(t *testing.T) {
func TestBridgeHaltAndResume(t *testing.T) {
key, memKey, ctx, encCfg, authKeeper, bankKeeper, addrs := testutil.PrepareFbridgeTest(t, 3)
auth := types.DefaultAuthority()
k := NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", auth.String())
k := NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, auth.String())
err := k.InitGenesis(ctx, types.DefaultGenesisState())
require.NoError(t, err)
for _, addr := range addrs {
Expand Down
5 changes: 4 additions & 1 deletion x/fbridge/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
)

func (k Keeper) InitGenesis(ctx sdk.Context, gs *types.GenesisState) error {
k.SetParams(ctx, gs.Params)
if err := k.SetParams(ctx, gs.Params); err != nil {
return err

Check warning on line 12 in x/fbridge/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/genesis.go#L12

Added line #L12 was not covered by tests
}

k.setNextSequence(ctx, gs.SendingState.NextSeq)
for _, info := range gs.SendingState.SeqToBlocknum {
k.setSeqToBlocknum(ctx, info.Seq, info.Blocknum)
Expand Down
18 changes: 7 additions & 11 deletions x/fbridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ type Keeper struct {
authKeeper types.AccountKeeper
bankKeeper types.BankKeeper

// the target denom for the bridge
targetDenom string

// authority can give a role to a specific address like guardian
authority string
}
Expand All @@ -31,7 +28,7 @@ func NewKeeper(
key, memKey sdk.StoreKey,
authKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
targetDenom, authority string,
authority string,
) Keeper {
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic(errors.New("fbridge module account has not been set"))
Expand All @@ -50,13 +47,12 @@ func NewKeeper(
}

return Keeper{
storeKey: key,
memKey: memKey,
cdc: cdc,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
targetDenom: targetDenom,
authority: authority,
storeKey: key,
memKey: memKey,
cdc: cdc,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
authority: authority,
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/fbridge/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ func TestNewKeeper(t *testing.T) {
"fbridge module account has not been set": {
malleate: func() {
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(nil).Times(1)
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", types.DefaultAuthority().String())
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, types.DefaultAuthority().String())
},
isPanic: true,
},
"fbridge authority must be the gov or foundation module account": {
malleate: func() {
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress("invalid").String())
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress("invalid").String())
},
isPanic: true,
},
"success - gov authority": {
malleate: func() {
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress(govtypes.ModuleName).String())
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
},
isPanic: false,
},
"success - foundation authority": {
malleate: func() {
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress(foundation.ModuleName).String())
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress(foundation.ModuleName).String())
},
isPanic: false,
},
Expand Down
23 changes: 23 additions & 0 deletions x/fbridge/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"

sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
Expand All @@ -18,6 +19,28 @@
return &msgServer{k}
}

func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

Check warning on line 23 in x/fbridge/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/msg_server.go#L22-L23

Added lines #L22 - L23 were not covered by tests

if msg.Authority != m.Keeper.GetAuthority() {
return nil, fmt.Errorf(
"invalid authority; expected %s, got %s",
m.Keeper.GetAuthority(), msg.Authority)

Check warning on line 28 in x/fbridge/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/msg_server.go#L25-L28

Added lines #L25 - L28 were not covered by tests
}

if err := m.Keeper.SetParams(ctx, msg.Params); err != nil {
return nil, err

Check warning on line 32 in x/fbridge/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/msg_server.go#L31-L32

Added lines #L31 - L32 were not covered by tests
}

if err := ctx.EventManager().EmitTypedEvent(&types.EventUpdateParams{
Params: msg.Params,
}); err != nil {
panic(err)

Check warning on line 38 in x/fbridge/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/msg_server.go#L35-L38

Added lines #L35 - L38 were not covered by tests
}

return &types.MsgUpdateParamsResponse{}, nil

Check warning on line 41 in x/fbridge/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fbridge/keeper/msg_server.go#L41

Added line #L41 was not covered by tests
}

func (m msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

Expand Down
7 changes: 6 additions & 1 deletion x/fbridge/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import (
"github.com/Finschia/finschia-sdk/x/fbridge/types"
)

func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
if err := params.ValidateParams(); err != nil {
return err
}

store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&params)
store.Set(types.KeyParams, bz)
return nil
}

func (k Keeper) GetParams(ctx sdk.Context) types.Params {
Expand Down
Loading
Loading