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 11 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 @@ -3,6 +3,7 @@
- Improved pagination ([#544](https://github.com/desmos-labs/desmos/pull/544))
- 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))
- Made oracle-related data on-chain parameters ([#547](https://github.com/desmos-labs/desmos/pull/547))

# Version 0.17.0
## Changes
Expand Down
31 changes: 31 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 @@ -25,6 +26,11 @@ message Params {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max_bio_length\""
];

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

// NicknameParams defines the parameters related to the profiles nicknames
Expand Down Expand Up @@ -64,3 +70,28 @@ message DTagParams {
(gogoproto.customname) = "MaxDTagLength"
];
}

// OracleParams defines the parameters related to the profile oracle
dadamu marked this conversation as resolved.
Show resolved Hide resolved
message OracleParams {
option (gogoproto.goproto_getters) = false;

int64 script_id = 1 [
dadamu marked this conversation as resolved.
Show resolved Hide resolved
(gogoproto.customname) = "ScriptID",
(gogoproto.moretags) = "yaml:\"script_id\""
];
uint64 ask_count = 2 [ (gogoproto.moretags) = "yaml:\"ask_count\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

uint64 min_count = 3 [ (gogoproto.moretags) = "yaml:\"min_count\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

uint64 prepare_gas = 4 [ (gogoproto.moretags) = "yaml:\"prepare_gas\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

uint64 execute_gas = 5 [ (gogoproto.moretags) = "yaml:\"execute_gas\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

string fee_payer = 6 [ (gogoproto.moretags) = "yaml:\"fee_payer\"" ];
dadamu marked this conversation as resolved.
Show resolved Hide resolved

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\""
];
}
25 changes: 25 additions & 0 deletions x/oracle/types/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package types

// nolint
const (
DoNotModify = "[do-not-modify]"

MaxNameLength = 128
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
MaxDescriptionLength = 4096
MaxClientIDLength = 128
MaxRequestKeyLength = 128
MaxSchemaLength = 512
MaxURLLength = 128

MaxExecutableSize = 8 * 1024 // 8kB
MaxWasmCodeSize = 512 * 1024 // 512kB
MaxCompiledWasmCodeSize = 1 * 1024 * 1024 // 1MB
MaxDataSize = 256 // 256B

MaximumOwasmGas = 20000000 // The half of block gas limit
)

// nolint
var (
DoNotModifyBytes = []byte(DoNotModify)
)
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)),
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)),
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)),
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)),
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)),
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)),
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)),
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/legacy/v0160/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ func MigrateParams(ctx sdk.Context, amino *codec.LegacyAmino, subspace paramstyp
dTagParams.MaxDTagLength,
),
maxBioLen,
types.DefaultOracleParams(),
), nil
}
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
9 changes: 9 additions & 0 deletions x/profiles/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,14 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
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(),
)
},
),
}
}
31 changes: 31 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 @@ -157,6 +168,26 @@ func RandomBioParams(r *rand.Rand) sdk.Int {
return sdk.NewInt(int64(simtypes.RandIntBetween(r, 500, 1000)))
}

// RandomOracleParams return a random oracle param
func RandomOracleParams(r *rand.Rand) types.OracleParams {
randomID := r.Int63()
randomMinCount := uint64(simtypes.RandIntBetween(r, 1, 20))
randomAskCount := uint64(simtypes.RandIntBetween(r, int(randomMinCount), int(randomMinCount)+50))
randomPrepareGas := uint64(simtypes.RandIntBetween(r, 1, 10000))
randomExecuteGas := uint64(simtypes.RandIntBetween(r, 1, 10000))
randomFeepayer := simtypes.RandStringOfLength(r, 10)
randomFeeAmount := simtypes.RandSubsetCoins(r, feeCoins)
return types.NewOracleParams(
randomID,
randomAskCount,
randomMinCount,
randomPrepareGas,
randomExecuteGas,
randomFeepayer,
randomFeeAmount...,
)
dadamu marked this conversation as resolved.
Show resolved Hide resolved
}

// 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.DefaultMaxBioLength,
types.DefaultOracleParams(),
),
types.IBCPortID,
nil,
Expand Down
Loading