process

package
v0.0.0-...-cd4288d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const ConsensusRound = sdk.ContextKey("consensus_round")
View Source
const (
	ModuleName = "process_proposal"
)

Variables

View Source
var (
	// 1 - 99: Default.
	ErrDecodingTxBytes   = errorsmod.Register(ModuleName, 1, "Decoding tx bytes failed")
	ErrMsgValidateBasic  = errorsmod.Register(ModuleName, 2, "ValidateBasic failed on msg")
	ErrUnexpectedNumMsgs = errorsmod.Register(ModuleName, 3, "Unexpected num of msgs")
	ErrUnexpectedMsgType = errorsmod.Register(ModuleName, 4, "Unexpected msg type")
)

Functions

func FullNodeProcessProposalHandler

func FullNodeProcessProposalHandler(
	txConfig client.TxConfig,
	clobKeeper ProcessClobKeeper,
	perpetualKeeper ProcessPerpetualKeeper,
	pricesKeeper ProcessPricesKeeper,
) sdk.ProcessProposalHandler

FullNodeProcessProposalHandler is the `ProcessProposal` implementation for full-nodes. This implementation calculates and reports MEV metrics and always returns `abci.ResponseProcessProposal_ACCEPT`. Validators within the validator set should never use this implementation.

func IsDisallowClobOrderMsgInOtherTxs

func IsDisallowClobOrderMsgInOtherTxs(targetMsg sdk.Msg) bool

IsDisallowClobOrderMsgInOtherTxs returns true if the given msg type is not allowed to be in a proposed block as part of OtherTxs. Otherwise, returns false.

func ProcessProposalHandler

func ProcessProposalHandler(
	txConfig client.TxConfig,
	clobKeeper ProcessClobKeeper,
	perpetualKeeper ProcessPerpetualKeeper,
	pricesKeeper ProcessPricesKeeper,
) sdk.ProcessProposalHandler

ProcessProposalHandler is responsible for ensuring that the list of txs in the proposed block are valid. Specifically, this validates:

  • Tx bytes can be decoded to a valid tx.
  • Txs are ordered correctly.
  • Required "app-injected message" txs are included.
  • No duplicate "app-injected message" txs are present (i.e. no "app-injected msg" in "other" txs).
  • All messages are "valid" (i.e. `Msg.ValidateBasic` does not return errors).
  • All proposed prices within `MsgUpdateMarketPrices` are valid according to non-deterministic validation.

Note: `MsgUpdateMarketPrices` is an exception to only doing stateless validation. In order for this msg to be valid, the proposed price update values are compared against the local index price. Because the outcome depends on the local index price, this validation is dependent on "in-memory state"; therefore, this check is NOT stateless. Note: stakingKeeper and perpetualKeeper are only needed for MEV calculations.

Types

type AddPremiumVotesTx

type AddPremiumVotesTx struct {
	// contains filtered or unexported fields
}

AddPremiumVotesTx represents `MsgAddPremiumVotes` tx that can be validated.

func DecodeAddPremiumVotesTx

func DecodeAddPremiumVotesTx(decoder sdk.TxDecoder, txBytes []byte) (*AddPremiumVotesTx, error)

DecodeAddPremiumVotesTx returns a new `AddPremiumVotesTx` after validating the following:

  • decodes the given tx bytes
  • checks the num of msgs in the tx matches expectations
  • checks the msg is of expected type

If error occurs during any of the checks, returns error.

func (*AddPremiumVotesTx) GetMsg

func (afst *AddPremiumVotesTx) GetMsg() sdk.Msg

GetMsg returns the underlying `MsgAddPremiumVotes`.

func (*AddPremiumVotesTx) Validate

func (afst *AddPremiumVotesTx) Validate() error

Validate returns an error if the underlying msg fails `ValidateBasic`.

type MultiMsgsTx

type MultiMsgsTx interface {
	// Validate checks if the underlying msgs are valid or not.
	// Returns error if one of the msgs is invalid. Otherwise, returns nil.
	Validate() error

	// GetMsgs returns the underlying msgs in the tx.
	GetMsgs() []sdk.Msg
}

MultiMsgsTx represents a tx with multiple msgs.

type OtherMsgsTx

type OtherMsgsTx struct {
	// contains filtered or unexported fields
}

OtherMsgsTx represents tx msgs in the "other" category that can be validated.

func DecodeOtherMsgsTx

func DecodeOtherMsgsTx(decoder sdk.TxDecoder, txBytes []byte) (*OtherMsgsTx, error)

DecodeOtherMsgsTx returns a new `OtherMsgsTx` after validating the following:

  • decodes the given tx bytes
  • checks the num of msgs in the tx is not 0
  • checks the msgs do not contain "app-injected msgs" or "internal msgs" or "unsupported msgs"
  • checks the msgs do not contain "nested msgs" that fail `ValidateNestedMsg`
  • checks the msgs do not contain top-level msgs that are not allowed in OtherTxs

If error occurs during any of the checks, returns error.

func (*OtherMsgsTx) GetMsgs

func (omt *OtherMsgsTx) GetMsgs() []sdk.Msg

GetMsgs returns the underlying msgs in the tx.

func (*OtherMsgsTx) Validate

func (omt *OtherMsgsTx) Validate() error

Validate returns an error if one of the underlying msgs fails `ValidateBasic`.

type ProcessClobKeeper

type ProcessClobKeeper interface {
	RecordMevMetricsIsEnabled() bool
	RecordMevMetrics(
		ctx sdk.Context,
		stakingKeeper ProcessStakingKeeper,
		perpetualKeeper ProcessPerpetualKeeper,
		msgProposedOperations *types.MsgProposedOperations,
	)
}

ProcessClobKeeper defines the expected clob keeper used for `ProcessProposal`.

type ProcessPerpetualKeeper

type ProcessPerpetualKeeper interface {
	MaybeProcessNewFundingTickEpoch(ctx sdk.Context)
	GetSettlementPpm(
		ctx sdk.Context,
		perpetualId uint32,
		quantums *big.Int,
		index *big.Int,
	) (
		bigNetSettlementPpm *big.Int,
		newFundingIndex *big.Int,
		err error,
	)
	GetPerpetual(ctx sdk.Context, id uint32) (val perptypes.Perpetual, err error)
}

ProcessPerpetualKeeper defines the expected perpetual keeper used for `ProcessProposal`.

type ProcessPricesKeeper

type ProcessPricesKeeper interface {
	PerformStatefulPriceUpdateValidation(
		ctx sdk.Context,
		marketPriceUpdates *pricestypes.MsgUpdateMarketPrices,
		performNonDeterministicValidation bool,
	) error

	UpdateSmoothedPrices(
		ctx sdk.Context,
		linearInterpolateFunc func(v0 uint64, v1 uint64, ppm uint32) (uint64, error),
	) error
}

ProcessPricesKeeper defines the expected Prices keeper used for `ProcessProposal`.

type ProcessProposalTxs

type ProcessProposalTxs struct {
	// Single msg txs.
	ProposedOperationsTx *ProposedOperationsTx
	AddPremiumVotesTx    *AddPremiumVotesTx
	UpdateMarketPricesTx *UpdateMarketPricesTx

	// Multi msgs txs.
	OtherTxs []*OtherMsgsTx
}

ProcessProposalTxs is used as an intermediary struct to validate a proposed list of txs for `ProcessProposal`.

func DecodeProcessProposalTxs

func DecodeProcessProposalTxs(
	ctx sdk.Context,
	decoder sdk.TxDecoder,
	req *abci.RequestProcessProposal,
	pricesKeeper ProcessPricesKeeper,
) (*ProcessProposalTxs, error)

DecodeProcessProposalTxs returns a new `processProposalTxs`.

func (*ProcessProposalTxs) Validate

func (ppt *ProcessProposalTxs) Validate() error

Validate performs `ValidateBasic` on the underlying msgs that are part of the txs. Returns nil if all are valid. Otherwise, returns error.

Exception: for UpdateMarketPricesTx, we perform "in-memory stateful" validation to ensure that the new proposed prices are "valid" in comparison to index prices.

type ProcessStakingKeeper

type ProcessStakingKeeper interface {
	GetValidatorByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (validator stakingtypes.Validator, err error)
}

ProcessStakingKeeper defines the expected staking keeper used for `ProcessProposal`.

type ProposedOperationsTx

type ProposedOperationsTx struct {
	// contains filtered or unexported fields
}

ProposedOperationsTx represents `MsgProposedOperations` tx that can be validated.

func DecodeProposedOperationsTx

func DecodeProposedOperationsTx(decoder sdk.TxDecoder, txBytes []byte) (*ProposedOperationsTx, error)

DecodeProposedOperationsTx returns a new `ProposedOperationsTx` after validating the following:

  • decodes the given tx bytes
  • checks the num of msgs in the tx matches expectations
  • checks the msg is of expected type

If error occurs during any of the checks, returns error.

func (*ProposedOperationsTx) GetMsg

func (pmot *ProposedOperationsTx) GetMsg() sdk.Msg

GetMsg returns the underlying `MsgProposedOperations`.

func (*ProposedOperationsTx) Validate

func (pmot *ProposedOperationsTx) Validate() error

Validate returns an error if the underlying msg fails `ValidateBasic`.

type SingleMsgTx

type SingleMsgTx interface {
	// validate checks if the underlying msg is valid or not.
	// Returns error if invalid. Otherwise, returns nil.
	Validate() error

	// getMsg returns the underlying msg in the tx.
	GetMsg() sdk.Msg
}

SingleMsgTx represents a tx with a single msg.

type UpdateMarketPricesTx

type UpdateMarketPricesTx struct {
	// contains filtered or unexported fields
}

UpdateMarketPricesTx represents `MsgUpdateMarketPrices` tx that can be validated.

func DecodeUpdateMarketPricesTx

func DecodeUpdateMarketPricesTx(
	ctx sdk.Context,
	pricesKeeper ProcessPricesKeeper,
	decoder sdk.TxDecoder,
	txBytes []byte,
) (*UpdateMarketPricesTx, error)

DecodeAddPremiumVotesTx returns a new `UpdateMarketPricesTx` after validating the following:

  • decodes the given tx bytes
  • checks the num of msgs in the tx matches expectations
  • checks the msg is of expected type

If error occurs during any of the checks, returns error.

func (*UpdateMarketPricesTx) GetMsg

func (umpt *UpdateMarketPricesTx) GetMsg() sdk.Msg

GetMsg returns the underlying `MsgUpdateMarketPrices`.

func (*UpdateMarketPricesTx) Validate

func (umpt *UpdateMarketPricesTx) Validate() error

Validate returns an error if: - the underlying msg fails `ValidateBasic` - the underlying msg values are not "valid" according to the index price.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL