-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable multiple confirmation count values in chain params (#3461)
* add fine-grained confirmation to chain params; add migration script * add changelog entry * fix unit test * rename Confirmation as ConfirmationParams; remove 0 check on safe inbound, outbound count * leave ConfirmationParams as empty in mock chain params, we don't check 0 count any more * mark chain params ConfirmationCount as deprecated * make changelog entry explicit; add proto message comment; improve migrate script and unit test * validate all chain params during migration; return error if validation fails * make ConfirmationParams nullable to avoid upgrade test failure; adjust checks and tests accordingly
- Loading branch information
1 parent
5cda985
commit 304c4d7
Showing
17 changed files
with
1,059 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
proto/zetachain/zetacore/observer/confirmation_params.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
package zetachain.zetacore.observer; | ||
|
||
option go_package = "github.com/zeta-chain/node/x/observer/types"; | ||
|
||
message ConfirmationParams { | ||
// This is the safe number of confirmations to wait before an inbound is | ||
// considered finalized. | ||
uint64 safe_inbound_count = 1; | ||
|
||
// This is the number of confirmations for fast inbound observation, which is | ||
// shorter than safe_inbound_count. | ||
uint64 fast_inbound_count = 2; | ||
|
||
// This is the safe number of confirmations to wait before an outbound is | ||
// considered finalized. | ||
uint64 safe_outbound_count = 3; | ||
|
||
// This is the number of confirmations for fast outbound observation, which is | ||
// shorter than safe_outbound_count. | ||
uint64 fast_outbound_count = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
typescript/zetachain/zetacore/observer/confirmation_params_pb.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts" | ||
// @generated from file zetachain/zetacore/observer/confirmation_params.proto (package zetachain.zetacore.observer, syntax proto3) | ||
/* eslint-disable */ | ||
// @ts-nocheck | ||
|
||
import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; | ||
import { Message, proto3 } from "@bufbuild/protobuf"; | ||
|
||
/** | ||
* @generated from message zetachain.zetacore.observer.ConfirmationParams | ||
*/ | ||
export declare class ConfirmationParams extends Message<ConfirmationParams> { | ||
/** | ||
* This is the safe number of confirmations to wait before an inbound is | ||
* considered finalized. | ||
* | ||
* @generated from field: uint64 safe_inbound_count = 1; | ||
*/ | ||
safeInboundCount: bigint; | ||
|
||
/** | ||
* This is the number of confirmations for fast inbound observation, which is | ||
* shorter than safe_inbound_count. | ||
* | ||
* @generated from field: uint64 fast_inbound_count = 2; | ||
*/ | ||
fastInboundCount: bigint; | ||
|
||
/** | ||
* This is the safe number of confirmations to wait before an outbound is | ||
* considered finalized. | ||
* | ||
* @generated from field: uint64 safe_outbound_count = 3; | ||
*/ | ||
safeOutboundCount: bigint; | ||
|
||
/** | ||
* This is the number of confirmations for fast outbound observation, which is | ||
* shorter than safe_outbound_count. | ||
* | ||
* @generated from field: uint64 fast_outbound_count = 4; | ||
*/ | ||
fastOutboundCount: bigint; | ||
|
||
constructor(data?: PartialMessage<ConfirmationParams>); | ||
|
||
static readonly runtime: typeof proto3; | ||
static readonly typeName = "zetachain.zetacore.observer.ConfirmationParams"; | ||
static readonly fields: FieldList; | ||
|
||
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ConfirmationParams; | ||
|
||
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ConfirmationParams; | ||
|
||
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ConfirmationParams; | ||
|
||
static equals(a: ConfirmationParams | PlainMessage<ConfirmationParams> | undefined, b: ConfirmationParams | PlainMessage<ConfirmationParams> | undefined): boolean; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package v10 | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/zeta-chain/node/x/observer/types" | ||
) | ||
|
||
type observerKeeper interface { | ||
GetChainParamsList(ctx sdk.Context) (val types.ChainParamsList, found bool) | ||
SetChainParamsList(ctx sdk.Context, chainParams types.ChainParamsList) | ||
} | ||
|
||
// MigrateStore migrates the x/observer module state from the consensus version 9 to version 10. | ||
// The migration sets existing 'confirmation_count' as default value for newly added fields: | ||
// - 'safe_inbound_count' | ||
// - 'fast_inbound_count' | ||
// - 'safe_outbound_count' | ||
// - 'fast_outbound_count' | ||
func MigrateStore(ctx sdk.Context, observerKeeper observerKeeper) error { | ||
allChainParams, found := observerKeeper.GetChainParamsList(ctx) | ||
if !found { | ||
return errorsmod.Wrap(types.ErrChainParamsNotFound, "failed to get chain params") | ||
} | ||
|
||
// set new fields to the same value as 'confirmation_count' | ||
for _, chainParams := range allChainParams.ChainParams { | ||
if chainParams != nil { | ||
chainParams.ConfirmationParams = &types.ConfirmationParams{ | ||
SafeInboundCount: chainParams.ConfirmationCount, | ||
FastInboundCount: chainParams.ConfirmationCount, | ||
SafeOutboundCount: chainParams.ConfirmationCount, | ||
FastOutboundCount: chainParams.ConfirmationCount, | ||
} | ||
} | ||
} | ||
|
||
// validate the updated chain params list | ||
if err := allChainParams.Validate(); err != nil { | ||
return errorsmod.Wrap(types.ErrInvalidChainParams, err.Error()) | ||
} | ||
|
||
// set the updated chain params list | ||
observerKeeper.SetChainParamsList(ctx, allChainParams) | ||
|
||
return nil | ||
} |
Oops, something went wrong.