Skip to content

Commit

Permalink
Squashed commit of the following: (#1135)
Browse files Browse the repository at this point in the history
commit e806d67
Author: Eric <eric.warehime@gmail.com>
Date:   Mon Mar 11 12:21:02 2024 -0700

    Run update-sample-pregenesis

commit ea01d17
Merge: 97b29d4 340801a
Author: Eric <eric.warehime@gmail.com>
Date:   Mon Mar 11 11:53:03 2024 -0700

    Merge remote-tracking branch 'upstream' into eric/proposal-logic

commit 97b29d4
Author: Nikhil <nikhil@skip.money>
Date:   Fri Mar 8 14:17:49 2024 -0500

    update Dockerfile

commit 3bbf627
Author: Nikhil Vasan <nikhil@skip.money>
Date:   Fri Mar 8 11:02:19 2024 -0800

    lint

commit 37720da
Author: Nikhil Vasan <nikhil@skip.money>
Date:   Fri Mar 8 10:50:24 2024 -0800

    remove non-deterministic validation logic

commit 0af5a49
Author: Eric <eric.warehime@gmail.com>
Date:   Thu Mar 7 16:48:50 2024 -0800

    Update constants w/ slinky values

commit 9cf8a67
Author: Eric <eric.warehime@gmail.com>
Date:   Wed Mar 6 20:41:22 2024 -0800

    Update docs

commit 7feaddb
Author: Eric <eric.warehime@gmail.com>
Date:   Sun Mar 3 21:28:32 2024 -0800

    Fix import order

commit 382d45c
Author: Eric <eric.warehime@gmail.com>
Date:   Sun Mar 3 21:24:41 2024 -0800

    Prepare and Process logic for Slinky
  • Loading branch information
Eric-Warehime authored Mar 14, 2024
1 parent c0cd790 commit dd41d0a
Show file tree
Hide file tree
Showing 24 changed files with 1,294 additions and 90 deletions.
8 changes: 6 additions & 2 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/app/flags"
"github.com/dydxprotocol/v4-chain/protocol/app/middleware"
"github.com/dydxprotocol/v4-chain/protocol/app/prepare"
"github.com/dydxprotocol/v4-chain/protocol/app/prepare/prices"
"github.com/dydxprotocol/v4-chain/protocol/app/process"

"github.com/dydxprotocol/v4-chain/protocol/lib"
Expand Down Expand Up @@ -1356,6 +1357,7 @@ func New(
app.SetPrepareCheckStater(app.PrepareCheckStater)

// PrepareProposal setup.
priceUpdateGenerator := prices.NewDefaultPriceUpdateGenerator(app.PricesKeeper)
if appFlags.NonValidatingFullNode {
app.SetPrepareProposal(prepare.FullNodePrepareProposalHandler())
} else {
Expand All @@ -1364,13 +1366,14 @@ func New(
txConfig,
app.BridgeKeeper,
app.ClobKeeper,
app.PricesKeeper,
app.PerpetualsKeeper,
priceUpdateGenerator,
),
)
}

// ProcessProposal setup.
priceUpdateDecoder := process.NewDefaultUpdateMarketPriceTxDecoder(app.PricesKeeper, app.txConfig.TxDecoder())
if appFlags.NonValidatingFullNode {
// Note: If the command-line flag `--non-validating-full-node` is enabled, this node will use
// an implementation of `ProcessProposal` which always returns `abci.ResponseProcessProposal_ACCEPT`.
Expand All @@ -1382,7 +1385,7 @@ func New(
app.ClobKeeper,
app.StakingKeeper,
app.PerpetualsKeeper,
app.PricesKeeper,
priceUpdateDecoder,
),
)
} else {
Expand All @@ -1394,6 +1397,7 @@ func New(
app.StakingKeeper,
app.PerpetualsKeeper,
app.PricesKeeper,
priceUpdateDecoder,
),
)
}
Expand Down
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: 0 additions & 6 deletions protocol/app/prepare/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
bridgetypes "github.com/dydxprotocol/v4-chain/protocol/x/bridge/types"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
perpstypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types"
)

// PrepareClobKeeper defines the expected CLOB keeper used for `PrepareProposal`.
Expand All @@ -20,11 +19,6 @@ type PreparePerpetualsKeeper interface {
GetAddPremiumVotes(ctx sdk.Context) *perpstypes.MsgAddPremiumVotes
}

// PreparePricesKeeper defines the expected Prices keeper used for `PrepareProposal`.
type PreparePricesKeeper interface {
GetValidMarketPriceUpdates(ctx sdk.Context) *pricestypes.MsgUpdateMarketPrices
}

// PrepareBridgeKeeper defines the expected Bridge keeper used for `PrepareProposal`.
type PrepareBridgeKeeper interface {
GetAcknowledgeBridges(ctx sdk.Context, blockTimestamp time.Time) *bridgetypes.MsgAcknowledgeBridges
Expand Down
39 changes: 25 additions & 14 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 @@ -10,7 +11,9 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"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"
)

var (
Expand Down Expand Up @@ -52,8 +55,8 @@ func PrepareProposalHandler(
txConfig client.TxConfig,
bridgeKeeper PrepareBridgeKeeper,
clobKeeper PrepareClobKeeper,
pricesKeeper PreparePricesKeeper,
perpetualKeeper PreparePerpetualsKeeper,
priceUpdateGenerator prices.PriceUpdateGenerator,
) sdk.PrepareProposalHandler {
return func(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
defer telemetry.ModuleMeasureSince(
Expand All @@ -71,8 +74,23 @@ func PrepareProposalHandler(
return &EmptyResponse, nil
}

// 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) >= constants.OracleVEInjectedTxs {
extCommitBzTx = req.Txs[constants.OracleInfoIndex]
}

// get the update market prices tx
msg, err := priceUpdateGenerator.GetValidMarketPriceUpdates(ctx, extCommitBzTx)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("GetValidMarketPriceUpdates error: %v", err))
recordErrorMetricsWithLabel(metrics.PricesTx)
return &EmptyResponse, nil
}

// Gather "FixedSize" group messages.
pricesTxResp, err := GetUpdateMarketPricesTx(ctx, txConfig, pricesKeeper)
pricesTxResp, err := EncodeMarketPriceUpdates(txConfig, msg)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("GetUpdateMarketPricesTx error: %v", err))
recordErrorMetricsWithLabel(metrics.PricesTx)
Expand Down Expand Up @@ -180,19 +198,12 @@ func PrepareProposalHandler(
}
}

// GetUpdateMarketPricesTx returns a tx containing `MsgUpdateMarketPrices`.
func GetUpdateMarketPricesTx(
ctx sdk.Context,
// EncodeMarketPriceUpdates returns a tx containing `MsgUpdateMarketPrices`.
func EncodeMarketPriceUpdates(
txConfig client.TxConfig,
pricesKeeper PreparePricesKeeper,
msg *pricetypes.MsgUpdateMarketPrices,
) (PricesTxResponse, error) {
// Get prices to update.
msgUpdateMarketPrices := pricesKeeper.GetValidMarketPriceUpdates(ctx)
if msgUpdateMarketPrices == nil {
return PricesTxResponse{}, fmt.Errorf("MsgUpdateMarketPrices cannot be nil")
}

tx, err := EncodeMsgsIntoTxBytes(txConfig, msgUpdateMarketPrices)
tx, err := EncodeMsgsIntoTxBytes(txConfig, msg)
if err != nil {
return PricesTxResponse{}, err
}
Expand All @@ -202,7 +213,7 @@ func GetUpdateMarketPricesTx(

return PricesTxResponse{
Tx: tx,
NumMarkets: len(msgUpdateMarketPrices.MarketPriceUpdates),
NumMarkets: len(msg.MarketPriceUpdates),
}, nil
}

Expand Down
Loading

0 comments on commit dd41d0a

Please sign in to comment.