Skip to content

Commit

Permalink
Added oracle-related data to x/profiles params
Browse files Browse the repository at this point in the history
See PR #547
  • Loading branch information
dadamu authored Jul 12, 2021
1 parent 7bd1135 commit a549ef7
Show file tree
Hide file tree
Showing 14 changed files with 845 additions and 71 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Renamed `PollData` and `PollAnswer` to `Poll` and `ProvidedAnswer` ([#536]((https://github.com/desmos-labs/desmos/issues/536)))
- Enabled snapshot by default ([#529](https://github.com/desmos-labs/desmos/pull/529))
- Improved `x/profiles` params structure [#538](https://github.com/desmos-labs/desmos/issues/538)
- Made oracle-related data on-chain parameters ([#547](https://github.com/desmos-labs/desmos/pull/547))

## Version 0.17.0
### Changes
Expand Down
47 changes: 47 additions & 0 deletions proto/desmos/profiles/v1beta1/models_params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package desmos.profiles.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/desmos-labs/desmos/x/profiles/types";

Expand All @@ -22,6 +23,11 @@ message Params {

BioParams bio = 3
[ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"bio\"" ];

OracleParams oracle = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"oracle\""
];
}

// NicknameParams defines the parameters related to the profiles nicknames
Expand Down Expand Up @@ -72,3 +78,44 @@ message BioParams {
(gogoproto.moretags) = "yaml:\"max_length\""
];
}

// OracleParams defines the parameters related to the oracle
// that will be used to verify the ownership of a centralized
// application account by a Desmos profile
message OracleParams {
option (gogoproto.goproto_getters) = false;

// ScriptID represents the ID of the oracle script to be called to verify the
// data
int64 script_id = 1 [
(gogoproto.customname) = "ScriptID",
(gogoproto.moretags) = "yaml:\"script_id\""
];

// AskCount represents the number of oracles to which ask to verify the data
uint64 ask_count = 2 [ (gogoproto.moretags) = "yaml:\"ask_count\"" ];

// MinCount represents the minimum count of oracles that should complete the
// verification successfully
uint64 min_count = 3 [ (gogoproto.moretags) = "yaml:\"min_count\"" ];

// PrepareGas represents the amount of gas to be used during the preparation
// stage of the oracle script
uint64 prepare_gas = 4 [ (gogoproto.moretags) = "yaml:\"prepare_gas\"" ];

// ExecuteGas represents the amount of gas to be used during the execution of
// the oracle script
uint64 execute_gas = 5 [ (gogoproto.moretags) = "yaml:\"execute_gas\"" ];

// FeePayer represents the key of the account that is going to pay for oracle
// fees if needed
string fee_payer = 6 [ (gogoproto.moretags) = "yaml:\"fee_payer\"" ];

// FeeAmount represents the amount of fees to be payed in order to execute the
// oracle script
repeated cosmos.base.v1beta1.Coin fee_amount = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"fee_amount\""
];
}
2 changes: 1 addition & 1 deletion x/oracle/types/packet.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packet
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/packet.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions x/profiles/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
)
suite.k.SetParams(ctx, params)
suite.k.SetPort(ctx, "port-id")
Expand Down Expand Up @@ -169,6 +178,15 @@ func (suite *KeeperTestSuite) Test_ExportGenesis() {
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
),
"port-id",
[]types.ChainLink{
Expand Down Expand Up @@ -361,6 +379,15 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
),
"profiles-port-id",
[]types.ChainLink{
Expand Down Expand Up @@ -433,6 +460,15 @@ func (suite *KeeperTestSuite) Test_InitGenesis() {
types.NewNicknameParams(sdk.NewInt(100), sdk.NewInt(200)),
types.NewDTagParams("regex", sdk.NewInt(100), sdk.NewInt(200)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
)
suite.Require().Equal(params, suite.k.GetParams(ctx))

Expand Down
27 changes: 27 additions & 0 deletions x/profiles/keeper/keeper_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ func (suite *KeeperTestSuite) TestKeeper_SetParams() {
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
)
suite.k.SetParams(suite.ctx, params)

Expand All @@ -32,6 +41,15 @@ func (suite *KeeperTestSuite) TestKeeper_GetParams() {
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
)
suite.k.SetParams(ctx, params)
},
Expand All @@ -40,6 +58,15 @@ func (suite *KeeperTestSuite) TestKeeper_GetParams() {
types.NewNicknameParams(sdk.NewInt(3), sdk.NewInt(1000)),
types.NewDTagParams("^[A-Za-z0-9_]+$", sdk.NewInt(3), sdk.NewInt(1000)),
types.NewBioParams(sdk.NewInt(1000)),
types.NewOracleParams(
32,
10,
6,
50_000,
200_000,
"desmos-ibc-profiles",
sdk.NewCoin("band", sdk.NewInt(10)),
),
),
},
{
Expand Down
36 changes: 11 additions & 25 deletions x/profiles/keeper/relay_app_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ import (
oracletypes "github.com/desmos-labs/desmos/x/oracle/types"
)

// TODO: Make the following parameter
const (
// OracleScriptID represents the oracle script to be called on Band Protocol
OracleScriptID = 32

OracleAskCount = 10
OracleMinCount = 6
OraclePrepareGas = 50_000
OracleExecuteGas = 200_000

FeePayer = "desmos-ibc-profiles"
)

var (
FeeCoins = sdk.NewCoins(sdk.NewCoin("band", sdk.NewInt(0)))
)

// oracleScriptCallData represents the data that should be OBI-encoded and sent to perform an oracle request
type oracleScriptCallData struct {
Application string `obi:"application"`
Expand Down Expand Up @@ -91,6 +74,9 @@ func (k Keeper) StartProfileConnection(
CallData: dataSourceCallData,
}

params := k.GetParams(ctx)
oraclePrams := params.Oracle

// Serialize the call data using the OBI encoding
callDataBz, err := obi.Encode(data)
if err != nil {
Expand All @@ -101,14 +87,14 @@ func (k Keeper) StartProfileConnection(
clientID := sender.String() + "-" + applicationData.Application + "-" + applicationData.Username
packetData := oracletypes.NewOracleRequestPacketData(
clientID,
OracleScriptID,
oraclePrams.ScriptID,
callDataBz,
OracleAskCount,
OracleMinCount,
FeeCoins,
FeePayer,
OraclePrepareGas,
OracleExecuteGas,
oraclePrams.AskCount,
oraclePrams.MinCount,
oraclePrams.FeeAmount,
oraclePrams.FeePayer,
oraclePrams.PrepareGas,
oraclePrams.ExecuteGas,
)

// Create the IBC packet
Expand Down Expand Up @@ -136,7 +122,7 @@ func (k Keeper) StartProfileConnection(
types.ApplicationLinkStateInitialized,
types.NewOracleRequest(
-1,
int64(OracleScriptID),
oraclePrams.ScriptID,
types.NewOracleRequestCallData(applicationData.Application, dataSourceCallData),
clientID,
),
Expand Down
1 change: 1 addition & 0 deletions x/profiles/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func RandomizedGenState(simsState *module.SimulationState) {
RandomNicknameParams(simsState.Rand),
RandomDTagParams(simsState.Rand),
RandomBioParams(simsState.Rand),
RandomOracleParams(simsState.Rand),
),
types.IBCPortID,
nil,
Expand Down
15 changes: 12 additions & 3 deletions x/profiles/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,34 @@ import (

func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.NicknameLenParamsKey),
simulation.NewSimParamChange(types.ModuleName, string(types.NicknameParamsKey),
func(r *rand.Rand) string {
params := RandomNicknameParams(r)
return fmt.Sprintf(`{"min_nickname_len":"%s","max_nickname_len":"%s"}`,
params.MinLength, params.MaxLength)
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.DTagLenParamsKey),
simulation.NewSimParamChange(types.ModuleName, string(types.DTagParamsKey),
func(r *rand.Rand) string {
params := RandomDTagParams(r)
return fmt.Sprintf(`{"min_dtag_len":"%s","max_dtag_len":"%s"}`,
params.MinLength, params.MaxLength)
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.MaxBioLenParamsKey),
simulation.NewSimParamChange(types.ModuleName, string(types.BioParamsKey),
func(r *rand.Rand) string {
params := RandomBioParams(r)
return fmt.Sprintf(`{"max_bio_len":"%s"}`, params)
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.OracleParamsKey),
func(r *rand.Rand) string {
params := RandomOracleParams(r)
return fmt.Sprintf(
`{"script_id":"%d", "ask_count":"%d", "min_count":"%d", "prepare_gas":"%d", "execute_gas":"%d", "fee_payer":"%s", fee_coins:"%s"}`,
params.ScriptID, params.AskCount, params.MinCount, params.PrepareGas, params.ExecuteGas, params.FeePayer, params.FeeAmount.String(),
)
},
),
}
}
25 changes: 25 additions & 0 deletions x/profiles/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ var (
"e1ba4807a15d8579f79cfd90a07fc015e6125565c9271eb94aded0b2ebf86163",
"3f40462915a3e6026a4d790127b95ded4d870f6ab18d9af2fcbc454168255237",
}

feeCoins = sdk.NewCoins(
sdk.NewCoin("band", sdk.NewInt(10)),
sdk.NewCoin("atom", sdk.NewInt(10)),
sdk.NewCoin("desmos", sdk.NewInt(10)),
sdk.NewCoin("akt", sdk.NewInt(10)),
sdk.NewCoin("dvpn", sdk.NewInt(10)),
sdk.NewCoin("daric", sdk.NewInt(10)),
sdk.NewCoin("osmo", sdk.NewInt(10)),
sdk.NewCoin("regen", sdk.NewInt(10)),
)
)

// NewRandomProfiles returns number random profiles
Expand Down Expand Up @@ -158,6 +169,20 @@ func RandomBioParams(r *rand.Rand) types.BioParams {
return types.NewBioParams(randomMax)
}

// RandomOracleParams return a random oracle param
func RandomOracleParams(r *rand.Rand) types.OracleParams {
randomMinCount := uint64(simtypes.RandIntBetween(r, 1, 20))
return types.NewOracleParams(
r.Int63(),
uint64(simtypes.RandIntBetween(r, int(randomMinCount), int(randomMinCount)+50)),
randomMinCount,
uint64(simtypes.RandIntBetween(r, 1, 10000)),
uint64(simtypes.RandIntBetween(r, 1, 10000)),
simtypes.RandStringOfLength(r, 10),
simtypes.RandSubsetCoins(r, feeCoins)...,
)
}

// RandomRelationship picks and returns a random relationships from an array
func RandomRelationship(r *rand.Rand, relationships []types.Relationship) types.Relationship {
idx := r.Intn(len(relationships))
Expand Down
1 change: 1 addition & 0 deletions x/profiles/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestValidateGenesis(t *testing.T) {
types.NewNicknameParams(sdk.NewInt(-1), sdk.NewInt(10)),
types.DefaultDTagParams(),
types.DefaultBioParams(),
types.DefaultOracleParams(),
),
types.IBCPortID,
nil,
Expand Down
Loading

0 comments on commit a549ef7

Please sign in to comment.