From 5282ba0274e089bc882979a6ae8d5bdbb0b4531a Mon Sep 17 00:00:00 2001 From: jayy04 <103467857+jayy04@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:46:26 -0400 Subject: [PATCH] [CT-1237] enable messages and add ante decorator to the chain (#2375) --- protocol/app/ante.go | 17 +++++++++++++---- protocol/app/msgs/all_msgs.go | 10 ++++++++++ protocol/app/msgs/internal_msgs.go | 6 +++++- protocol/app/msgs/internal_msgs_test.go | 4 ++++ protocol/app/msgs/normal_msgs.go | 9 +++++++++ protocol/app/msgs/normal_msgs_test.go | 7 +++++++ protocol/lib/ante/internal_msg.go | 4 ++++ protocol/x/accountplus/ante/circuit_breaker.go | 12 ++++++------ .../x/accountplus/ante/circuit_breaker_test.go | 4 ++-- protocol/x/accountplus/module.go | 10 ++++++++-- protocol/x/accountplus/types/codec.go | 9 +++++++++ 11 files changed, 77 insertions(+), 15 deletions(-) diff --git a/protocol/app/ante.go b/protocol/app/ante.go index 63fc159b60..b00c48e157 100644 --- a/protocol/app/ante.go +++ b/protocol/app/ante.go @@ -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( @@ -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 diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 1276ccb7cc..d09a39cccd 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -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": {}, diff --git a/protocol/app/msgs/internal_msgs.go b/protocol/app/msgs/internal_msgs.go index 736ef64829..9c0e58f9f6 100644 --- a/protocol/app/msgs/internal_msgs.go +++ b/protocol/app/msgs/internal_msgs.go @@ -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" @@ -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, diff --git a/protocol/app/msgs/internal_msgs_test.go b/protocol/app/msgs/internal_msgs_test.go index 25485356a9..70e3549fe5 100644 --- a/protocol/app/msgs/internal_msgs_test.go +++ b/protocol/app/msgs/internal_msgs_test.go @@ -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", diff --git a/protocol/app/msgs/normal_msgs.go b/protocol/app/msgs/normal_msgs.go index a6a5bdb08d..2990258712 100644 --- a/protocol/app/msgs/normal_msgs.go +++ b/protocol/app/msgs/normal_msgs.go @@ -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" @@ -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, diff --git a/protocol/app/msgs/normal_msgs_test.go b/protocol/app/msgs/normal_msgs_test.go index e8f660357c..2ae0015db5 100644 --- a/protocol/app/msgs/normal_msgs_test.go +++ b/protocol/app/msgs/normal_msgs_test.go @@ -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", diff --git a/protocol/lib/ante/internal_msg.go b/protocol/lib/ante/internal_msg.go index 2fc5754712..4d578d4f10 100644 --- a/protocol/lib/ante/internal_msg.go +++ b/protocol/lib/ante/internal_msg.go @@ -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" @@ -71,6 +72,9 @@ func IsInternalMsg(msg sdk.Msg) bool { *upgrade.MsgSoftwareUpgrade, // ------- Custom modules + // accountplus + *accountplus.MsgSetActiveState, + // blocktime *blocktime.MsgUpdateDowntimeParams, diff --git a/protocol/x/accountplus/ante/circuit_breaker.go b/protocol/x/accountplus/ante/circuit_breaker.go index 549461847a..95eebb429a 100644 --- a/protocol/x/accountplus/ante/circuit_breaker.go +++ b/protocol/x/accountplus/ante/circuit_breaker.go @@ -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, @@ -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) } diff --git a/protocol/x/accountplus/ante/circuit_breaker_test.go b/protocol/x/accountplus/ante/circuit_breaker_test.go index 08ac7e7a81..b774154142 100644 --- a/protocol/x/accountplus/ante/circuit_breaker_test.go +++ b/protocol/x/accountplus/ante/circuit_breaker_test.go @@ -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) diff --git a/protocol/x/accountplus/module.go b/protocol/x/accountplus/module.go index f1e3b6a0ae..41032aef6b 100644 --- a/protocol/x/accountplus/module.go +++ b/protocol/x/accountplus/module.go @@ -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 @@ -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. diff --git a/protocol/x/accountplus/types/codec.go b/protocol/x/accountplus/types/codec.go index e3e58daf7d..cbaf4e039b 100644 --- a/protocol/x/accountplus/types/codec.go +++ b/protocol/x/accountplus/types/codec.go @@ -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 @@ -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 (