Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jun 4, 2024
1 parent de0ce36 commit f38882c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 148 deletions.
148 changes: 9 additions & 139 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"path/filepath"
"time"

"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
Expand Down Expand Up @@ -46,10 +49,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
Expand Down Expand Up @@ -170,20 +171,10 @@ import (
keepers "github.com/public-awesome/stargaze/v14/app/keepers"
sgstatesync "github.com/public-awesome/stargaze/v14/internal/statesync"

// slinky
"github.com/skip-mev/slinky/abci/proposals"
compression "github.com/skip-mev/slinky/abci/strategies/codec"
"github.com/skip-mev/slinky/abci/strategies/currencypair"
"github.com/skip-mev/slinky/abci/ve"
"github.com/skip-mev/slinky/pkg/math/voteweighted"
oracleclient "github.com/skip-mev/slinky/service/clients/oracle"
servicemetrics "github.com/skip-mev/slinky/service/metrics"
"github.com/skip-mev/slinky/x/oracle"
oraclekeeper "github.com/skip-mev/slinky/x/oracle/keeper"
oracletypes "github.com/skip-mev/slinky/x/oracle/types"

oraclepreblock "github.com/skip-mev/slinky/abci/preblock/oracle"
oracleconfig "github.com/skip-mev/slinky/oracle/config"
"github.com/skip-mev/slinky/x/marketmap"
marketmapkeeper "github.com/skip-mev/slinky/x/marketmap/keeper"
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types"
Expand Down Expand Up @@ -997,41 +988,12 @@ func NewStargazeApp(
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)

// Read general config from app-opts, and construct oracle service.
cfg, err := oracleconfig.ReadConfigFromAppOpts(appOpts)
if err != nil {
panic(err)
}

// If app level instrumentation is enabled, then wrap the oracle service with a metrics client
// to get metrics on the oracle service (for ABCI++). This will allow the instrumentation to track
// latency in VerifyVoteExtension requests and more.
oracleMetrics, err := servicemetrics.NewMetricsFromConfig(cfg, app.ChainID())
if err != nil {
panic(err)
}

// Create the oracle service.
app.oracleClient, err = oracleclient.NewClientFromConfig(
cfg,
app.Logger().With("client", "oracle"),
oracleMetrics,
)
if err != nil {
panic(err)
}

// Connect to the oracle service (default timeout of 5 seconds).
go func() {
if err := app.oracleClient.Start(context.Background()); err != nil {
app.Logger().Error("failed to start oracle client", "err", err)
panic(err)
}

app.Logger().Info("started oracle client", "address", cfg.OracleAddress)
}()
// -------------------------------------------------------------------- //
// APP INITIALIZATION //
// -------------------------------------------------------------------- //

// initialize BaseApp
// Create the proposal handler that will be used to fill proposals with
// transactions and oracle data.
proposalHandler := proposals.NewProposalHandler(
app.Logger(),
baseapp.NoOpPrepareProposal(),
Expand All @@ -1051,10 +1013,6 @@ func NewStargazeApp(
app.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.SetProcessProposal(proposalHandler.ProcessProposalHandler())

app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

// Create the aggregation function that will be used to aggregate oracle data
// from each validator.
aggregatorFn := voteweighted.MedianFromContext(
Expand All @@ -1080,26 +1038,8 @@ func NewStargazeApp(
compression.NewZStdCompressor(),
),
)
oraclePreblocker := oraclePreBlockHandler.PreBlocker()
preBlocker := func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
// call app's preblocker first in case there is changes made on upgrades
// that can modify state and lead to serialization/deserialization issues
resp, err := app.PreBlocker(ctx, req)
if err != nil {
return resp, err
}

// oracle preblocker sends empty response pre block so it can ignored
_, err = oraclePreblocker(ctx, req)
if err != nil {
return &sdk.ResponsePreBlock{}, err
}

// return resp from app's preblocker which can return consensus param changed flag
return resp, nil
}

app.SetPreBlocker(preBlocker)
app.SetPreBlocker(oraclePreBlockHandler.PreBlocker())

// Create the vote extensions handler that will be used to extend and verify
// vote extensions (i.e. oracle data).
Expand Down Expand Up @@ -1147,76 +1087,6 @@ func NewStargazeApp(
panic(err)
}

// -------------------------------------------------------------------- //
// APP INITIALIZATION //
// -------------------------------------------------------------------- //

// Create the proposal handler that will be used to fill proposals with
// transactions and oracle data.
proposalHandler := proposals.NewProposalHandler(
app.Logger(),
baseapp.NoOpPrepareProposal(),
baseapp.NoOpProcessProposal(),
ve.NewDefaultValidateVoteExtensionsFn(app.Keepers.StakingKeeper),
compression.NewCompressionVoteExtensionCodec(
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
compression.NewCompressionExtendedCommitCodec(
compression.NewDefaultExtendedCommitCodec(),
compression.NewZStdCompressor(),
),
currencypair.NewDeltaCurrencyPairStrategy(app.Keepers.OracleKeeper),
oracleMetrics,
)
app.SetPrepareProposal(proposalHandler.PrepareProposalHandler())
app.SetProcessProposal(proposalHandler.ProcessProposalHandler())

// Create the aggregation function that will be used to aggregate oracle data
// from each validator.
aggregatorFn := voteweighted.MedianFromContext(
app.Logger(),
app.Keepers.StakingKeeper,
voteweighted.DefaultPowerThreshold,
)

// Create the pre-finalize block hook that will be used to apply oracle data
// to the state before any transactions are executed (in finalize block).
oraclePreBlockHandler := oraclepreblock.NewOraclePreBlockHandler(
app.Logger(),
aggregatorFn,
app.Keepers.OracleKeeper,
oracleMetrics,
currencypair.NewDeltaCurrencyPairStrategy(app.Keepers.OracleKeeper),
compression.NewCompressionVoteExtensionCodec(
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
compression.NewCompressionExtendedCommitCodec(
compression.NewDefaultExtendedCommitCodec(),
compression.NewZStdCompressor(),
),
)

app.SetPreBlocker(oraclePreBlockHandler.PreBlocker())

// Create the vote extensions handler that will be used to extend and verify
// vote extensions (i.e. oracle data).
voteExtensionsHandler := ve.NewVoteExtensionHandler(
app.Logger(),
app.oracleClient,
time.Second,
currencypair.NewDeltaCurrencyPairStrategy(app.Keepers.OracleKeeper),
compression.NewCompressionVoteExtensionCodec(
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
oraclePreBlockHandler.PreBlocker(),
oracleMetrics,
)
app.SetExtendVoteHandler(voteExtensionsHandler.ExtendVoteHandler())
app.SetVerifyVoteExtensionHandler(voteExtensionsHandler.VerifyVoteExtensionHandler())

app.SetAnteHandler(anteHandler)
app.SetPostHandler(postHandler)
app.RegisterUpgradeHandlers(configurator)
Expand Down
9 changes: 1 addition & 8 deletions app/params/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package params

import (
"fmt"
"time"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -43,13 +42,7 @@ func DefaultConfig() (string, interface{}) {
Config: *serverConfig,
Oracle: oracleConfig,
Wasm: wasmConfig,
Oracle: oracleconfig.AppConfig{
Enabled: false,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 1,
MetricsEnabled: false,
},
}

return CustomconfigTemplate(wasmConfig, customConfig.Oracle), customConfig
return CustomconfigTemplate(wasmConfig), customConfig
}
2 changes: 1 addition & 1 deletion e2e/slinky/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ require (
github.com/cosmos/ibc-apps/modules/ibc-hooks/v8 v8.0.0-00010101000000-000000000000 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0 // indirect
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240208183954-71fa5c9fd708 // indirect
github.com/cosmos/ibc-go/v8 v8.2.1 // indirect
github.com/cosmos/ibc-go/v8 v8.3.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down
1 change: 1 addition & 0 deletions e2e/slinky/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240208183954-71f
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240208183954-71fa5c9fd708/go.mod h1:Jn7QCHDIa4DknrRUwJvwpGPU5Htgka0k5W6tuEckwUk=
github.com/cosmos/ibc-go/v8 v8.2.1 h1:MTsnZZjxvGD4Fv5pYyx5UkELafSX0rlPt6IfsE2BpTQ=
github.com/cosmos/ibc-go/v8 v8.2.1/go.mod h1:wj3qx75iC/XNnsMqbPDCIGs0G6Y3E/lo3bdqCyoCy+8=
github.com/cosmos/ibc-go/v8 v8.3.1/go.mod h1:izwHZvn9lKrBn8xWj0aXWut6HKcwHMPD3uyuvOJoPSA=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/interchain-security/v5 v5.0.0 h1:iwHu1nFbXuYfa13isEgm6hkHU+2t/t56YjcfyP3PnQA=
Expand Down

0 comments on commit f38882c

Please sign in to comment.