Skip to content

Commit

Permalink
Update docstrings, rename OracleClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime committed Mar 7, 2024
1 parent daad125 commit d53292c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
3 changes: 3 additions & 0 deletions protocol/app/vote_extensions/extend_vote_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions protocol/app/vote_extensions/oracle_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions protocol/app/vote_extensions/oracle_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand All @@ -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)

Expand All @@ -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{},
Expand All @@ -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()

Expand All @@ -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{
Expand Down

0 comments on commit d53292c

Please sign in to comment.