diff --git a/proto/dydxprotocol/blocktime/params.proto b/proto/dydxprotocol/blocktime/params.proto index 72b63e3e68b..e97239a65b9 100644 --- a/proto/dydxprotocol/blocktime/params.proto +++ b/proto/dydxprotocol/blocktime/params.proto @@ -13,3 +13,13 @@ message DowntimeParams { repeated google.protobuf.Duration durations = 1 [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ]; } + +// SynchronyParams defines the parameters for block synchrony. +message SynchronyParams { + // next_block_delay replaces the locally configured timeout_commit in + // CometBFT. It determines the amount of time the CometBFT waits after the If + // the application sends next_block_delay = 0 to the consensus engine, the + // latter defaults back to using timeout_commit. + google.protobuf.Duration next_block_delay = 1 + [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ]; +} diff --git a/proto/dydxprotocol/blocktime/tx.proto b/proto/dydxprotocol/blocktime/tx.proto index 80779c1dcb8..ffd9be8edb5 100644 --- a/proto/dydxprotocol/blocktime/tx.proto +++ b/proto/dydxprotocol/blocktime/tx.proto @@ -13,6 +13,9 @@ service Msg { // UpdateDowntimeParams updates the DowntimeParams in state. rpc UpdateDowntimeParams(MsgUpdateDowntimeParams) returns (MsgUpdateDowntimeParamsResponse); + // UpdateSynchronyParams updates the SynchronyParams in state. + rpc UpdateSynchronyParams(MsgUpdateSynchronyParams) + returns (MsgUpdateSynchronyParamsResponse); } // MsgUpdateDowntimeParams is the Msg/UpdateDowntimeParams request type. @@ -28,3 +31,17 @@ message MsgUpdateDowntimeParams { // MsgUpdateDowntimeParamsResponse is the Msg/UpdateDowntimeParams response // type. message MsgUpdateDowntimeParamsResponse {} + +// MsgUpdateSynchronyParams is the Msg/UpdateSynchronyParams request type. +message MsgUpdateSynchronyParams { + // The address that controls the module. + option (cosmos.msg.v1.signer) = "authority"; + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + + // Defines the parameters to update. All parameters must be supplied. + SynchronyParams params = 2 [ (gogoproto.nullable) = false ]; +} + +// MsgUpdateSynchronyParamsResponse is the Msg/UpdateSynchronyParams response +// type. +message MsgUpdateSynchronyParamsResponse {} diff --git a/protocol/app/app.go b/protocol/app/app.go index 042bac91ea7..fe66efdaee9 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -1569,6 +1569,8 @@ func New( app.SetPrepareProposal(prepareProposalHandler) app.SetProcessProposal(processProposalHandler) + app.SetBlockDelayGetter(app.BlockTimeKeeper.GetBlockDelay) + // Note that panics from out of gas errors won't get logged, since the `OutOfGasMiddleware` is added in front of this, // so error will get handled by that middleware and subsequent middlewares won't get executed. // Also note that `AddRunTxRecoveryHandler` adds the handler in reverse order, meaning that handlers that appear diff --git a/protocol/app/msgs/all_msgs.go b/protocol/app/msgs/all_msgs.go index 9a6e072df02..357d9c02189 100644 --- a/protocol/app/msgs/all_msgs.go +++ b/protocol/app/msgs/all_msgs.go @@ -180,8 +180,10 @@ var ( "/dydxprotocol.accountplus.TxExtension": {}, // blocktime - "/dydxprotocol.blocktime.MsgUpdateDowntimeParams": {}, - "/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": {}, + "/dydxprotocol.blocktime.MsgUpdateDowntimeParams": {}, + "/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": {}, + "/dydxprotocol.blocktime.MsgUpdateSynchronyParams": {}, + "/dydxprotocol.blocktime.MsgUpdateSynchronyParamsResponse": {}, // bridge "/dydxprotocol.bridge.MsgAcknowledgeBridges": {}, diff --git a/protocol/app/msgs/internal_msgs.go b/protocol/app/msgs/internal_msgs.go index 8587ff5e4c7..44725202ba5 100644 --- a/protocol/app/msgs/internal_msgs.go +++ b/protocol/app/msgs/internal_msgs.go @@ -118,8 +118,10 @@ var ( "/dydxprotocol.accountplus.MsgSetActiveStateResponse": nil, // blocktime - "/dydxprotocol.blocktime.MsgUpdateDowntimeParams": &blocktime.MsgUpdateDowntimeParams{}, - "/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": nil, + "/dydxprotocol.blocktime.MsgUpdateDowntimeParams": &blocktime.MsgUpdateDowntimeParams{}, + "/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": nil, + "/dydxprotocol.blocktime.MsgUpdateSynchronyParams": &blocktime.MsgUpdateSynchronyParams{}, + "/dydxprotocol.blocktime.MsgUpdateSynchronyParamsResponse": nil, // bridge "/dydxprotocol.bridge.MsgCompleteBridge": &bridge.MsgCompleteBridge{}, diff --git a/protocol/go.mod b/protocol/go.mod index 5611346f400..33f4bf01172 100644 --- a/protocol/go.mod +++ b/protocol/go.mod @@ -468,9 +468,9 @@ replace ( // Use dYdX fork of Cosmos SDK/store cosmossdk.io/store => github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d // Use dYdX fork of CometBFT - github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.38.6-0.20241120221529-56316dc17261 + github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.38.6-0.20241120224121-fc0b273d1fbd // Use dYdX fork of Cosmos SDK - github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241120185835-38650041ec4d + github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241124185923-7b365908c58e github.com/cosmos/iavl => github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85 ) diff --git a/protocol/go.sum b/protocol/go.sum index 44b6c99da51..8c9848fbd7c 100644 --- a/protocol/go.sum +++ b/protocol/go.sum @@ -959,10 +959,10 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY= github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= -github.com/dydxprotocol/cometbft v0.38.6-0.20241120221529-56316dc17261 h1:uspjqDKBvC5I98gKBdZxqX3q0M2UOE/UlGgg+1CLNyI= -github.com/dydxprotocol/cometbft v0.38.6-0.20241120221529-56316dc17261/go.mod h1:XSQX1hQbr54qaJb4/5YNNZGXkAQHHa6bi/KMcN1SQ7w= -github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241120185835-38650041ec4d h1:6Qzg4IuX6LNdciU55jzpGuKxEVgD09rbU2cQaoJFo9Q= -github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241120185835-38650041ec4d/go.mod h1:8EZnLstapHjZ2iGa9nGIhctJ3gU1yCqmRUPN8WI7jD0= +github.com/dydxprotocol/cometbft v0.38.6-0.20241120224121-fc0b273d1fbd h1:3xEX8EOE7MsOAJXTx8m5zHPJyxjBtqMblC7Z4+QYhs4= +github.com/dydxprotocol/cometbft v0.38.6-0.20241120224121-fc0b273d1fbd/go.mod h1:XSQX1hQbr54qaJb4/5YNNZGXkAQHHa6bi/KMcN1SQ7w= +github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241124185923-7b365908c58e h1:MfvcPOS7hrp0BDVuhml6D1Aftbc23GWdgdSTVmuw/gI= +github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241124185923-7b365908c58e/go.mod h1:K1nHKSbBpLCmgNEv01sYWfvYN7DPUdx5rsrwIxUrqe0= github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d h1:HgLu1FD2oDFzlKW6/+SFXlH5Os8cwNTbplQIrQOWx8w= github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d/go.mod h1:zMcD3hfNwd0WMTpdRUhS3QxoCoEtBXWeoKsu3iaLBbQ= github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85 h1:5B/yGZyTBX/OZASQQMnk6Ms/TZja56MYd8OBaVc0Mho= diff --git a/protocol/lib/ante/internal_msg.go b/protocol/lib/ante/internal_msg.go index 3e1b44a917a..e9257555e3c 100644 --- a/protocol/lib/ante/internal_msg.go +++ b/protocol/lib/ante/internal_msg.go @@ -77,7 +77,7 @@ func IsInternalMsg(msg sdk.Msg) bool { // blocktime *blocktime.MsgUpdateDowntimeParams, - + *blocktime.MsgUpdateSynchronyParams, // bridge *bridge.MsgCompleteBridge, *bridge.MsgUpdateEventParams, diff --git a/protocol/x/blocktime/keeper/block_delay.go b/protocol/x/blocktime/keeper/block_delay.go new file mode 100644 index 00000000000..eb8f8d1a240 --- /dev/null +++ b/protocol/x/blocktime/keeper/block_delay.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "fmt" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" +) + +func (k Keeper) GetSynchronyParams(ctx sdk.Context) types.SynchronyParams { + store := ctx.KVStore(k.storeKey) + bytes := store.Get([]byte(types.SynchronyParamsKey)) + + if bytes == nil { + fmt.Printf("!! Returning default synchrony params\n") + return types.DefaultSynchronyParams() + } + + var params types.SynchronyParams + k.cdc.MustUnmarshal(bytes, ¶ms) + fmt.Printf("Returning un-nil synchrony params: %v\n", params) + return params +} + +func (k Keeper) SetSynchronyParams(ctx sdk.Context, params types.SynchronyParams) { + store := ctx.KVStore(k.storeKey) + store.Set([]byte(types.SynchronyParamsKey), k.cdc.MustMarshal(¶ms)) +} + +func (k Keeper) GetBlockDelay(ctx sdk.Context) time.Duration { + return k.GetSynchronyParams(ctx).NextBlockDelay +} diff --git a/protocol/x/blocktime/keeper/block_delay_test.go b/protocol/x/blocktime/keeper/block_delay_test.go new file mode 100644 index 00000000000..8fe89cb97aa --- /dev/null +++ b/protocol/x/blocktime/keeper/block_delay_test.go @@ -0,0 +1,49 @@ +package keeper_test + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/keeper" + "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" + "github.com/stretchr/testify/require" +) + +func Test_Set_GetSynchronyParams_GetBlockDelay(t *testing.T) { + tests := map[string]struct { + setUp func(keeper.Keeper, sdk.Context) + expectedSynchronyParams types.SynchronyParams + expectedBlockDelay time.Duration + }{ + "No set-up, empty synchrony params, block_delay = 0": { + setUp: func(k keeper.Keeper, ctx sdk.Context) { + }, + expectedSynchronyParams: types.DefaultSynchronyParams(), + expectedBlockDelay: 0, + }, + "Non-nil synchrony param": { + setUp: func(k keeper.Keeper, ctx sdk.Context) { + k.SetSynchronyParams(ctx, types.SynchronyParams{ + NextBlockDelay: 300 * time.Millisecond, + }) + }, + expectedSynchronyParams: types.SynchronyParams{ + NextBlockDelay: 300 * time.Millisecond, + }, + expectedBlockDelay: 300 * time.Millisecond, + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + tApp := testapp.NewTestAppBuilder(t).Build() + ctx := tApp.InitChain() + k := tApp.App.BlockTimeKeeper + tc.setUp(k, ctx) + require.Equal(t, tc.expectedSynchronyParams, k.GetSynchronyParams(ctx)) + require.Equal(t, tc.expectedBlockDelay, k.GetBlockDelay(ctx)) + }) + } +} diff --git a/protocol/x/blocktime/keeper/msg_server.go b/protocol/x/blocktime/keeper/msg_server.go index e4cac712c7b..397bfb7f4b9 100644 --- a/protocol/x/blocktime/keeper/msg_server.go +++ b/protocol/x/blocktime/keeper/msg_server.go @@ -41,3 +41,21 @@ func (k msgServer) UpdateDowntimeParams( return &types.MsgUpdateDowntimeParamsResponse{}, nil } + +func (k msgServer) UpdateSynchronyParams( + goCtx context.Context, + msg *types.MsgUpdateSynchronyParams, +) (*types.MsgUpdateSynchronyParamsResponse, error) { + if !k.HasAuthority(msg.Authority) { + return nil, errorsmod.Wrapf( + govtypes.ErrInvalidSigner, + "invalid authority %s", + msg.Authority, + ) + } + + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + k.SetSynchronyParams(ctx, msg.Params) + + return &types.MsgUpdateSynchronyParamsResponse{}, nil +} diff --git a/protocol/x/blocktime/types/errors.go b/protocol/x/blocktime/types/errors.go index 250e78305c5..d2756adb226 100644 --- a/protocol/x/blocktime/types/errors.go +++ b/protocol/x/blocktime/types/errors.go @@ -20,4 +20,9 @@ var ( 402, "Authority is invalid", ) + ErrNegativeNextBlockDealy = errorsmod.Register( + ModuleName, + 403, + "next_block_delay must be non-negative", + ) ) diff --git a/protocol/x/blocktime/types/keys.go b/protocol/x/blocktime/types/keys.go index 48344dc6b15..670a7689c2e 100644 --- a/protocol/x/blocktime/types/keys.go +++ b/protocol/x/blocktime/types/keys.go @@ -19,4 +19,7 @@ const ( // PreviousBlockInfoKey defines the key for PreviousBlockInfo PreviousBlockInfoKey = "PreviousBlockInfo" + + // SynchronyParamsKey defines the key for the SynchronyParams + SynchronyParamsKey = "SP:" ) diff --git a/protocol/x/blocktime/types/params.go b/protocol/x/blocktime/types/params.go index c86f29769d8..9bef62e0514 100644 --- a/protocol/x/blocktime/types/params.go +++ b/protocol/x/blocktime/types/params.go @@ -1,5 +1,7 @@ package types +import time "time" + func (m *DowntimeParams) Validate() error { if m.Durations != nil { for i := 0; i < len(m.Durations); i++ { @@ -16,3 +18,18 @@ func (m *DowntimeParams) Validate() error { } return nil } + +func (s SynchronyParams) Validate() error { + if s.NextBlockDelay < 0 { + return ErrNegativeNextBlockDealy + } + return nil +} + +func DefaultSynchronyParams() SynchronyParams { + return SynchronyParams{ + // CometBFT defaults back to `timeout_commit` if application sends over + // `NextBlockDelay` of 0. + NextBlockDelay: 0 * time.Second, + } +} diff --git a/protocol/x/blocktime/types/params.pb.go b/protocol/x/blocktime/types/params.pb.go index 1f55a12d30a..b31f1c4c833 100644 --- a/protocol/x/blocktime/types/params.pb.go +++ b/protocol/x/blocktime/types/params.pb.go @@ -74,8 +74,58 @@ func (m *DowntimeParams) GetDurations() []time.Duration { return nil } +// SynchronyParams defines the parameters for block synchrony. +type SynchronyParams struct { + // next_block_delay replaces the locally configured timeout_commit in + // CometBFT. It determines the amount of time the CometBFT waits after the If + // the application sends next_block_delay = 0 to the consensus engine, the + // latter defaults back to using timeout_commit. + NextBlockDelay time.Duration `protobuf:"bytes,1,opt,name=next_block_delay,json=nextBlockDelay,proto3,stdduration" json:"next_block_delay"` +} + +func (m *SynchronyParams) Reset() { *m = SynchronyParams{} } +func (m *SynchronyParams) String() string { return proto.CompactTextString(m) } +func (*SynchronyParams) ProtoMessage() {} +func (*SynchronyParams) Descriptor() ([]byte, []int) { + return fileDescriptor_d036653b2617e4cf, []int{1} +} +func (m *SynchronyParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SynchronyParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SynchronyParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SynchronyParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_SynchronyParams.Merge(m, src) +} +func (m *SynchronyParams) XXX_Size() int { + return m.Size() +} +func (m *SynchronyParams) XXX_DiscardUnknown() { + xxx_messageInfo_SynchronyParams.DiscardUnknown(m) +} + +var xxx_messageInfo_SynchronyParams proto.InternalMessageInfo + +func (m *SynchronyParams) GetNextBlockDelay() time.Duration { + if m != nil { + return m.NextBlockDelay + } + return 0 +} + func init() { proto.RegisterType((*DowntimeParams)(nil), "dydxprotocol.blocktime.DowntimeParams") + proto.RegisterType((*SynchronyParams)(nil), "dydxprotocol.blocktime.SynchronyParams") } func init() { @@ -83,7 +133,7 @@ func init() { } var fileDescriptor_d036653b2617e4cf = []byte{ - // 221 bytes of a gzipped FileDescriptorProto + // 268 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xa9, 0x4c, 0xa9, 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x2e, 0xc9, 0xcc, 0x4d, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x03, 0xcb, 0x08, 0x89, 0x21, 0x2b, @@ -92,12 +142,15 @@ var fileDescriptor_d036653b2617e4cf = []byte{ 0x69, 0x51, 0x62, 0x49, 0x66, 0x7e, 0x1e, 0x44, 0x5e, 0x29, 0x98, 0x8b, 0xcf, 0x25, 0xbf, 0x3c, 0x0f, 0x64, 0x42, 0x00, 0xd8, 0x16, 0x21, 0x47, 0x2e, 0x4e, 0x98, 0x9a, 0x62, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x49, 0x3d, 0x88, 0x29, 0x7a, 0x30, 0x53, 0xf4, 0x5c, 0xa0, 0x2a, 0x9c, - 0x38, 0x4e, 0xdc, 0x93, 0x67, 0x98, 0x71, 0x5f, 0x9e, 0x31, 0x08, 0xa1, 0xcb, 0x29, 0xf4, 0xc4, - 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, - 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xac, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, - 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x51, 0x3c, 0x5b, 0x66, 0xa2, 0x9b, 0x9c, 0x91, 0x98, 0x99, 0xa7, - 0x0f, 0x17, 0xa9, 0x40, 0x0a, 0x80, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x9c, 0x31, - 0x20, 0x00, 0x00, 0xff, 0xff, 0x1e, 0xa4, 0x26, 0x2b, 0x27, 0x01, 0x00, 0x00, + 0x38, 0x4e, 0xdc, 0x93, 0x67, 0x98, 0x71, 0x5f, 0x9e, 0x31, 0x08, 0xa1, 0x4b, 0x29, 0x81, 0x8b, + 0x3f, 0xb8, 0x32, 0x2f, 0x39, 0xa3, 0x28, 0x3f, 0xaf, 0x12, 0x6a, 0xaa, 0x2f, 0x97, 0x40, 0x5e, + 0x6a, 0x45, 0x49, 0x3c, 0xd8, 0xbd, 0xf1, 0x29, 0xa9, 0x39, 0x89, 0x95, 0x12, 0x8c, 0x0a, 0x8c, + 0xc4, 0x1a, 0xce, 0x07, 0xd2, 0xec, 0x04, 0xd2, 0xeb, 0x02, 0xd2, 0xea, 0x14, 0x7a, 0xe2, 0x91, + 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, + 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xd6, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, + 0xc9, 0xf9, 0xb9, 0xfa, 0x28, 0xc1, 0x59, 0x66, 0xa2, 0x9b, 0x9c, 0x91, 0x98, 0x99, 0xa7, 0x0f, + 0x17, 0xa9, 0x40, 0x0a, 0xe2, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x9c, 0x31, 0x20, + 0x00, 0x00, 0xff, 0xff, 0x09, 0x2a, 0x13, 0xab, 0x89, 0x01, 0x00, 0x00, } func (m *DowntimeParams) Marshal() (dAtA []byte, err error) { @@ -135,6 +188,37 @@ func (m *DowntimeParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *SynchronyParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SynchronyParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SynchronyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + n1, err1 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.NextBlockDelay, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.NextBlockDelay):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintParams(dAtA []byte, offset int, v uint64) int { offset -= sovParams(v) base := offset @@ -161,6 +245,17 @@ func (m *DowntimeParams) Size() (n int) { return n } +func (m *SynchronyParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.NextBlockDelay) + n += 1 + l + sovParams(uint64(l)) + return n +} + func sovParams(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -251,6 +346,89 @@ func (m *DowntimeParams) Unmarshal(dAtA []byte) error { } return nil } +func (m *SynchronyParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SynchronyParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SynchronyParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NextBlockDelay", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdDurationUnmarshal(&m.NextBlockDelay, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipParams(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/blocktime/types/tx.go b/protocol/x/blocktime/types/tx.go index 1dbe2dcc2f8..bd54c2bb4ee 100644 --- a/protocol/x/blocktime/types/tx.go +++ b/protocol/x/blocktime/types/tx.go @@ -20,3 +20,17 @@ func (msg *MsgUpdateDowntimeParams) ValidateBasic() error { } return msg.Params.Validate() } + +func (msg *MsgUpdateSynchronyParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap( + ErrInvalidAuthority, + fmt.Sprintf( + "authority '%s' must be a valid bech32 address, but got error '%v'", + msg.Authority, + err.Error(), + ), + ) + } + return msg.Params.Validate() +} diff --git a/protocol/x/blocktime/types/tx.pb.go b/protocol/x/blocktime/types/tx.pb.go index 5fd591ab262..017b9d18711 100644 --- a/protocol/x/blocktime/types/tx.pb.go +++ b/protocol/x/blocktime/types/tx.pb.go @@ -122,15 +122,109 @@ func (m *MsgUpdateDowntimeParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUpdateDowntimeParamsResponse proto.InternalMessageInfo +// MsgUpdateSynchronyParams is the Msg/UpdateSynchronyParams request type. +type MsgUpdateSynchronyParams struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // Defines the parameters to update. All parameters must be supplied. + Params SynchronyParams `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateSynchronyParams) Reset() { *m = MsgUpdateSynchronyParams{} } +func (m *MsgUpdateSynchronyParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateSynchronyParams) ProtoMessage() {} +func (*MsgUpdateSynchronyParams) Descriptor() ([]byte, []int) { + return fileDescriptor_4b4afda7c355c8b6, []int{2} +} +func (m *MsgUpdateSynchronyParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateSynchronyParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateSynchronyParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateSynchronyParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateSynchronyParams.Merge(m, src) +} +func (m *MsgUpdateSynchronyParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateSynchronyParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateSynchronyParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateSynchronyParams proto.InternalMessageInfo + +func (m *MsgUpdateSynchronyParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateSynchronyParams) GetParams() SynchronyParams { + if m != nil { + return m.Params + } + return SynchronyParams{} +} + +// MsgUpdateSynchronyParamsResponse is the Msg/UpdateSynchronyParams response +// type. +type MsgUpdateSynchronyParamsResponse struct { +} + +func (m *MsgUpdateSynchronyParamsResponse) Reset() { *m = MsgUpdateSynchronyParamsResponse{} } +func (m *MsgUpdateSynchronyParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateSynchronyParamsResponse) ProtoMessage() {} +func (*MsgUpdateSynchronyParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_4b4afda7c355c8b6, []int{3} +} +func (m *MsgUpdateSynchronyParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateSynchronyParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateSynchronyParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateSynchronyParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateSynchronyParamsResponse.Merge(m, src) +} +func (m *MsgUpdateSynchronyParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateSynchronyParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateSynchronyParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateSynchronyParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgUpdateDowntimeParams)(nil), "dydxprotocol.blocktime.MsgUpdateDowntimeParams") proto.RegisterType((*MsgUpdateDowntimeParamsResponse)(nil), "dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse") + proto.RegisterType((*MsgUpdateSynchronyParams)(nil), "dydxprotocol.blocktime.MsgUpdateSynchronyParams") + proto.RegisterType((*MsgUpdateSynchronyParamsResponse)(nil), "dydxprotocol.blocktime.MsgUpdateSynchronyParamsResponse") } func init() { proto.RegisterFile("dydxprotocol/blocktime/tx.proto", fileDescriptor_4b4afda7c355c8b6) } var fileDescriptor_4b4afda7c355c8b6 = []byte{ - // 326 bytes of a gzipped FileDescriptorProto + // 384 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xa9, 0x4c, 0xa9, 0x28, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x2e, 0xc9, 0xcc, 0x4d, 0xd5, 0x2f, 0xa9, 0xd0, 0x03, 0x8b, 0x0a, 0x89, 0x21, 0x2b, 0xd0, 0x83, 0x2b, 0x90, @@ -144,14 +238,17 @@ var fileDescriptor_4b4afda7c355c8b6 = []byte{ 0x79, 0xe9, 0x41, 0x08, 0xa5, 0x42, 0x2e, 0x5c, 0x6c, 0x10, 0x9b, 0x25, 0x98, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xd4, 0xf4, 0xb0, 0xfb, 0x55, 0x0f, 0xd5, 0x3e, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x7a, 0xad, 0xf8, 0x9a, 0x9e, 0x6f, 0xd0, 0x42, 0x98, 0xaa, 0xa4, 0xc8, 0x25, 0x8f, - 0xc3, 0xa1, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x46, 0x1d, 0x8c, 0x5c, 0xcc, 0xbe, - 0xc5, 0xe9, 0x42, 0x0d, 0x8c, 0x5c, 0x22, 0x58, 0x7d, 0xa4, 0x8f, 0xcb, 0x25, 0x38, 0x4c, 0x96, - 0x32, 0x27, 0x51, 0x03, 0xcc, 0x29, 0x4e, 0xa1, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, - 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, - 0xc7, 0x10, 0x65, 0x9d, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x8f, 0x12, - 0x6f, 0x65, 0x26, 0xba, 0xc9, 0x19, 0x89, 0x99, 0x79, 0xfa, 0x70, 0x91, 0x0a, 0xe4, 0x84, 0x53, - 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, 0x96, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x67, 0x88, - 0x2a, 0x78, 0x5f, 0x02, 0x00, 0x00, + 0xc3, 0xa1, 0x41, 0xa9, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x4a, 0x2b, 0x19, 0xb9, 0x24, 0xe0, + 0x6a, 0x82, 0x2b, 0xf3, 0x92, 0x33, 0x8a, 0xf2, 0xf3, 0x2a, 0x29, 0xf4, 0x8d, 0x2b, 0x9a, 0x6f, + 0xd4, 0x71, 0xf9, 0x06, 0xcd, 0x42, 0x02, 0xde, 0x51, 0xe2, 0x52, 0xc0, 0xe5, 0x54, 0x98, 0x7f, + 0x8c, 0xfa, 0x98, 0xb8, 0x98, 0x7d, 0x8b, 0xd3, 0x85, 0x1a, 0x18, 0xb9, 0x44, 0xb0, 0xc6, 0x90, + 0x3e, 0x2e, 0xb7, 0xe0, 0x08, 0x29, 0x29, 0x73, 0x12, 0x35, 0xc0, 0x9c, 0x22, 0xd4, 0xcc, 0xc8, + 0x25, 0x8a, 0x3d, 0x5c, 0x0d, 0x08, 0x1a, 0x89, 0xa6, 0x43, 0xca, 0x82, 0x54, 0x1d, 0x30, 0x57, + 0x38, 0x85, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, + 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x75, 0x7a, 0x66, + 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0x4a, 0x6e, 0x28, 0x33, 0xd1, 0x4d, 0xce, + 0x48, 0xcc, 0xcc, 0xd3, 0x87, 0x8b, 0x54, 0x20, 0x67, 0xc7, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, + 0xb0, 0x9c, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc2, 0x8d, 0xcd, 0xb5, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -168,6 +265,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // UpdateDowntimeParams updates the DowntimeParams in state. UpdateDowntimeParams(ctx context.Context, in *MsgUpdateDowntimeParams, opts ...grpc.CallOption) (*MsgUpdateDowntimeParamsResponse, error) + // UpdateSynchronyParams updates the SynchronyParams in state. + UpdateSynchronyParams(ctx context.Context, in *MsgUpdateSynchronyParams, opts ...grpc.CallOption) (*MsgUpdateSynchronyParamsResponse, error) } type msgClient struct { @@ -187,10 +286,21 @@ func (c *msgClient) UpdateDowntimeParams(ctx context.Context, in *MsgUpdateDownt return out, nil } +func (c *msgClient) UpdateSynchronyParams(ctx context.Context, in *MsgUpdateSynchronyParams, opts ...grpc.CallOption) (*MsgUpdateSynchronyParamsResponse, error) { + out := new(MsgUpdateSynchronyParamsResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.blocktime.Msg/UpdateSynchronyParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // UpdateDowntimeParams updates the DowntimeParams in state. UpdateDowntimeParams(context.Context, *MsgUpdateDowntimeParams) (*MsgUpdateDowntimeParamsResponse, error) + // UpdateSynchronyParams updates the SynchronyParams in state. + UpdateSynchronyParams(context.Context, *MsgUpdateSynchronyParams) (*MsgUpdateSynchronyParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -200,6 +310,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) UpdateDowntimeParams(ctx context.Context, req *MsgUpdateDowntimeParams) (*MsgUpdateDowntimeParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateDowntimeParams not implemented") } +func (*UnimplementedMsgServer) UpdateSynchronyParams(ctx context.Context, req *MsgUpdateSynchronyParams) (*MsgUpdateSynchronyParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateSynchronyParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -223,6 +336,24 @@ func _Msg_UpdateDowntimeParams_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Msg_UpdateSynchronyParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateSynchronyParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateSynchronyParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.blocktime.Msg/UpdateSynchronyParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateSynchronyParams(ctx, req.(*MsgUpdateSynchronyParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.blocktime.Msg", HandlerType: (*MsgServer)(nil), @@ -231,6 +362,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateDowntimeParams", Handler: _Msg_UpdateDowntimeParams_Handler, }, + { + MethodName: "UpdateSynchronyParams", + Handler: _Msg_UpdateSynchronyParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/blocktime/tx.proto", @@ -299,6 +434,69 @@ func (m *MsgUpdateDowntimeParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } +func (m *MsgUpdateSynchronyParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateSynchronyParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateSynchronyParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateSynchronyParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateSynchronyParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateSynchronyParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -334,6 +532,30 @@ func (m *MsgUpdateDowntimeParamsResponse) Size() (n int) { return n } +func (m *MsgUpdateSynchronyParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateSynchronyParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -505,6 +727,171 @@ func (m *MsgUpdateDowntimeParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateSynchronyParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateSynchronyParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateSynchronyParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateSynchronyParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateSynchronyParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateSynchronyParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/blocktime/types/tx_test.go b/protocol/x/blocktime/types/tx_test.go index c125b6f6f38..544c0f451f2 100644 --- a/protocol/x/blocktime/types/tx_test.go +++ b/protocol/x/blocktime/types/tx_test.go @@ -54,3 +54,50 @@ func TestMsgUpdateDowntimeParams_ValidateBasic(t *testing.T) { }) } } + +func TestMsgUpdateSynchronyParams_ValidateBasic(t *testing.T) { + tests := map[string]struct { + msg types.MsgUpdateSynchronyParams + expectedErr error + }{ + "Success - empty params": { + msg: types.MsgUpdateSynchronyParams{ + Authority: validAuthority, + Params: types.SynchronyParams{}, + }, + }, + "Success": { + msg: types.MsgUpdateSynchronyParams{ + Authority: validAuthority, + Params: types.SynchronyParams{ + NextBlockDelay: 300 * time.Millisecond, + }, + }, + }, + "Failure: Invalid authority": { + msg: types.MsgUpdateSynchronyParams{ + Authority: "", // invalid + }, + expectedErr: types.ErrInvalidAuthority, + }, + "Failure: Invalid params": { + msg: types.MsgUpdateSynchronyParams{ + Authority: validAuthority, + Params: types.SynchronyParams{ + NextBlockDelay: -1 * time.Second, + }, + }, + expectedErr: types.ErrNegativeNextBlockDealy, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expectedErr == nil { + require.NoError(t, err) + } else { + require.ErrorIs(t, err, tc.expectedErr) + } + }) + } +}