From d53292c78a6fe33f501377b3609c87b003fcdfcd Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 6 Mar 2024 20:16:01 -0800 Subject: [PATCH] Update docstrings, rename OracleClient --- .../vote_extensions/extend_vote_handler.go | 3 ++ protocol/app/vote_extensions/oracle_client.go | 31 ++++++++++--------- .../app/vote_extensions/oracle_client_test.go | 12 +++---- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/protocol/app/vote_extensions/extend_vote_handler.go b/protocol/app/vote_extensions/extend_vote_handler.go index 09105d3454..17c6af2417 100644 --- a/protocol/app/vote_extensions/extend_vote_handler.go +++ b/protocol/app/vote_extensions/extend_vote_handler.go @@ -25,6 +25,9 @@ type ExtendVoteHandler struct { // 3. Updating the market prices in the PricesKeeper so that the GetValidMarketPriceUpdates function returns the // latest available market prices // 4. Calling the Slinky ExtendVoteHandler to handle the rest of ExtendVote +// +// See https://github.com/skip-mev/slinky/blob/a5b1d3d3a2723e4746b5d588c512d7cc052dc0ff/abci/ve/vote_extension.go#L77 +// for the Slinky ExtendVoteHandler logic. func (e *ExtendVoteHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { return func(ctx sdk.Context, req *cometabci.RequestExtendVote) (resp *cometabci.ResponseExtendVote, err error) { // Decode the x/prices txn in the current block diff --git a/protocol/app/vote_extensions/oracle_client.go b/protocol/app/vote_extensions/oracle_client.go index cfe7b8ad15..07fc0e647f 100644 --- a/protocol/app/vote_extensions/oracle_client.go +++ b/protocol/app/vote_extensions/oracle_client.go @@ -11,43 +11,44 @@ import ( "google.golang.org/grpc" ) -// OracleClient is a wrapper around the default Slinky OracleClient interface. This object is responsible for requesting -// prices from the x/prices module (originally sent via the sidecar to the price-feed service), and -// injecting those prices into the vote-extension. -type OracleClient struct { +// OraclePrices is an implementation of the Slinky OracleClient interface. +// This object is responsible for requesting prices from the x/prices module, and injecting those prices into the +// vote-extension. +// The +type OraclePrices struct { PricesKeeper PricesKeeper } -// NewOracleClient returns a new OracleClient object. -func NewOracleClient(pricesKeeper PricesKeeper) *OracleClient { - return &OracleClient{ +// NewOraclePrices returns a new OracleClient object. +func NewOraclePrices(pricesKeeper PricesKeeper) *OraclePrices { + return &OraclePrices{ PricesKeeper: pricesKeeper, } } -// Start starts the OracleClient. -func (o *OracleClient) Start(_ context.Context) error { +// Start is a no-op. +func (o *OraclePrices) Start(_ context.Context) error { return nil } -// Stop stops the OracleClient. -func (o *OracleClient) Stop() error { +// Stop is a no-op. +func (o *OraclePrices) Stop() error { return nil } -// Prices is a wrapper around the Slinky OracleClient's Prices method. +// Prices is called in ExtendVoteHandler to determine which Prices are put into the extended commit. // This method is responsible for doing the following: // 1. Get the latest prices from the x/prices module's indexPriceCache via GetValidMarketPriceUpdates // 2. Translate the response from x/prices into a QueryPricesResponse, and return it. // // This method fails if: // - The passed in context is not an sdk.Context -func (o *OracleClient) Prices(ctx context.Context, +func (o *OraclePrices) Prices(ctx context.Context, _ *oracleservicetypes.QueryPricesRequest, - opts ...grpc.CallOption) (*oracleservicetypes.QueryPricesResponse, error) { + _ ...grpc.CallOption) (*oracleservicetypes.QueryPricesResponse, error) { sdkCtx, ok := ctx.(sdk.Context) if !ok { - return nil, fmt.Errorf("oracle client was passed on non-sdk context object") + return nil, fmt.Errorf("OraclePrices was passed on non-sdk context object") } // get the final prices to include in the vote-extension from the x/prices module diff --git a/protocol/app/vote_extensions/oracle_client_test.go b/protocol/app/vote_extensions/oracle_client_test.go index 3c0b63ec25..0bf1a3ed4f 100644 --- a/protocol/app/vote_extensions/oracle_client_test.go +++ b/protocol/app/vote_extensions/oracle_client_test.go @@ -15,7 +15,7 @@ import ( ) func TestStartStopNoop(t *testing.T) { - cli := NewOracleClient(nil) + cli := NewOraclePrices(nil) err := cli.Start(context.TODO()) require.NoError(t, err) @@ -25,7 +25,7 @@ func TestStartStopNoop(t *testing.T) { func TestValidPriceResponse(t *testing.T) { pk := mocks.NewPricesKeeper(t) - cli := NewOracleClient(pk) + cli := NewOraclePrices(pk) pk.On("GetValidMarketPriceUpdates", mock.Anything). Return(&types.MsgUpdateMarketPrices{ MarketPriceUpdates: []*types.MsgUpdateMarketPrices_MarketPrice{ @@ -46,7 +46,7 @@ func TestValidPriceResponse(t *testing.T) { func TestNonSdkContextFails(t *testing.T) { pk := mocks.NewPricesKeeper(t) - cli := NewOracleClient(pk) + cli := NewOraclePrices(pk) _, err := cli.Prices(context.TODO(), nil) @@ -55,7 +55,7 @@ func TestNonSdkContextFails(t *testing.T) { func TestEmptyUpdatesPasses(t *testing.T) { pk := mocks.NewPricesKeeper(t) - cli := NewOracleClient(pk) + cli := NewOraclePrices(pk) pk.On("GetValidMarketPriceUpdates", mock.Anything). Return(&types.MsgUpdateMarketPrices{ MarketPriceUpdates: []*types.MsgUpdateMarketPrices_MarketPrice{}, @@ -69,7 +69,7 @@ func TestEmptyUpdatesPasses(t *testing.T) { func TestNilUpdatesPasses(t *testing.T) { pk := mocks.NewPricesKeeper(t) - cli := NewOracleClient(pk) + cli := NewOraclePrices(pk) pk.On("GetValidMarketPriceUpdates", mock.Anything). Return(nil).Once() @@ -81,7 +81,7 @@ func TestNilUpdatesPasses(t *testing.T) { func TestPairNotFoundNoOps(t *testing.T) { pk := mocks.NewPricesKeeper(t) - cli := NewOracleClient(pk) + cli := NewOraclePrices(pk) pk.On("GetValidMarketPriceUpdates", mock.Anything). Return(&types.MsgUpdateMarketPrices{ MarketPriceUpdates: []*types.MsgUpdateMarketPrices_MarketPrice{