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 vote extensions #47

Merged
merged 47 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e19b1c0
bootstrap code for oracle vote extensions
antstalepresh Dec 18, 2023
f80aa19
update voteExtHandler bApp config
antstalepresh Dec 21, 2023
75fec8d
Resolve nil memory pointer issue
antstalepresh Dec 22, 2023
75783d2
cli commands addition
antstalepresh Jan 8, 2024
e7de75a
SetOraclePrices function update to set the price on correct key
antstalepresh Jan 9, 2024
367ab82
oracle extension price change working
antstalepresh Jan 11, 2024
4af9e04
remove unused store service
antstalepresh Jan 11, 2024
d1ca02c
simplification for not required fields
antstalepresh Jan 11, 2024
3fe0966
Merge branch 'sdk-50' of github.com:Team-Kujira/core into oracle-vote…
antstalepresh Jan 11, 2024
9e5bdd3
Update PrepareProposal, ProcessProposal, PreBlocker to handle both de…
antstalepresh Jan 17, 2024
dcff75b
Add oracle endpoint on app.toml for custom configuration
antstalepresh Jan 17, 2024
23d3032
Remove supportedPairs logic and let all the pairs to be submitted
antstalepresh Jan 18, 2024
7dbc33c
Remove unused app/abci.go - legacy implementation of vote extension
antstalepresh Jan 18, 2024
e519d9f
add miss counter using original median and miss counter logic
antstalepresh Jan 22, 2024
ece3b8a
add consensus addr and validator mapping for GetBallotByDenom
antstalepresh Jan 23, 2024
4e5969f
Implement body for compareOraclePrices and compareMissMap
antstalepresh Jan 23, 2024
0bf5027
Add DeleteExchangeRate on PreBlocker & Remove unused code
antstalepresh Jan 24, 2024
44119dd
Add SlashAndResetMissCounters on PreBlocker
antstalepresh Jan 24, 2024
1dcab55
update comments and logging
antstalepresh Jan 25, 2024
1f5a482
simplify PrepareProposal and ProcessProposal to reuse sdk default han…
antstalepresh Jan 25, 2024
fc67377
lint fixes
antstalepresh Jan 26, 2024
d274b90
add unit test for ComputeStakeWeightedPricesAndMissMap and GetBallotB…
antstalepresh Jan 29, 2024
6e2d4fa
set required denoms on unit test
antstalepresh Jan 29, 2024
6af59b5
Write unit test for CompareOraclePrices & CompareMissMap
antstalepresh Jan 30, 2024
f299ca4
add unit test for PrepareProposal
antstalepresh Jan 31, 2024
d5ef346
add unit test for ProcessProposal
antstalepresh Feb 1, 2024
f6c76af
add unit test for PreBlocker
antstalepresh Feb 1, 2024
718bc47
add utility function SetupTest and use it on oracle abci
antstalepresh Feb 1, 2024
8dc920b
fix panic when empty txs pass
antstalepresh Feb 1, 2024
a95cf87
Add unit test for ExtendVoteHandler and VerifyVoteExtensionHandler
antstalepresh Feb 2, 2024
560148b
Threshold check for oracle vote extension
antstalepresh Feb 5, 2024
32f3d9f
Recover unit test for OracleTally
antstalepresh Feb 6, 2024
d160af4
remove abci test
antstalepresh Feb 6, 2024
bf19ff5
resolve sync issue on a new validator when oracle server's off
antstalepresh Feb 7, 2024
2b807f9
simplification
antstalepresh Feb 14, 2024
12b515c
vote extension enable check on PrepareProposal
antstalepresh Feb 14, 2024
a56653f
update prepareProposal for better readability
antstalepresh Feb 14, 2024
c29d16a
return default empty extension when http request fails
antstalepresh Feb 14, 2024
feb2535
Merge branch 'sdk-50' into oracle-vote-extensions
codehans Feb 14, 2024
0fa65a9
Merge branch 'oracle-vote-extensions' of github.com:Team-Kujira/core …
codehans Feb 14, 2024
c63affd
optimistic exec
codehans Feb 14, 2024
b5777ec
ibc-tm
codehans Feb 16, 2024
9f8c7a4
Merge branch 'sdk-50' of github.com:Team-Kujira/core into oracle-vote…
antstalepresh Feb 21, 2024
03985a2
Merge branch 'sdk-50' into oracle-vote-extensions
codehans Feb 22, 2024
7e9f70b
lint
antstalepresh Feb 26, 2024
ffcd41c
lint
antstalepresh Feb 26, 2024
819b141
lint
antstalepresh Feb 26, 2024
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
84 changes: 0 additions & 84 deletions app/abci.go

This file was deleted.

62 changes: 29 additions & 33 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -147,6 +148,7 @@ import (
schedulertypes "github.com/Team-Kujira/core/x/scheduler/types"

"github.com/Team-Kujira/core/x/oracle"
oracleabci "github.com/Team-Kujira/core/x/oracle/abci"
oraclekeeper "github.com/Team-Kujira/core/x/oracle/keeper"
oracletypes "github.com/Team-Kujira/core/x/oracle/types"

Expand Down Expand Up @@ -302,39 +304,6 @@ func New(
std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

// Below we could construct and set an application specific mempool and
// ABCI 1.0 PrepareProposal and ProcessProposal handlers. These defaults are
// already set in the SDK's BaseApp, this shows an example of how to override
// them.
//
// Example:
//
// bApp := baseapp.NewBaseApp(...)
// nonceMempool := mempool.NewSenderNonceMempool()
// abciPropHandler := NewDefaultProposalHandler(nonceMempool, bApp)
//
// bApp.SetMempool(nonceMempool)
// bApp.SetPrepareProposal(abciPropHandler.PrepareProposalHandler())
// bApp.SetProcessProposal(abciPropHandler.ProcessProposalHandler())
//
// Alternatively, you can construct BaseApp options, append those to
// baseAppOptions and pass them to NewBaseApp.
//
// Example:
//
// prepareOpt = func(app *baseapp.BaseApp) {
// abciPropHandler := baseapp.NewDefaultProposalHandler(nonceMempool, app)
// app.SetPrepareProposal(abciPropHandler.PrepareProposalHandler())
// }
// baseAppOptions = append(baseAppOptions, prepareOpt)

// create and set dummy vote extension handler
voteExtOp := func(bApp *baseapp.BaseApp) {
voteExtHandler := NewVoteExtensionHandler()
voteExtHandler.SetHandlers(bApp)
}
baseAppOptions = append(baseAppOptions, voteExtOp)

bApp := baseapp.NewBaseApp(Name, logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand Down Expand Up @@ -632,6 +601,19 @@ func New(
authority,
)

voteExtHandler := oracleabci.NewVoteExtHandler(
logger,
app.OracleKeeper,
)

oracleConfig, err := oracleabci.ReadOracleConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading oracle config: %s", err))
}

bApp.SetExtendVoteHandler(voteExtHandler.ExtendVoteHandler(oracleConfig))
bApp.SetVerifyVoteExtensionHandler(voteExtHandler.VerifyVoteExtensionHandler(oracleConfig))

denomKeeper := denomkeeper.NewKeeper(
appCodec,
keys[denomtypes.StoreKey],
Expand Down Expand Up @@ -1120,6 +1102,20 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

nonceMempool := mempool.NewSenderNonceMempool()
propHandler := oracleabci.NewProposalHandler(
logger,
app.OracleKeeper,
app.StakingKeeper,
app.ModuleManager,
nonceMempool,
bApp,
)
bApp.SetMempool(nonceMempool)
bApp.SetPrepareProposal(propHandler.PrepareProposal())
bApp.SetProcessProposal(propHandler.ProcessProposal())
bApp.SetPreBlocker(propHandler.PreBlocker)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
Expand Down
13 changes: 11 additions & 2 deletions cmd/kujirad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/Team-Kujira/core/app"
"github.com/Team-Kujira/core/app/params"
oracleabci "github.com/Team-Kujira/core/x/oracle/abci"
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -146,7 +147,8 @@ func initAppConfig() (string, interface{}) {
type CustomAppConfig struct {
serverconfig.Config

WASM WASMConfig `mapstructure:"wasm"`
WASM WASMConfig `mapstructure:"wasm"`
Oracle oracleabci.OracleConfig `mapstructure:"oracle"`
}

// Optionally allow the chain developer to overwrite the SDK's default
Expand All @@ -173,6 +175,9 @@ func initAppConfig() (string, interface{}) {
LruSize: 1,
QueryGasLimit: 30000000,
},
Oracle: oracleabci.OracleConfig{
Endpoint: "http://localhost:10171/api/v1/prices",
},
}

customAppTemplate := serverconfig.DefaultConfigTemplate + `
Expand All @@ -181,7 +186,11 @@ func initAppConfig() (string, interface{}) {
query_gas_limit = 30000000
# This is the number of wasm vm instances we keep cached in memory for speed-up
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
lru_size = 0`
lru_size = 0

[oracle]
# Endpoint to query oracle prices for vote extension
endpoint = "http://localhost:10171/api/v1/prices"`

return customAppTemplate, customAppConfig
}
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.21
require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd
cosmossdk.io/store v1.0.0
// cosmossdk.io/tools/rosetta v0.2.1
// cosmossdk.io/x/upgrade v0.0.0
Expand All @@ -22,7 +21,7 @@ require (
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.17.0
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
Expand All @@ -36,7 +35,6 @@ require (

require (
cosmossdk.io/client/v2 v2.0.0-20231103103049-f73a17f75727
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.0
cosmossdk.io/log v1.2.1
cosmossdk.io/tools/confix v0.0.0-20231103111158-e83a20081ced
Expand All @@ -47,7 +45,6 @@ require (
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc6
github.com/hashicorp/go-metrics v0.5.1
golang.org/x/sync v0.3.0
)

require (
Expand All @@ -57,7 +54,10 @@ require (
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/api v0.7.2 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/x/circuit v0.0.0-20231103111158-e83a20081ced // indirect
cosmossdk.io/x/nft v0.0.0-20231103111158-e83a20081ced // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -189,6 +189,7 @@ require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ cosmossdk.io/log v1.2.1 h1:Xc1GgTCicniwmMiKwDxUjO4eLhPxoVdI9vtMW8Ti/uk=
cosmossdk.io/log v1.2.1/go.mod h1:GNSCc/6+DhFIj1aLn/j7Id7PaO8DzNylUZoOYBL9+I4=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd h1:KwV+LjYFc4N+KwUrPtCfKW6m+zIdCI0kz1Zr+RrDW/Y=
cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd/go.mod h1:qnOJ7OPtF1kNzces9lnB3vpeMhQu4uQE9i+h0+vb+RA=
cosmossdk.io/store v1.0.0 h1:6tnPgTpTSIskaTmw/4s5C9FARdgFflycIc9OX8i1tOI=
cosmossdk.io/store v1.0.0/go.mod h1:ABMprwjvx6IpMp8l06TwuMrj6694/QP5NIW+X6jaTYc=
cosmossdk.io/tools/confix v0.0.0-20231103111158-e83a20081ced h1:mWxKV+jXbxoL+80U0cNriByvBhrMxErlGY6GCNEiyC4=
Expand Down
7 changes: 2 additions & 5 deletions proto/kujira/oracle/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ option go_package = "github.com/Team-Kujira/core/x/oracle/types";
// GenesisState defines the oracle module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated FeederDelegation feeder_delegations = 2 [(gogoproto.nullable) = false];
repeated ExchangeRateTuple exchange_rates = 3
repeated ExchangeRateTuple exchange_rates = 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should retain the same indexes for the same properties? Make an old genesis export compatible with the new module

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genesis encoding/decoding's done in JSON and proto index won't be affected I believe.

[(gogoproto.castrepeated) = "ExchangeRateTuples", (gogoproto.nullable) = false];
repeated MissCounter miss_counters = 4 [(gogoproto.nullable) = false];
repeated AggregateExchangeRatePrevote aggregate_exchange_rate_prevotes = 5 [(gogoproto.nullable) = false];
repeated AggregateExchangeRateVote aggregate_exchange_rate_votes = 6 [(gogoproto.nullable) = false];
repeated MissCounter miss_counters = 3 [(gogoproto.nullable) = false];
}

// FeederDelegation is the address for where oracle feeder authority are
Expand Down
28 changes: 0 additions & 28 deletions proto/kujira/oracle/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,6 @@ message Denom {
string name = 1 [(gogoproto.moretags) = "yaml:\"name\""];
}

// struct for aggregate prevoting on the ExchangeRateVote.
// The purpose of aggregate prevote is to hide vote exchange rates with hash
// which is formatted as hex string in SHA256("{salt}:{exchange rate}{denom},...,{exchange rate}{denom}:{voter}")
message AggregateExchangeRatePrevote {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string hash = 1 [(gogoproto.moretags) = "yaml:\"hash\""];
string voter = 2 [(gogoproto.moretags) = "yaml:\"voter\""];
uint64 submit_block = 3 [(gogoproto.moretags) = "yaml:\"submit_block\""];
}

// MsgAggregateExchangeRateVote - struct for voting on exchange rates.
message AggregateExchangeRateVote {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

repeated ExchangeRateTuple exchange_rate_tuples = 1 [
(gogoproto.moretags) = "yaml:\"exchange_rate_tuples\"",
(gogoproto.castrepeated) = "ExchangeRateTuples",
(gogoproto.nullable) = false
];

string voter = 2 [(gogoproto.moretags) = "yaml:\"voter\""];
}

// ExchangeRateTuple - struct to store interpreted exchange rates data to store
message ExchangeRateTuple {
option (gogoproto.equal) = false;
Expand Down
Loading
Loading