Skip to content

Commit

Permalink
Update constants w/ slinky values
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime committed Mar 8, 2024
1 parent 9cf8a67 commit 0af5a49
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
9 changes: 9 additions & 0 deletions protocol/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ const (
AppDaemonName = AppName + "d"
ServiceName = "validator"
)

// Slinky Constants

const (
// OracleInfoIndex is the index at which slinky will inject VE data
OracleInfoIndex = 0
// OracleVEInjectedTxs is the number of transactions Slinky injects into the block (for VE data)
OracleVEInjectedTxs = 1
)
6 changes: 3 additions & 3 deletions protocol/app/prepare/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package prepare

import (
"fmt"
"github.com/dydxprotocol/v4-chain/protocol/app/constants"
"time"

abci "github.com/cometbft/cometbft/abci/types"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/app/prepare/prices"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"
pricetypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
slinkyabci "github.com/skip-mev/slinky/abci/types"
)

var (
Expand Down Expand Up @@ -77,8 +77,8 @@ func PrepareProposalHandler(
// Grab the injected VEs from the previous block.
// If VEs are not enabled, no tx will have been injected.
var extCommitBzTx []byte
if len(req.Txs) >= slinkyabci.NumInjectedTxs {
extCommitBzTx = req.Txs[slinkyabci.OracleInfoIndex]
if len(req.Txs) >= constants.OracleVEInjectedTxs {
extCommitBzTx = req.Txs[constants.OracleInfoIndex]
}

// get the update market prices tx
Expand Down
12 changes: 6 additions & 6 deletions protocol/app/process/slinky_market_price_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package process
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/constants"
"github.com/dydxprotocol/v4-chain/protocol/app/prepare/prices"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
slinkyabci "github.com/skip-mev/slinky/abci/types"
"github.com/skip-mev/slinky/abci/ve"
)

Expand Down Expand Up @@ -43,15 +43,15 @@ func (mpd *SlinkyMarketPriceDecoder) DecodeUpdateMarketPricesTx(
// check if vote-extensions are enabled
if ve.VoteExtensionsEnabled(ctx) {
// if there isn't a vote-extension in the block when there should be, fail
if len(txs) < slinkyabci.NumInjectedTxs {
if len(txs) < constants.OracleVEInjectedTxs {
return nil, getDecodingError(
msgUpdateMarketPricesType,
fmt.Errorf("expected %v txs, got %v", slinkyabci.NumInjectedTxs, len(txs)))
fmt.Errorf("expected %v txs, got %v", constants.OracleVEInjectedTxs))
}

// get the expected message from the injected vote-extensions
var err error
expectedMsg, err = mpd.agg.GetValidMarketPriceUpdates(ctx, txs[slinkyabci.OracleInfoIndex])
expectedMsg, err = mpd.agg.GetValidMarketPriceUpdates(ctx, txs[constants.OracleInfoIndex])
if err != nil {
return nil, getDecodingError(msgUpdateMarketPricesType, err)
}
Expand All @@ -78,11 +78,11 @@ func (mpd *SlinkyMarketPriceDecoder) DecodeUpdateMarketPricesTx(
}

// GetTxOffset returns the offset that other injected txs should be placed with respect to their normally
// expected indices. If vote-extensions are enabled, slinkyabci.NumInjectedTxs is the expected offset,
// expected indices. If vote-extensions are enabled, constants.OracleVEInjectedTxs is the expected offset,
// otherwise 0 is the expected offset.
func (mpd *SlinkyMarketPriceDecoder) GetTxOffset(ctx sdk.Context) int {
if ve.VoteExtensionsEnabled(ctx) {
return slinkyabci.NumInjectedTxs
return constants.OracleVEInjectedTxs
}
return 0
}
Expand Down
18 changes: 9 additions & 9 deletions protocol/app/process/slinky_market_price_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/constants"
"github.com/dydxprotocol/v4-chain/protocol/app/process"
"github.com/dydxprotocol/v4-chain/protocol/mocks"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
"github.com/skip-mev/slinky/abci/testutils"
slinkyabci "github.com/skip-mev/slinky/abci/types"
"github.com/stretchr/testify/suite"
)

Expand Down Expand Up @@ -112,7 +112,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestVoteExtensionsEnabled() {
err := fmt.Errorf("error")

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(nil, err)
suite.ctx, proposal[constants.OracleInfoIndex]).Return(nil, err)

decoder := process.NewSlinkyMarketPriceDecoder(suite.decoder, suite.gen)
tx, err := decoder.DecodeUpdateMarketPricesTx(suite.ctx, proposal)
Expand All @@ -130,7 +130,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestMarketPriceUpdateValidation_With
proposal := [][]byte{[]byte("test")}

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(&pricestypes.MsgUpdateMarketPrices{
suite.ctx, proposal[constants.OracleInfoIndex]).Return(&pricestypes.MsgUpdateMarketPrices{
MarketPriceUpdates: []*pricestypes.MsgUpdateMarketPrices_MarketPrice{
{
MarketId: 1,
Expand Down Expand Up @@ -165,7 +165,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestMarketPriceUpdateValidation_With
}

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(expectedMsg, nil)
suite.ctx, proposal[constants.OracleInfoIndex]).Return(expectedMsg, nil)

suite.decoder.On("DecodeUpdateMarketPricesTx",
suite.ctx, proposal).Return(
Expand Down Expand Up @@ -201,7 +201,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestMarketPriceUpdateValidation_With
}

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(expectedMsg, nil)
suite.ctx, proposal[constants.OracleInfoIndex]).Return(expectedMsg, nil)

suite.decoder.On("DecodeUpdateMarketPricesTx",
suite.ctx, proposal).Return(
Expand Down Expand Up @@ -241,7 +241,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestMarketPriceUpdateValidation_With
}

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(expectedMsg, nil)
suite.ctx, proposal[constants.OracleInfoIndex]).Return(expectedMsg, nil)

suite.decoder.On("DecodeUpdateMarketPricesTx",
suite.ctx, proposal).Return(process.NewUpdateMarketPricesTx(suite.ctx, nil, expectedMsg), nil)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestHappyPath_VoteExtensionsEnabled(
}

suite.gen.On("GetValidMarketPriceUpdates",
suite.ctx, proposal[slinkyabci.OracleInfoIndex]).Return(expectedMsg, nil)
suite.ctx, proposal[constants.OracleInfoIndex]).Return(expectedMsg, nil)

suite.decoder.On("DecodeUpdateMarketPricesTx",
suite.ctx, proposal).Return(
Expand Down Expand Up @@ -306,7 +306,7 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestGetTxOffset() {
suite.Equal(0, offset)
})

suite.Run("TxOffset is slinkyabci.NumInjectedTx if VE is enabled", func() {
suite.Run("TxOffset is constants.OracleVEInjectedTxs if VE is enabled", func() {
decoder := process.NewSlinkyMarketPriceDecoder(
process.NewDefaultUpdateMarketPriceTxDecoder(nil, nil), nil) // ignore deps

Expand All @@ -315,6 +315,6 @@ func (suite *SlinkyMarketPriceDecoderSuite) TestGetTxOffset() {
suite.ctx = suite.ctx.WithBlockHeight(5)

offset := decoder.GetTxOffset(suite.ctx)
suite.Equal(slinkyabci.NumInjectedTxs, offset)
suite.Equal(constants.OracleVEInjectedTxs, offset)
})
}

0 comments on commit 0af5a49

Please sign in to comment.