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

feat: Oracle vote extension handler #396

Merged
merged 29 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6c75a76
feat: Oracle vote extension handler
rbajollari Mar 4, 2024
19b255e
fix preblocker init
rbajollari Mar 6, 2024
c839a04
use validator in pf config for vote extensions
rbajollari Mar 6, 2024
b4f7f25
lint
rbajollari Mar 6, 2024
c782b75
add verification in process proposal
rbajollari Mar 7, 2024
d6acf4c
process proposal verifaction
rbajollari Mar 7, 2024
d1ec5de
setup oracle abci integration test suite
rbajollari Mar 8, 2024
81cbe3c
use vote extension signer for exchange rate generation
rbajollari Mar 11, 2024
d09cbd6
add vote extention and preblocker integration tests
rbajollari Mar 27, 2024
9e234a0
fix preblocker test
rbajollari Mar 27, 2024
69ea14f
nolint spacing revert
rbajollari Mar 27, 2024
6de9f10
Merge branch 'main' into ryan/vote-extensions
rbajollari Mar 28, 2024
b96a12b
go mod tidy
rbajollari Mar 28, 2024
501537c
add abci propsal tests
rbajollari Apr 2, 2024
336f5a5
update price feeder import
rbajollari Apr 3, 2024
a8b13ec
add price feeder app config
rbajollari Apr 4, 2024
a9584fa
fix e2e test setup
rbajollari Apr 8, 2024
c5f313a
pr comments
rbajollari Apr 9, 2024
26084fb
git rm cached ignore files
rbajollari Apr 9, 2024
fd32880
lint
rbajollari Apr 9, 2024
87c9aeb
import latest pf version
rbajollari Apr 9, 2024
97c881d
Update .gitignore
rbajollari Apr 9, 2024
5ae25dd
Update x/oracle/abci/proposal.go
rbajollari Apr 9, 2024
8b67675
Update x/oracle/abci/voteextension.go
rbajollari Apr 9, 2024
e47a9e9
round 2 pr comments
rbajollari Apr 9, 2024
128313a
README update
rbajollari Apr 9, 2024
3726583
super lint
rbajollari Apr 9, 2024
07bb0ad
Merge branch 'main' into ryan/vote-extensions
rbajollari Apr 9, 2024
ed7a984
go mod tidy
rbajollari Apr 9, 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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ release/
.idea/
.vscode/
.DS_Store
build
build
buf.work.yaml
proto/buf.gen.pulsar.yaml
proto/buf.gen.sta.yaml
proto/buf.gen.swagger.yaml
rbajollari marked this conversation as resolved.
Show resolved Hide resolved
proto/buf.gen.ts.yaml
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.1.11-0.20240403153904-aeda5a5840a6
rbajollari marked this conversation as resolved.
Show resolved Hide resolved
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.2+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
Loading