Skip to content

Commit

Permalink
Showing 13 changed files with 1,126 additions and 602 deletions.
25 changes: 2 additions & 23 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
@@ -93,7 +93,6 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
"go.uber.org/zap"
"google.golang.org/grpc"

// App
@@ -1545,15 +1544,8 @@ func (app *App) initOracle(pricesTxDecoder process.UpdateMarketPriceTxDecoder) {
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
),
// We are not using the slinky PreBlocker, so there is no need to pass in PreBlocker here for
// VE handler to work properly.
// Currently the clob PreBlocker assumes that it will only be called during the normal ABCI
// PreBlocker step. Passing in the app PreBlocker here will break that assumption by causing
// the clob PreBlocker to be called unexpectedly. This to leads improperly initialized clob state
// which results in the next block being committed incorrectly.
func(_ sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return nil, nil
},
// TODO we can move the UpdateMarketPrices in extend vote to this in the future.
vote_extensions.NoopPriceApplier{},
app.oracleMetrics,
)

@@ -1576,19 +1568,6 @@ func (app *App) initOracleMetrics(appOpts servertypes.AppOptions) {
if err != nil {
panic(err)
}
// run prometheus metrics
if cfg.MetricsEnabled {
promLogger, err := zap.NewProduction()
if err != nil {
panic(err)
}
app.oraclePrometheusServer, err = promserver.NewPrometheusServer(cfg.PrometheusServerAddress, promLogger)
if err != nil {
panic(err)
}
// start the prometheus server
go app.oraclePrometheusServer.Start()
}
app.oracleMetrics = oracleMetrics
}

1 change: 0 additions & 1 deletion protocol/app/vote_extensions/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -15,5 +15,4 @@ type PricesKeeper interface {
ctx sdk.Context,
updates []*pricestypes.MsgUpdateMarketPrices_MarketPrice,
) (err error)
GetPrevBlockCPCounter(ctx sdk.Context) (uint64, error)
}
12 changes: 12 additions & 0 deletions protocol/app/vote_extensions/extend_vote_handler.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ package vote_extensions

import (
"fmt"
slinkytypes "github.com/skip-mev/slinky/pkg/types"
"math/big"

cometabci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -19,6 +21,16 @@ type ExtendVoteHandler struct {
PricesKeeper PricesKeeper
}

type NoopPriceApplier struct{}

func (n NoopPriceApplier) ApplyPricesFromVoteExtensions(
_ sdk.Context, _ *cometabci.RequestFinalizeBlock) (map[slinkytypes.CurrencyPair]*big.Int, error) {
return nil, nil
}
func (n NoopPriceApplier) GetPricesForValidator(_ sdk.ConsAddress) map[slinkytypes.CurrencyPair]*big.Int {
return nil
}

// ExtendVoteHandler returns a sdk.ExtendVoteHandler, responsible for the following:
// 1. Decoding the x/prices MsgUpdateMarketPrices in the current block - fail on errors
// 2. Validating the proposed MsgUpdateMarketPrices in accordance with the ProcessProposal check
9 changes: 4 additions & 5 deletions protocol/cmd/dydxprotocold/cmd/config.go
Original file line number Diff line number Diff line change
@@ -55,11 +55,10 @@ func initAppConfig() (string, *DydxAppConfig) {
appConfig := DydxAppConfig{
Config: *srvCfg,
Oracle: oracleconfig.AppConfig{
Enabled: true,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 2,
MetricsEnabled: false,
PrometheusServerAddress: "",
Enabled: true,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 2,
MetricsEnabled: false,
},
}

19 changes: 4 additions & 15 deletions protocol/daemons/flags/flags.go
Original file line number Diff line number Diff line change
@@ -112,11 +112,10 @@ func GetDefaultDaemonFlags() DaemonFlags {
},
Slinky: SlinkyFlags{
AppConfig: oracleconfig.AppConfig{
Enabled: true,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 2,
MetricsEnabled: true,
PrometheusServerAddress: "0.0.0.0:8001",
Enabled: true,
OracleAddress: "localhost:8080",
ClientTimeout: time.Second * 2,
MetricsEnabled: true,
},
},
}
@@ -218,11 +217,6 @@ func AddDaemonFlagsToCmd(
df.Slinky.AppConfig.MetricsEnabled,
"Enable the oracle metrics reporting for Slinky.",
)
cmd.Flags().String(
FlagOraclePrometheusServerAddress,
df.Slinky.AppConfig.PrometheusServerAddress,
"The address of the exposed prometheus address for Slinky metrics.",
)
}

// GetDaemonFlagValuesFromOptions gets all daemon flag values from the `AppOptions` struct.
@@ -316,11 +310,6 @@ func GetDaemonFlagValuesFromOptions(
result.Slinky.AppConfig.MetricsEnabled = v
}
}
if option := appOpts.Get(FlagOraclePrometheusServerAddress); option != nil {
if v, err := cast.ToStringE(option); err == nil {
result.Slinky.AppConfig.PrometheusServerAddress = v
}
}

return result
}
8 changes: 4 additions & 4 deletions protocol/daemons/types/grpc_client.go
Original file line number Diff line number Diff line change
@@ -29,12 +29,12 @@ func (g *GrpcClientImpl) NewGrpcConnection(
ctx context.Context,
socketAddress string,
) (*grpc.ClientConn, error) {
return grpc.DialContext(
return grpc.DialContext( //nolint:staticcheck
ctx,
socketAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
// https://github.com/grpc/grpc-go/blob/master/dialoptions.go#L264
grpc.WithBlock(),
grpc.WithBlock(), //nolint:staticcheck
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
// Create a custom `net.Dialer` in order to specify `unix` as the desired network.
var dialer net.Dialer
@@ -48,11 +48,11 @@ func (g *GrpcClientImpl) NewTcpConnection(
ctx context.Context,
endpoint string,
) (*grpc.ClientConn, error) {
return grpc.DialContext(
return grpc.DialContext( //nolint:staticcheck
ctx,
endpoint,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithBlock(), //nolint:staticcheck
)
}

216 changes: 118 additions & 98 deletions protocol/go.mod

Large diffs are not rendered by default.

1,377 changes: 929 additions & 448 deletions protocol/go.sum

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion protocol/mocks/OracleClient.go
2 changes: 1 addition & 1 deletion protocol/testing/containertest/node.go
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ func (n *Node) createCometClient() (*comethttp.HTTP, error) {
}

func (n *Node) createGrpcConn() (*grpc.ClientConn, error) {
return grpc.Dial(n.grpcPort, grpc.WithTransportCredentials(insecure.NewCredentials()))
return grpc.Dial(n.grpcPort, grpc.WithTransportCredentials(insecure.NewCredentials())) //nolint:staticcheck
}

// Wait for current block height has advanced by at least `numBlocks`
15 changes: 12 additions & 3 deletions protocol/x/prices/keeper/slinky_adapter.go
Original file line number Diff line number Diff line change
@@ -87,9 +87,7 @@ func (k Keeper) GetPriceForCurrencyPair(ctx sdk.Context, cp slinkytypes.Currency
}, nil
}

// GetPrevBlockCPCounter returns the number of currency pairs (markets) in the previous block
// Currently we use the existing market number as an upper bound size markets cannot be deleted.
func (k Keeper) GetPrevBlockCPCounter(ctx sdk.Context) (uint64, error) {
func (k Keeper) GetNumCurrencyPairs(ctx sdk.Context) (uint64, error) {
marketPriceStore := k.getMarketPriceStore(ctx)

var numMarketPrices uint64
@@ -105,3 +103,14 @@ func (k Keeper) GetPrevBlockCPCounter(ctx sdk.Context) (uint64, error) {

return numMarketPrices, nil
}

// GetNumRemovedCurrencyPairs is currently a no-op since we don't support removing Markets right now.
func (k Keeper) GetNumRemovedCurrencyPairs(_ sdk.Context) (uint64, error) {
return 0, nil
}

// GetAllCurrencyPairs is not used with the DefaultCurrencyPair strategy.
// See https://github.com/skip-mev/slinky/blob/main/abci/strategies/currencypair/default.go
func (k Keeper) GetAllCurrencyPairs(ctx sdk.Context) []slinkytypes.CurrencyPair {
return nil
}
4 changes: 2 additions & 2 deletions protocol/x/prices/keeper/slinky_adapter_test.go
Original file line number Diff line number Diff line change
@@ -103,13 +103,13 @@ func TestBadMarketData(t *testing.T) {
require.Error(t, err)
}

func TestGetPrevBlockCPCounter(t *testing.T) {
func TestGetNumCurrencyPairs(t *testing.T) {
ctx, keeper, _, _, mockTimeProvider := keepertest.PricesKeepers(t)
mockTimeProvider.On("Now").Return(constants.TimeT)

marketNumber := 10
_ = keepertest.CreateNMarkets(t, ctx, keeper, marketNumber)
cpCounter, err := keeper.GetPrevBlockCPCounter(ctx)
cpCounter, err := keeper.GetNumCurrencyPairs(ctx)
require.NoError(t, err)
require.Equal(t, uint64(marketNumber), cpCounter)
}
1 change: 0 additions & 1 deletion protocol/x/prices/types/types.go
Original file line number Diff line number Diff line change
@@ -53,5 +53,4 @@ type PricesKeeper interface {
GetCurrencyPairFromID(ctx sdk.Context, id uint64) (cp slinkytypes.CurrencyPair, found bool)
GetIDForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (uint64, bool)
GetPriceForCurrencyPair(ctx sdk.Context, cp slinkytypes.CurrencyPair) (oracletypes.QuotePrice, error)
GetPrevBlockCPCounter(ctx sdk.Context) (uint64, error)
}

0 comments on commit f344d9d

Please sign in to comment.