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 all 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.

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
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