Skip to content

Commit

Permalink
Merge pull request #47 from Team-Kujira/oracle-vote-extensions
Browse files Browse the repository at this point in the history
Oracle vote extensions
  • Loading branch information
antstalepresh authored Feb 26, 2024
2 parents 47fba8a + 819b141 commit 0a45539
Show file tree
Hide file tree
Showing 51 changed files with 2,076 additions and 7,659 deletions.
84 changes: 0 additions & 84 deletions app/abci.go

This file was deleted.

66 changes: 33 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 @@ -119,6 +120,7 @@ import (
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand Down Expand Up @@ -147,6 +149,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 @@ -283,6 +286,8 @@ func New(
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
baseAppOptions = append(baseAppOptions, baseapp.SetOptimisticExecution())

interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
Expand All @@ -302,39 +307,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 @@ -634,6 +606,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 @@ -878,6 +863,7 @@ func New(
upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
ibctm.NewAppModule(),
params.NewAppModule(app.ParamsKeeper),
transferModule,

Expand Down Expand Up @@ -1122,6 +1108,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
2 changes: 1 addition & 1 deletion app/openapiconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var index embed.FS
func Handler(title, specURL string) http.HandlerFunc {
t, _ := template.ParseFS(index, "index.tpl")

return func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, _ *http.Request) {
t.Execute(w, struct { //nolint:errcheck
Title string
URL string
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
3 changes: 1 addition & 2 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.1
cosmossdk.io/math v1.2.0
cosmossdk.io/simapp v0.0.0-20231107193120-9814f684b9dd
cosmossdk.io/store v1.0.2
// 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.1
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.8.0
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.3.0 h1:L0Z0XstClo2kOU4h3V1iDoE5Ji64sg5HLOogzGg67Oo=
cosmossdk.io/log v1.3.0/go.mod h1:HIDyvWLqZe2ovlWabsDN4aPMpY/nUEquAhgfTf2ZzB8=
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.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0=
cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs=
cosmossdk.io/tools/confix v0.1.0 h1:2OOZTtQsDT5e7P3FM5xqM0bPfluAxZlAwxqaDmYBE+E=
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
[(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

0 comments on commit 0a45539

Please sign in to comment.