Skip to content

Commit

Permalink
feat: Oracle vote extension handler (#396)
Browse files Browse the repository at this point in the history
* feat: Oracle vote extension handler

* fix preblocker init

* use validator in pf config for vote extensions

* lint

* add verification in process proposal

* process proposal verifaction

* setup oracle abci integration test suite

* use vote extension signer for exchange rate generation

* add vote extention and preblocker integration tests

* fix preblocker test

* nolint spacing revert

* go mod tidy

* add abci propsal tests

* update price feeder import

* add price feeder app config

* fix e2e test setup

* pr comments

* git rm cached ignore files

* lint

* import latest pf version

* Update .gitignore

Co-authored-by: Adam Wozniak <[email protected]>

* Update x/oracle/abci/proposal.go

Co-authored-by: Adam Wozniak <[email protected]>

* Update x/oracle/abci/voteextension.go

Co-authored-by: Adam Wozniak <[email protected]>

* round 2 pr comments

* README update

* super lint

* go mod tidy

---------

Co-authored-by: Adam Wozniak <[email protected]>
  • Loading branch information
rbajollari and adamewozniak authored Apr 10, 2024
1 parent 5e4d57e commit 15abd95
Show file tree
Hide file tree
Showing 37 changed files with 1,727 additions and 365 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ release/
.idea/
.vscode/
.DS_Store
build
build
# files generated by ignite cli
buf.work.yaml
proto/buf.gen.pulsar.yaml
proto/buf.gen.sta.yaml
proto/buf.gen.swagger.yaml
proto/buf.gen.ts.yaml
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ To install the `ojod` binary:
$ make install
```

## Run Node

Example command structure for running a node with a price feeder config file located at `./price-feeder.example.config` (See [price-feeder](https://github.com/ojo-network/price-feeder) repo for more information on configuring an Ojo price feeder)

```shell
$ ojod start --pricefeeder.config_path=./price-feeder.example.config --pricefeeder.log_level="INFO" --pricefeeder.chain_config=TRUE --pricefeeder.oracle_tick_time=5s
```

## Networks

Ojo currently has three active public networks:
Expand Down
30 changes: 29 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ import (
airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper"
airdroptypes "github.com/ojo-network/ojo/x/airdrop/types"

"github.com/ojo-network/ojo/pricefeeder"
oracleabci "github.com/ojo-network/ojo/x/oracle/abci"

customante "github.com/ojo-network/ojo/ante"
)

Expand Down Expand Up @@ -216,6 +219,8 @@ type App struct {

// module configurator
configurator module.Configurator

PriceFeeder *pricefeeder.PriceFeeder
}

// New returns a reference to an initialized blockchain app
Expand Down Expand Up @@ -723,14 +728,37 @@ func New(
app.StateSimulationManager = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules)
app.StateSimulationManager.RegisterStoreDecoders()

proposalHandler := oracleabci.NewProposalHandler(
app.Logger(),
app.OracleKeeper,
app.StakingKeeper,
)
app.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.SetProcessProposal(proposalHandler.ProcessProposalHandler())

preBlockHandler := oracleabci.NewPreBlockHandler(
app.Logger(),
app.OracleKeeper,
)
app.SetPreBlocker(preBlockHandler.PreBlocker())

// initialize empty price feeder object to pass reference into vote extension handler
app.PriceFeeder = &pricefeeder.PriceFeeder{}
voteExtensionsHandler := oracleabci.NewVoteExtensionHandler(
app.Logger(),
app.OracleKeeper,
app.PriceFeeder,
)
app.SetExtendVoteHandler(voteExtensionsHandler.ExtendVoteHandler())
app.SetVerifyVoteExtensionHandler(voteExtensionsHandler.VerifyVoteExtensionHandler())

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(txConfig)
Expand Down
33 changes: 30 additions & 3 deletions cmd/ojod/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"io"
"os"
"time"

"cosmossdk.io/log"
"cosmossdk.io/tools/confix/cmd"
Expand Down Expand Up @@ -55,7 +56,8 @@ func initAppConfig() (string, interface{}) {

type CustomAppConfig struct {
serverconfig.Config
WASM WASMConfig `mapstructure:"wasm"`
WASM WASMConfig `mapstructure:"wasm"`
PriceFeeder pricefeeder.AppConfig `mapstructure:"pricefeeder"`
}

// here we set a default initial app.toml values for validators.
Expand All @@ -68,6 +70,12 @@ func initAppConfig() (string, interface{}) {
LruSize: 1,
QueryGasLimit: 300000,
},
PriceFeeder: pricefeeder.AppConfig{
ConfigPath: "",
ChainConfig: true,
LogLevel: "info",
OracleTickTime: time.Second * 5,
},
}

customAppTemplate := serverconfig.DefaultConfigTemplate + `
Expand All @@ -76,7 +84,7 @@ func initAppConfig() (string, interface{}) {
query_gas_limit = 300000
# 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` + pricefeeder.DefaultConfigTemplate

return customAppTemplate, customAppConfig
}
Expand Down Expand Up @@ -120,6 +128,20 @@ func initRootCmd(
txCommand(),
keys.Commands(),
)

// add price feeder flags
rootCmd.PersistentFlags().String(pricefeeder.FlagConfigPath, "", "Path to price feeder config file")
rootCmd.PersistentFlags().Bool(
pricefeeder.FlagChainConfig,
true,
"Specifies whether the currency pair providers and currency deviation threshold values should",
)
rootCmd.PersistentFlags().String(pricefeeder.FlagLogLevel, "", "Log level of price feeder process")
rootCmd.PersistentFlags().Duration(
pricefeeder.FlagOracleTickTime,
time.Second*5,
"Time interval that the price feeder's oracle process waits before fetching for new prices",
)
}

// genesisCommand builds genesis-related `simd genesis` command. Users may
Expand Down Expand Up @@ -205,10 +227,15 @@ func newApp(
)

// start price feeder
appConfig, err := pricefeeder.ReadConfigFromAppOpts(appOpts)
if err != nil {
panic(err)
}

var oracleGenState oracletypes.GenesisState
app.AppCodec().MustUnmarshalJSON(app.DefaultGenesis()[oracletypes.ModuleName], &oracleGenState)
go func() {
err := pricefeeder.Start(oracleGenState.Params)
err := app.PriceFeeder.Start(oracleGenState.Params, appConfig)
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/ojod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: appparams.Name + "d",
Short: "Ojo application network daemon and client",
Long: `A daemon and client for interacting with the Ojo network. Ojo is a
Universal Capital Facility that can collateralize assets on one blockchain
towards borrowing assets on another blockchain.`,
Long: `A daemon and client for interacting with the Ojo network. Ojo is an
oracle platform which other blockchains and smart contracts can use to receive
up-to-date and accurate data.`,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
Expand Down
7 changes: 7 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ genesis:
staking:
params:
bond_denom: uojo
consensus:
params:
abci:
vote_extensions_enable_height: "2"
chain_id: ojo-testnet
validators:
- name: alice
bonded: 33500000000000uojo
app:
pricefeeder:
config_path: "./pricefeeder/price-feeder.example.toml"
23 changes: 22 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
cosmossdk.io/x/tx v0.13.1
cosmossdk.io/x/upgrade v0.1.0
github.com/armon/go-metrics v0.4.1
github.com/bufbuild/buf v1.15.1
github.com/cometbft/cometbft v0.38.5
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-proto v1.0.0-beta.4
Expand All @@ -32,9 +33,10 @@ require (
github.com/golangci/golangci-lint v1.55.2
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1
github.com/mgechev/revive v1.3.6
github.com/mitchellh/mapstructure v1.5.0
github.com/ojo-network/price-feeder v0.1.10-0.20240221234245-b3d7d675adc9
github.com/ojo-network/price-feeder v0.2.0
github.com/ory/dockertest/v3 v3.10.0
github.com/rs/zerolog v1.32.0
github.com/spf13/cast v1.6.0
Expand Down Expand Up @@ -98,6 +100,8 @@ require (
github.com/breml/errchkjson v0.3.6 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/bufbuild/connect-go v1.5.2 // indirect
github.com/bufbuild/protocompile v0.6.0 // indirect
github.com/butuzov/ireturn v0.2.2 // indirect
github.com/butuzov/mirror v1.1.0 // indirect
github.com/catenacyber/perfsprint v0.2.0 // indirect
Expand All @@ -121,6 +125,7 @@ require (
github.com/cosmos/iavl v1.0.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/curioswitch/go-reassign v0.2.0 // indirect
Expand All @@ -134,7 +139,9 @@ require (
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/docker/cli v24.0.2+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -144,13 +151,16 @@ require (
github.com/ettle/strcase v0.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/firefart/nonamedreturns v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/ghostiam/protogetter v0.2.3 // indirect
github.com/go-chi/chi/v5 v5.0.8 // indirect
github.com/go-critic/go-critic v0.9.0 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
Expand All @@ -171,6 +181,7 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/uuid/v5 v5.0.0 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -187,7 +198,9 @@ require (
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.13.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down Expand Up @@ -223,6 +236,7 @@ require (
github.com/imdario/mergo v0.3.16 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jdxcode/netrc v0.0.0-20221124155335-4616370d1a84 // indirect
github.com/jgautheron/goconst v1.6.0 // indirect
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
Expand All @@ -234,6 +248,7 @@ require (
github.com/kisielk/gotool v1.0.0 // indirect
github.com/kkHAIKE/contextcheck v1.1.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kulti/thelper v0.6.3 // indirect
Expand Down Expand Up @@ -263,6 +278,7 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/moricho/tparallel v0.3.1 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
github.com/nishanths/exhaustive v0.11.0 // indirect
Expand All @@ -277,7 +293,9 @@ require (
github.com/opencontainers/runc v1.1.7 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/polyfloyd/go-errorlint v1.4.5 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
Expand All @@ -293,6 +311,7 @@ require (
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryancurrah/gomodguard v1.3.0 // indirect
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down Expand Up @@ -347,8 +366,10 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.tmz.dev/musttag v0.7.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
Expand Down
Loading

0 comments on commit 15abd95

Please sign in to comment.