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

Oracle params improvement #547

Merged
merged 36 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6b39b80
Init oracle params
dadamu Jul 8, 2021
3baca61
Replace hard codedoracle params in relay
dadamu Jul 8, 2021
cb2a628
Fix tests
dadamu Jul 8, 2021
1d7695f
Add validate function for oracle params
dadamu Jul 8, 2021
5984f5e
Add sim test
dadamu Jul 8, 2021
a17c949
Improve oracle params validate and sim test functions
dadamu Jul 9, 2021
69bf97e
Import oracle constants.go
dadamu Jul 9, 2021
fbd66bc
Fix typo
dadamu Jul 9, 2021
790d0a3
Fix oracle params validate
dadamu Jul 9, 2021
61f74ea
Update CHANGELOG
dadamu Jul 9, 2021
912dd30
Fix sim tests error
dadamu Jul 9, 2021
c6de468
Merge branch 'master' of github.com:desmos-labs/desmos into paul/orac…
dadamu Jul 9, 2021
d7a98bd
Merge branch 'master' of github.com:desmos-labs/desmos into paul/orac…
dadamu Jul 12, 2021
2d03e77
Remove maxmum checking
dadamu Jul 12, 2021
32a3dcf
Remove default oracle params value
dadamu Jul 12, 2021
f6d05da
Remove unused tests
dadamu Jul 12, 2021
b55c97b
Revert tests
dadamu Jul 12, 2021
c6f5491
Fix typo
dadamu Jul 12, 2021
46a1665
Update x/profiles/types/models_params.go
dadamu Jul 12, 2021
470e794
Update x/profiles/types/models_params.go
dadamu Jul 12, 2021
b188c72
Update x/profiles/simulation/utils.go
dadamu Jul 12, 2021
a80a286
Update x/profiles/types/models_params.go
dadamu Jul 12, 2021
cffebfd
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
91acf7c
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
f326669
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
56c5cb5
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
9b9b837
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
c261288
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
2c37eae
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
1409962
Update proto/desmos/profiles/v1beta1/models_params.proto
dadamu Jul 12, 2021
9793894
Regenerate proto
dadamu Jul 12, 2021
e86211c
Merge branch 'master' of github.com:desmos-labs/desmos into paul/orac…
RiccardoM Jul 12, 2021
9cbd87c
Fixed merge conflicts
RiccardoM Jul 12, 2021
24e03ee
Fix error
dadamu Jul 12, 2021
322419c
Fixed build errors
RiccardoM Jul 12, 2021
8e6a99c
Merge remote-tracking branch 'origin/paul/oracle-params-improvement' …
RiccardoM Jul 12, 2021
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 @@ -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 [
dadamu marked this conversation as resolved.
Show resolved Hide resolved
(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\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

// MinCount represents the minimum count of oracles that should complete the
// verification successfully
uint64 min_count = 3 [ (gogoproto.moretags) = "yaml:\"min_count\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

// 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\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

// 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\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

// 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\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

// FeeAmount represents the amount of fees to be payed in order to execute the
// oracle script
repeated cosmos.base.v1beta1.Coin fee_amount = 7 [
dadamu marked this conversation as resolved.
Show resolved Hide resolved
(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