Skip to content

Commit

Permalink
Squashed commit of the following:
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 committed Mar 12, 2024
1 parent 525bb6f commit 5ad38a3
Show file tree
Hide file tree
Showing 31 changed files with 1,702 additions and 317 deletions.
15 changes: 12 additions & 3 deletions protocol/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NB: This is a digest for a multi-arch manifest list, you will want to get this by running
# `docker buildx imagetools inspect golang:1.21-alpine`
ARG GOLANG_1_21_ALPINE_DIGEST="926f7f7e1ab8509b4e91d5ec6d5916ebb45155b0c8920291ba9f361d65385806"
ARG GOLANG_1_22_ALPINE_DIGEST="8e96e6cff6a388c2f70f5f662b64120941fcd7d4b89d62fec87520323a316bd9"

# This Dockerfile is a stateless build of the `dydxprotocold` binary as a Docker container.
# It does not include any configuration, state, or genesis information.
Expand All @@ -9,7 +9,7 @@ ARG GOLANG_1_21_ALPINE_DIGEST="926f7f7e1ab8509b4e91d5ec6d5916ebb45155b0c8920291b
# Builder
# --------------------------------------------------------

FROM golang@sha256:${GOLANG_1_21_ALPINE_DIGEST} as builder
FROM golang@sha256:${GOLANG_1_22_ALPINE_DIGEST} as builder
ARG VERSION
ARG COMMIT

Expand Down Expand Up @@ -41,15 +41,24 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
-o /dydxprotocol/build/ \
./...

# Build the oracle binary
WORKDIR /
RUN git clone https://github.com/skip-mev/slinky.git
WORKDIR /slinky
RUN make build

# --------------------------------------------------------
# Runner
# --------------------------------------------------------

FROM golang@sha256:${GOLANG_1_21_ALPINE_DIGEST}
FROM golang@sha256:${GOLANG_1_22_ALPINE_DIGEST}

RUN apk add --no-cache bash

COPY --from=builder /dydxprotocol/build/dydxprotocold /bin/dydxprotocold
COPY --from=builder /slinky/build/oracle /bin/slinky
COPY --from=builder /slinky/config/local/oracle.json /etc/oracle.json
COPY --from=builder /slinky/config/local/market.json /etc/market.json

ENV HOME /dydxprotocol
WORKDIR $HOME
Expand Down
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 @@ -1330,6 +1331,7 @@ func New(
app.SetPrepareCheckStater(app.PrepareCheckStater)

// PrepareProposal setup.
priceUpdateGenerator := prices.NewDefaultPriceUpdateGenerator(app.PricesKeeper)
if appFlags.NonValidatingFullNode {
app.SetPrepareProposal(prepare.FullNodePrepareProposalHandler())
} else {
Expand All @@ -1338,13 +1340,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 @@ -1356,7 +1359,7 @@ func New(
app.ClobKeeper,
app.StakingKeeper,
app.PerpetualsKeeper,
app.PricesKeeper,
priceUpdateDecoder,
),
)
} else {
Expand All @@ -1368,6 +1371,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 5ad38a3

Please sign in to comment.