Skip to content

Commit

Permalink
feat(blocktime): Use gov-controllednext_block_delay to replace `tim…
Browse files Browse the repository at this point in the history
…eout_commit` (#2609)
  • Loading branch information
teddyding authored Nov 29, 2024
1 parent 35ecc0a commit 369a0c1
Show file tree
Hide file tree
Showing 22 changed files with 1,015 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ export interface DowntimeParamsSDKType {
*/
durations: DurationSDKType[];
}
/** SynchronyParams defines the parameters for block synchrony. */

export interface SynchronyParams {
/**
* next_block_delay replaces the locally configured timeout_commit in
* CometBFT. It determines the amount of time the CometBFT waits after the
* `CommitTime` (subjective time when +2/3 precommits were received), before
* moving to next height.
* If the application sends next_block_delay = 0 to the consensus engine, the
* latter defaults back to using timeout_commit.
*/
nextBlockDelay?: Duration;
}
/** SynchronyParams defines the parameters for block synchrony. */

export interface SynchronyParamsSDKType {
/**
* next_block_delay replaces the locally configured timeout_commit in
* CometBFT. It determines the amount of time the CometBFT waits after the
* `CommitTime` (subjective time when +2/3 precommits were received), before
* moving to next height.
* If the application sends next_block_delay = 0 to the consensus engine, the
* latter defaults back to using timeout_commit.
*/
next_block_delay?: DurationSDKType;
}

function createBaseDowntimeParams(): DowntimeParams {
return {
Expand Down Expand Up @@ -63,4 +89,49 @@ export const DowntimeParams = {
return message;
}

};

function createBaseSynchronyParams(): SynchronyParams {
return {
nextBlockDelay: undefined
};
}

export const SynchronyParams = {
encode(message: SynchronyParams, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.nextBlockDelay !== undefined) {
Duration.encode(message.nextBlockDelay, writer.uint32(10).fork()).ldelim();
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): SynchronyParams {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseSynchronyParams();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.nextBlockDelay = Duration.decode(reader, reader.uint32());
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<SynchronyParams>): SynchronyParams {
const message = createBaseSynchronyParams();
message.nextBlockDelay = object.nextBlockDelay !== undefined && object.nextBlockDelay !== null ? Duration.fromPartial(object.nextBlockDelay) : undefined;
return message;
}

};
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { MsgUpdateDowntimeParams, MsgUpdateDowntimeParamsResponse } from "./tx";
import { MsgUpdateDowntimeParams, MsgUpdateDowntimeParamsResponse, MsgUpdateSynchronyParams, MsgUpdateSynchronyParamsResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
/** UpdateDowntimeParams updates the DowntimeParams in state. */
updateDowntimeParams(request: MsgUpdateDowntimeParams): Promise<MsgUpdateDowntimeParamsResponse>;
/** UpdateSynchronyParams updates the SynchronyParams in state. */

updateSynchronyParams(request: MsgUpdateSynchronyParams): Promise<MsgUpdateSynchronyParamsResponse>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: Rpc;

constructor(rpc: Rpc) {
this.rpc = rpc;
this.updateDowntimeParams = this.updateDowntimeParams.bind(this);
this.updateSynchronyParams = this.updateSynchronyParams.bind(this);
}

updateDowntimeParams(request: MsgUpdateDowntimeParams): Promise<MsgUpdateDowntimeParamsResponse> {
Expand All @@ -21,4 +25,10 @@ export class MsgClientImpl implements Msg {
return promise.then(data => MsgUpdateDowntimeParamsResponse.decode(new _m0.Reader(data)));
}

updateSynchronyParams(request: MsgUpdateSynchronyParams): Promise<MsgUpdateSynchronyParamsResponse> {
const data = MsgUpdateSynchronyParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.blocktime.Msg", "UpdateSynchronyParams", data);
return promise.then(data => MsgUpdateSynchronyParamsResponse.decode(new _m0.Reader(data)));
}

}
119 changes: 118 additions & 1 deletion indexer/packages/v4-protos/src/codegen/dydxprotocol/blocktime/tx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DowntimeParams, DowntimeParamsSDKType } from "./params";
import { DowntimeParams, DowntimeParamsSDKType, SynchronyParams, SynchronyParamsSDKType } from "./params";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** MsgUpdateDowntimeParams is the Msg/UpdateDowntimeParams request type. */
Expand Down Expand Up @@ -29,6 +29,34 @@ export interface MsgUpdateDowntimeParamsResponse {}
*/

export interface MsgUpdateDowntimeParamsResponseSDKType {}
/** MsgUpdateSynchronyParams is the Msg/UpdateSynchronyParams request type. */

export interface MsgUpdateSynchronyParams {
authority: string;
/** Defines the parameters to update. All parameters must be supplied. */

params?: SynchronyParams;
}
/** MsgUpdateSynchronyParams is the Msg/UpdateSynchronyParams request type. */

export interface MsgUpdateSynchronyParamsSDKType {
authority: string;
/** Defines the parameters to update. All parameters must be supplied. */

params?: SynchronyParamsSDKType;
}
/**
* MsgUpdateSynchronyParamsResponse is the Msg/UpdateSynchronyParams response
* type.
*/

export interface MsgUpdateSynchronyParamsResponse {}
/**
* MsgUpdateSynchronyParamsResponse is the Msg/UpdateSynchronyParams response
* type.
*/

export interface MsgUpdateSynchronyParamsResponseSDKType {}

function createBaseMsgUpdateDowntimeParams(): MsgUpdateDowntimeParams {
return {
Expand Down Expand Up @@ -117,4 +145,93 @@ export const MsgUpdateDowntimeParamsResponse = {
return message;
}

};

function createBaseMsgUpdateSynchronyParams(): MsgUpdateSynchronyParams {
return {
authority: "",
params: undefined
};
}

export const MsgUpdateSynchronyParams = {
encode(message: MsgUpdateSynchronyParams, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.authority !== "") {
writer.uint32(10).string(message.authority);
}

if (message.params !== undefined) {
SynchronyParams.encode(message.params, writer.uint32(18).fork()).ldelim();
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateSynchronyParams {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMsgUpdateSynchronyParams();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.authority = reader.string();
break;

case 2:
message.params = SynchronyParams.decode(reader, reader.uint32());
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<MsgUpdateSynchronyParams>): MsgUpdateSynchronyParams {
const message = createBaseMsgUpdateSynchronyParams();
message.authority = object.authority ?? "";
message.params = object.params !== undefined && object.params !== null ? SynchronyParams.fromPartial(object.params) : undefined;
return message;
}

};

function createBaseMsgUpdateSynchronyParamsResponse(): MsgUpdateSynchronyParamsResponse {
return {};
}

export const MsgUpdateSynchronyParamsResponse = {
encode(_: MsgUpdateSynchronyParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateSynchronyParamsResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseMsgUpdateSynchronyParamsResponse();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(_: DeepPartial<MsgUpdateSynchronyParamsResponse>): MsgUpdateSynchronyParamsResponse {
const message = createBaseMsgUpdateSynchronyParamsResponse();
return message;
}

};
12 changes: 12 additions & 0 deletions proto/dydxprotocol/blocktime/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ 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
// `CommitTime` (subjective time when +2/3 precommits were received), before
// moving to next height.
// 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 ];
}
17 changes: 17 additions & 0 deletions proto/dydxprotocol/blocktime/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {}
2 changes: 2 additions & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,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
Expand Down
6 changes: 4 additions & 2 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
6 changes: 4 additions & 2 deletions protocol/app/msgs/internal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/msgs/internal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) {
// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams",
"/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse",
"/dydxprotocol.blocktime.MsgUpdateSynchronyParams",
"/dydxprotocol.blocktime.MsgUpdateSynchronyParamsResponse",

// bridge
"/dydxprotocol.bridge.MsgCompleteBridge",
Expand Down
4 changes: 2 additions & 2 deletions protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,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.20241126215519-69cdde955fd0
// 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.20241127172510-4ee58434cdea
github.com/cosmos/iavl => github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85
)

Expand Down
8 changes: 4 additions & 4 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -958,10 +958,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.20241126215519-69cdde955fd0 h1:KBMuBNAE91SVeULnq2XBnmSDGeimI6aM1+YxlLb0yOI=
github.com/dydxprotocol/cometbft v0.38.6-0.20241126215519-69cdde955fd0/go.mod h1:XSQX1hQbr54qaJb4/5YNNZGXkAQHHa6bi/KMcN1SQ7w=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241127172510-4ee58434cdea h1:5jsj2e6zqnx7Q7SiNTYC7UGEW0ymgKFTbLxzp27/2Fg=
github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241127172510-4ee58434cdea/go.mod h1:z/5+LD4MJzLqbe+fBCWI2pZLnQbOlzSM82snAw2zceg=
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=
Expand Down
2 changes: 1 addition & 1 deletion protocol/lib/ante/internal_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func IsInternalMsg(msg sdk.Msg) bool {

// blocktime
*blocktime.MsgUpdateDowntimeParams,

*blocktime.MsgUpdateSynchronyParams,
// bridge
*bridge.MsgCompleteBridge,
*bridge.MsgUpdateEventParams,
Expand Down
Loading

0 comments on commit 369a0c1

Please sign in to comment.