Skip to content

Commit

Permalink
[CT-1237] enable messages and add ante decorator to the chain (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 authored Sep 30, 2024
1 parent 6221a9e commit 19fd34d
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 15 deletions.
17 changes: 13 additions & 4 deletions protocol/app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,18 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
options.AccountKeeper,
*options.AccountplusKeeper,
),
sigVerification: customante.NewSigVerificationDecorator(
options.AccountKeeper,
options.SignModeHandler,
sigVerification: accountplusante.NewCircuitBreakerDecorator(
options.Codec,
accountplusante.NewAuthenticatorDecorator(
options.Codec,
options.AccountplusKeeper,
options.AccountKeeper,
options.SignModeHandler,
),
customante.NewSigVerificationDecorator(
options.AccountKeeper,
options.SignModeHandler,
),
),
consumeTxSizeGas: ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
deductFee: ante.NewDeductFeeDecorator(
Expand Down Expand Up @@ -163,7 +172,7 @@ type lockingAnteHandler struct {
validateSigCount ante.ValidateSigCountDecorator
incrementSequence ante.IncrementSequenceDecorator
replayProtection customante.ReplayProtectionDecorator
sigVerification customante.SigVerificationDecorator
sigVerification accountplusante.CircuitBreakerDecorator
consumeTxSizeGas ante.ConsumeTxSizeGasDecorator
deductFee ante.DeductFeeDecorator
setPubKey ante.SetPubKeyDecorator
Expand Down
10 changes: 10 additions & 0 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ var (
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelist": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelistResponse": {},

// accountplus
"/dydxprotocol.accountplus.MsgAddAuthenticator": {},
"/dydxprotocol.accountplus.MsgAddAuthenticatorResponse": {},
"/dydxprotocol.accountplus.MsgRemoveAuthenticator": {},
"/dydxprotocol.accountplus.MsgRemoveAuthenticatorResponse": {},
"/dydxprotocol.accountplus.MsgSetActiveState": {},
"/dydxprotocol.accountplus.MsgSetActiveStateResponse": {},
"/dydxprotocol.accountplus.TxExtension": {},

// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams": {},
"/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": {},
Expand Down
6 changes: 5 additions & 1 deletion protocol/app/msgs/internal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ibcconn "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/dydxprotocol/v4-chain/protocol/lib"
accountplus "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"
affiliates "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
blocktime "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types"
bridge "github.com/dydxprotocol/v4-chain/protocol/x/bridge/types"
Expand Down Expand Up @@ -106,13 +107,16 @@ var (

// Custom modules
InternalMsgSamplesDydxCustom = map[string]sdk.Msg{

// affiliates
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers": &affiliates.MsgUpdateAffiliateTiers{},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": nil,
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelist": &affiliates.MsgUpdateAffiliateWhitelist{},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelistResponse": nil,

// accountplus
"/dydxprotocol.accountplus.MsgSetActiveState": &accountplus.MsgSetActiveState{},
"/dydxprotocol.accountplus.MsgSetActiveStateResponse": nil,

// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams": &blocktime.MsgUpdateDowntimeParams{},
"/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": nil,
Expand Down
4 changes: 4 additions & 0 deletions protocol/app/msgs/internal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) {
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgradeResponse",

// accountplus
"/dydxprotocol.accountplus.MsgSetActiveState",
"/dydxprotocol.accountplus.MsgSetActiveStateResponse",

// affiliates
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers",
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse",
Expand Down
9 changes: 9 additions & 0 deletions protocol/app/msgs/normal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
ibcconn "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibccore "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/dydxprotocol/v4-chain/protocol/lib"
accountplus "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"
affiliates "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
clob "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
listing "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"
Expand Down Expand Up @@ -221,6 +222,14 @@ var (
// affiliates
"/dydxprotocol.affiliates.MsgRegisterAffiliate": &affiliates.MsgRegisterAffiliate{},
"/dydxprotocol.affiliates.MsgRegisterAffiliateResponse": nil,

// accountplus
"/dydxprotocol.accountplus.MsgAddAuthenticator": &accountplus.MsgAddAuthenticator{},
"/dydxprotocol.accountplus.MsgAddAuthenticatorResponse": nil,
"/dydxprotocol.accountplus.MsgRemoveAuthenticator": &accountplus.MsgRemoveAuthenticator{},
"/dydxprotocol.accountplus.MsgRemoveAuthenticatorResponse": nil,
"/dydxprotocol.accountplus.TxExtension": nil,

// clob
"/dydxprotocol.clob.MsgBatchCancel": &clob.MsgBatchCancel{},
"/dydxprotocol.clob.MsgBatchCancelResponse": nil,
Expand Down
7 changes: 7 additions & 0 deletions protocol/app/msgs/normal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func TestNormalMsgs_Key(t *testing.T) {
"/cosmos.upgrade.v1beta1.CancelSoftwareUpgradeProposal",
"/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",

// accountplus
"/dydxprotocol.accountplus.MsgAddAuthenticator",
"/dydxprotocol.accountplus.MsgAddAuthenticatorResponse",
"/dydxprotocol.accountplus.MsgRemoveAuthenticator",
"/dydxprotocol.accountplus.MsgRemoveAuthenticatorResponse",
"/dydxprotocol.accountplus.TxExtension",

// affiliates
"/dydxprotocol.affiliates.MsgRegisterAffiliate",
"/dydxprotocol.affiliates.MsgRegisterAffiliateResponse",
Expand Down
4 changes: 4 additions & 0 deletions protocol/lib/ante/internal_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ibcconn "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
accountplus "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types"
affiliates "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types"
blocktime "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types"
bridge "github.com/dydxprotocol/v4-chain/protocol/x/bridge/types"
Expand Down Expand Up @@ -71,6 +72,9 @@ func IsInternalMsg(msg sdk.Msg) bool {
*upgrade.MsgSoftwareUpgrade,

// ------- Custom modules
// accountplus
*accountplus.MsgSetActiveState,

// blocktime
*blocktime.MsgUpdateDowntimeParams,

Expand Down
12 changes: 6 additions & 6 deletions protocol/x/accountplus/ante/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
// the existence of `TxExtension`.
type CircuitBreakerDecorator struct {
cdc codec.BinaryCodec
authenticatorAnteHandlerFlow sdk.AnteHandler
originalAnteHandlerFlow sdk.AnteHandler
authenticatorAnteHandlerFlow sdk.AnteDecorator
originalAnteHandlerFlow sdk.AnteDecorator
}

// NewCircuitBreakerDecorator creates a new instance of CircuitBreakerDecorator with the provided parameters.
func NewCircuitBreakerDecorator(
cdc codec.BinaryCodec,
auth sdk.AnteHandler,
classic sdk.AnteHandler,
auth sdk.AnteDecorator,
classic sdk.AnteDecorator,
) CircuitBreakerDecorator {
return CircuitBreakerDecorator{
cdc: cdc,
Expand All @@ -44,9 +44,9 @@ func (ad CircuitBreakerDecorator) AnteHandle(
// Check that the authenticator flow is active
if specified, _ := lib.HasSelectedAuthenticatorTxExtensionSpecified(tx, ad.cdc); specified {
// Return and call the AnteHandle function on all the authenticator decorators.
return ad.authenticatorAnteHandlerFlow(ctx, tx, simulate)
return ad.authenticatorAnteHandlerFlow.AnteHandle(ctx, tx, simulate, next)
}

// Return and call the AnteHandle function on all the original decorators.
return ad.originalAnteHandlerFlow(ctx, tx, simulate)
return ad.originalAnteHandlerFlow.AnteHandle(ctx, tx, simulate, next)
}
4 changes: 2 additions & 2 deletions protocol/x/accountplus/ante/circuit_breaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (s *AuthenticatorCircuitBreakerAnteSuite) TestCircuitBreakerAnte() {
// Create a CircuitBreaker AnteDecorator
cbd := ante.NewCircuitBreakerDecorator(
s.tApp.App.AppCodec(),
sdk.ChainAnteDecorators(mockTestAuthenticator),
sdk.ChainAnteDecorators(mockTestClassic),
mockTestAuthenticator,
mockTestClassic,
)
anteHandler := sdk.ChainAnteDecorators(cbd)

Expand Down
10 changes: 8 additions & 2 deletions protocol/x/accountplus/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
panic(err)
}
}

// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users
// to generate new transactions containing messages defined in the module
Expand Down Expand Up @@ -121,7 +126,8 @@ func (am AppModule) IsOnePerModuleType() {}

// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries
func (am AppModule) RegisterServices(cfg module.Configurator) {
// accountplus does not have message and query
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
}

// InitGenesis performs the module's genesis initialization. It returns no validator updates.
Expand Down
9 changes: 9 additions & 0 deletions protocol/x/accountplus/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/types/tx"
)

// AuthenticatorTxOptions
Expand All @@ -13,6 +15,13 @@ type AuthenticatorTxOptions interface {
func RegisterCodec(cdc *codec.LegacyAmino) {}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*tx.TxExtensionOptionI)(nil), &TxExtension{})

registry.RegisterImplementations(
(*AuthenticatorTxOptions)(nil),
&TxExtension{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
Expand Down

0 comments on commit 19fd34d

Please sign in to comment.