diff --git a/changelog.md b/changelog.md index 9e5495105a..e3fe346ead 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +* [3461](https://github.com/zeta-chain/node/pull/3461) - add new 'ConfirmationParams' field to chain params to enable multiple confirmation count values, deprecating `confirmation_count` + ### Tests * [3430](https://github.com/zeta-chain/node/pull/3430) - add simulation test for MsgWithDrawEmission diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index daf6430c45..3ad546151f 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -59767,6 +59767,7 @@ definitions: confirmation_count: type: string format: uint64 + title: 'Deprecated(v28): use confirmation_params instead' gas_price_ticker: type: string format: uint64 @@ -59799,6 +59800,9 @@ definitions: type: boolean gateway_address: type: string + confirmation_params: + $ref: '#/definitions/observerConfirmationParams' + title: Advanced confirmation parameters for chain to support fast observation observerChainParamsList: type: object properties: @@ -59807,6 +59811,33 @@ definitions: items: type: object $ref: '#/definitions/observerChainParams' + observerConfirmationParams: + type: object + properties: + safe_inbound_count: + type: string + format: uint64 + description: |- + This is the safe number of confirmations to wait before an inbound is + considered finalized. + fast_inbound_count: + type: string + format: uint64 + description: |- + This is the number of confirmations for fast inbound observation, which is + shorter than safe_inbound_count. + safe_outbound_count: + type: string + format: uint64 + description: |- + This is the safe number of confirmations to wait before an outbound is + considered finalized. + fast_outbound_count: + type: string + format: uint64 + description: |- + This is the number of confirmations for fast outbound observation, which is + shorter than safe_outbound_count. observerCrosschainFlags: type: object properties: diff --git a/proto/zetachain/zetacore/observer/confirmation_params.proto b/proto/zetachain/zetacore/observer/confirmation_params.proto new file mode 100644 index 0000000000..d55d6c0168 --- /dev/null +++ b/proto/zetachain/zetacore/observer/confirmation_params.proto @@ -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; +} diff --git a/proto/zetachain/zetacore/observer/params.proto b/proto/zetachain/zetacore/observer/params.proto index 0d9208ad4f..0db7a1253b 100644 --- a/proto/zetachain/zetacore/observer/params.proto +++ b/proto/zetachain/zetacore/observer/params.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package zetachain.zetacore.observer; import "gogoproto/gogo.proto"; -import "zetachain/zetacore/observer/observer.proto"; +import "zetachain/zetacore/observer/confirmation_params.proto"; option go_package = "github.com/zeta-chain/node/x/observer/types"; @@ -10,7 +10,8 @@ message ChainParamsList { repeated ChainParams chain_params = 1; } message ChainParams { int64 chain_id = 11; - uint64 confirmation_count = 1; + // Deprecated(v28): use confirmation_params instead + uint64 confirmation_count = 1 [ deprecated = true ]; uint64 gas_price_ticker = 2; uint64 inbound_ticker = 3; uint64 outbound_ticker = 4; @@ -30,6 +31,9 @@ message ChainParams { ]; bool is_supported = 16; string gateway_address = 17; + + // Advanced confirmation parameters for chain to support fast observation + ConfirmationParams confirmation_params = 18; } // Deprecated(v17) diff --git a/testutil/sample/observer.go b/testutil/sample/observer.go index 354aa53c96..bf29b93770 100644 --- a/testutil/sample/observer.go +++ b/testutil/sample/observer.go @@ -97,6 +97,8 @@ func ChainParams(chainID int64) *types.ChainParams { return nil } + confirmationParams := ConfirmationParams(r) + return &types.ChainParams{ ChainId: chainID, ConfirmationCount: r.Uint64(), @@ -113,6 +115,8 @@ func ChainParams(chainID int64) *types.ChainParams { BallotThreshold: fiftyPercent, MinObserverDelegation: sdkmath.LegacyNewDec(r.Int63()), IsSupported: false, + GatewayAddress: EthAddress().String(), + ConfirmationParams: &confirmationParams, } } @@ -337,3 +341,15 @@ func OperationalFlags() types.OperationalFlags { SignerBlockTimeOffset: ptr.Ptr(time.Second), } } + +func ConfirmationParams(r *rand.Rand) types.ConfirmationParams { + randInboundCount := Uint64InRangeFromRand(r, 1, 200) + randOutboundCount := Uint64InRangeFromRand(r, 1, 200) + + return types.ConfirmationParams{ + SafeInboundCount: randInboundCount, + FastInboundCount: Uint64InRange(1, randInboundCount), + SafeOutboundCount: randOutboundCount, + FastOutboundCount: Uint64InRange(1, randOutboundCount), + } +} diff --git a/typescript/zetachain/zetacore/observer/confirmation_params_pb.d.ts b/typescript/zetachain/zetacore/observer/confirmation_params_pb.d.ts new file mode 100644 index 0000000000..5704a472c5 --- /dev/null +++ b/typescript/zetachain/zetacore/observer/confirmation_params_pb.d.ts @@ -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 { + /** + * 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); + + static readonly runtime: typeof proto3; + static readonly typeName = "zetachain.zetacore.observer.ConfirmationParams"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): ConfirmationParams; + + static fromJson(jsonValue: JsonValue, options?: Partial): ConfirmationParams; + + static fromJsonString(jsonString: string, options?: Partial): ConfirmationParams; + + static equals(a: ConfirmationParams | PlainMessage | undefined, b: ConfirmationParams | PlainMessage | undefined): boolean; +} + diff --git a/typescript/zetachain/zetacore/observer/index.d.ts b/typescript/zetachain/zetacore/observer/index.d.ts index bdb0cde736..7e44abde93 100644 --- a/typescript/zetachain/zetacore/observer/index.d.ts +++ b/typescript/zetachain/zetacore/observer/index.d.ts @@ -1,6 +1,7 @@ export * from "./ballot_pb"; export * from "./blame_pb"; export * from "./chain_nonces_pb"; +export * from "./confirmation_params_pb"; export * from "./crosschain_flags_pb"; export * from "./events_pb"; export * from "./genesis_pb"; diff --git a/typescript/zetachain/zetacore/observer/params_pb.d.ts b/typescript/zetachain/zetacore/observer/params_pb.d.ts index 9155826e05..3309a91a5f 100644 --- a/typescript/zetachain/zetacore/observer/params_pb.d.ts +++ b/typescript/zetachain/zetacore/observer/params_pb.d.ts @@ -5,6 +5,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf"; import { Message, proto3 } from "@bufbuild/protobuf"; +import type { ConfirmationParams } from "./confirmation_params_pb.js"; /** * @generated from message zetachain.zetacore.observer.ChainParamsList @@ -40,7 +41,10 @@ export declare class ChainParams extends Message { chainId: bigint; /** - * @generated from field: uint64 confirmation_count = 1; + * Deprecated(v28): use confirmation_params instead + * + * @generated from field: uint64 confirmation_count = 1 [deprecated = true]; + * @deprecated */ confirmationCount: bigint; @@ -109,6 +113,13 @@ export declare class ChainParams extends Message { */ gatewayAddress: string; + /** + * Advanced confirmation parameters for chain to support fast observation + * + * @generated from field: zetachain.zetacore.observer.ConfirmationParams confirmation_params = 18; + */ + confirmationParams?: ConfirmationParams; + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; diff --git a/x/observer/keeper/migrator.go b/x/observer/keeper/migrator.go index c98ccd9e0c..93372f6f3e 100644 --- a/x/observer/keeper/migrator.go +++ b/x/observer/keeper/migrator.go @@ -3,6 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + v10 "github.com/zeta-chain/node/x/observer/migrations/v10" v8 "github.com/zeta-chain/node/x/observer/migrations/v8" v9 "github.com/zeta-chain/node/x/observer/migrations/v9" ) @@ -55,3 +56,8 @@ func (m Migrator) Migrate7to8(ctx sdk.Context) error { func (m Migrator) Migrate8to9(ctx sdk.Context) error { return v9.MigrateStore(ctx, m.observerKeeper) } + +// Migrate9to10 migrates the store from consensus version 9 to 10 +func (m Migrator) Migrate9to10(ctx sdk.Context) error { + return v10.MigrateStore(ctx, m.observerKeeper) +} diff --git a/x/observer/migrations/v10/migrate.go b/x/observer/migrations/v10/migrate.go new file mode 100644 index 0000000000..381f3b8f4c --- /dev/null +++ b/x/observer/migrations/v10/migrate.go @@ -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 +} diff --git a/x/observer/migrations/v10/migrate_test.go b/x/observer/migrations/v10/migrate_test.go new file mode 100644 index 0000000000..61b192122e --- /dev/null +++ b/x/observer/migrations/v10/migrate_test.go @@ -0,0 +1,123 @@ +package v10_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + keepertest "github.com/zeta-chain/node/testutil/keeper" + "github.com/zeta-chain/node/testutil/sample" + v10 "github.com/zeta-chain/node/x/observer/migrations/v10" + "github.com/zeta-chain/node/x/observer/types" +) + +func TestMigrateStore(t *testing.T) { + t.Run("can migrate confirmation count", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + + // set chain params + testChainParams := getTestChainParams() + k.SetChainParamsList(ctx, testChainParams) + + // ensure the chain params are set correctly + oldChainParams, found := k.GetChainParamsList(ctx) + require.True(t, found) + require.Equal(t, testChainParams, oldChainParams) + + // migrate the store + err := v10.MigrateStore(ctx, *k) + require.NoError(t, err) + + // ensure we still have same number of chain params after migration + newChainParams, found := k.GetChainParamsList(ctx) + require.True(t, found) + require.Len(t, newChainParams.ChainParams, len(oldChainParams.ChainParams)) + + // compare the old and new chain params + for i, newParam := range newChainParams.ChainParams { + oldParam := oldChainParams.ChainParams[i] + + // ensure the confirmation fields are set correctly + require.Equal(t, oldParam.ConfirmationCount, newParam.ConfirmationParams.SafeInboundCount) + require.Equal(t, oldParam.ConfirmationCount, newParam.ConfirmationParams.FastInboundCount) + require.Equal(t, oldParam.ConfirmationCount, newParam.ConfirmationParams.SafeOutboundCount) + require.Equal(t, oldParam.ConfirmationCount, newParam.ConfirmationParams.FastOutboundCount) + + // ensure nothing else has changed except the confirmation + oldParam.ConfirmationParams = &types.ConfirmationParams{ + SafeInboundCount: oldParam.ConfirmationCount, + FastInboundCount: oldParam.ConfirmationCount, + SafeOutboundCount: oldParam.ConfirmationCount, + FastOutboundCount: oldParam.ConfirmationCount, + } + require.Equal(t, newParam, oldParam) + } + }) + + t.Run("migrate nothing if chain params not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + + // ensure no chain params are set + allChainParams, found := k.GetChainParamsList(ctx) + require.False(t, found) + require.Empty(t, allChainParams.ChainParams) + + // migrate the store + err := v10.MigrateStore(ctx, *k) + require.ErrorIs(t, err, types.ErrChainParamsNotFound) + + // ensure nothing has changed + allChainParams, found = k.GetChainParamsList(ctx) + require.False(t, found) + require.Empty(t, allChainParams.ChainParams) + }) + + t.Run("migrate nothing if chain params list validation fails", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + + // get test chain params + testChainParams := getTestChainParams() + + // make the first chain params invalid + testChainParams.ChainParams[0].InboundTicker = 0 + + // set chain params + k.SetChainParamsList(ctx, testChainParams) + + // ensure the chain params are set correctly + oldChainParams, found := k.GetChainParamsList(ctx) + require.True(t, found) + require.Equal(t, testChainParams, oldChainParams) + + // migrate the store + err := v10.MigrateStore(ctx, *k) + require.ErrorIs(t, err, types.ErrInvalidChainParams) + + // ensure nothing has changed + newChainParams, found := k.GetChainParamsList(ctx) + require.True(t, found) + require.Equal(t, oldChainParams, newChainParams) + }) +} + +// makeChainParamsEmptyConfirmation creates a sample chain params with empty confirmation +func makeChainParamsEmptyConfirmation(chainID int64, confirmationCount uint64) *types.ChainParams { + chainParams := sample.ChainParams(chainID) + chainParams.ConfirmationCount = confirmationCount + chainParams.ConfirmationParams = nil + return chainParams +} + +// getTestChainParams returns a list of chain params for testing +func getTestChainParams() types.ChainParamsList { + return types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + makeChainParamsEmptyConfirmation(1, 14), + makeChainParamsEmptyConfirmation(56, 20), + makeChainParamsEmptyConfirmation(8332, 3), + makeChainParamsEmptyConfirmation(7000, 0), + makeChainParamsEmptyConfirmation(137, 200), + makeChainParamsEmptyConfirmation(8453, 90), + makeChainParamsEmptyConfirmation(900, 32), + }, + } +} diff --git a/x/observer/module.go b/x/observer/module.go index aa7db5cd42..ab49afd97f 100644 --- a/x/observer/module.go +++ b/x/observer/module.go @@ -152,6 +152,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 8, m.Migrate8to9); err != nil { panic(err) } + if err := cfg.RegisterMigration(types.ModuleName, 9, m.Migrate9to10); err != nil { + panic(err) + } } // RegisterInvariants registers the observer module's invariants. @@ -176,7 +179,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 9 } +func (AppModule) ConsensusVersion() uint64 { return 10 } // BeginBlock executes all ABCI BeginBlock logic respective to the observer module. func (am AppModule) BeginBlock(c context.Context) error { diff --git a/x/observer/types/chain_params.go b/x/observer/types/chain_params.go index a2a8e31942..67e6f8debf 100644 --- a/x/observer/types/chain_params.go +++ b/x/observer/types/chain_params.go @@ -52,13 +52,42 @@ func ValidateChainParams(params *ChainParams) error { return fmt.Errorf("chain params cannot be nil") } + // don't validate ZetaChain params, because the validation will fail on existing params in the store + // we might remove the ZetaChain params in the future, this is TBD if chains.IsZetaChain(params.ChainId, nil) { - return errorsmod.Wrap(sdkerrors.ErrInvalidChainID, "zeta chain cannot have observer chain parameters") + return nil } + // validate confirmation counts + // TODO: ensure 'ConfirmationCount === 0' in the chain params update msg after migration (no other values allowed) + // zetaclient will unconditionally use 'ConfirmationParams' fields in the future + // https://github.com/zeta-chain/node/issues/3466 if params.ConfirmationCount == 0 { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "ConfirmationCount must be greater than 0") } + if params.ConfirmationParams == nil { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "confirmation params cannot be nil") + } + if params.ConfirmationParams.SafeInboundCount == 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "SafeInboundCount must be greater than 0") + } + if params.ConfirmationParams.FastInboundCount > params.ConfirmationParams.SafeInboundCount { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "FastInboundCount must be less than or equal to SafeInboundCount", + ) + } + if params.ConfirmationParams.SafeOutboundCount == 0 { + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "SafeOutboundCount must be greater than 0") + } + if params.ConfirmationParams.FastOutboundCount > params.ConfirmationParams.SafeOutboundCount { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "FastOutboundCount must be less than or equal to SafeOutboundCount", + ) + } + + // validate tickers and intervals if params.GasPriceTicker <= 0 || params.GasPriceTicker > 300 { return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "GasPriceTicker %d out of range", params.GasPriceTicker) } @@ -168,6 +197,12 @@ func GetDefaultEthMainnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 14, + FastInboundCount: 14, + SafeOutboundCount: 14, + FastOutboundCount: 14, + }, } } func GetDefaultBscMainnetChainParams() *ChainParams { @@ -186,6 +221,12 @@ func GetDefaultBscMainnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 14, + FastInboundCount: 14, + SafeOutboundCount: 14, + FastOutboundCount: 14, + }, } } func GetDefaultBtcMainnetChainParams() *ChainParams { @@ -204,6 +245,12 @@ func GetDefaultBtcMainnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 2, + FastInboundCount: 2, + SafeOutboundCount: 2, + FastOutboundCount: 2, + }, } } func GetDefaultGoerliTestnetChainParams() *ChainParams { @@ -223,6 +270,12 @@ func GetDefaultGoerliTestnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 6, + FastInboundCount: 6, + SafeOutboundCount: 6, + FastOutboundCount: 6, + }, } } func GetDefaultBscTestnetChainParams() *ChainParams { @@ -241,6 +294,12 @@ func GetDefaultBscTestnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 6, + FastInboundCount: 6, + SafeOutboundCount: 6, + FastOutboundCount: 6, + }, } } func GetDefaultMumbaiTestnetChainParams() *ChainParams { @@ -259,6 +318,12 @@ func GetDefaultMumbaiTestnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 12, + FastInboundCount: 12, + SafeOutboundCount: 12, + FastOutboundCount: 12, + }, } } func GetDefaultBtcTestnetChainParams() *ChainParams { @@ -277,6 +342,12 @@ func GetDefaultBtcTestnetChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 2, + FastInboundCount: 2, + SafeOutboundCount: 2, + FastOutboundCount: 2, + }, } } func GetDefaultBtcRegtestChainParams() *ChainParams { @@ -295,6 +366,12 @@ func GetDefaultBtcRegtestChainParams() *ChainParams { BallotThreshold: DefaultBallotThreshold, MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 1, + FastInboundCount: 1, + SafeOutboundCount: 1, + FastOutboundCount: 1, + }, } } func GetDefaultGoerliLocalnetChainParams() *ChainParams { @@ -314,6 +391,12 @@ func GetDefaultGoerliLocalnetChainParams() *ChainParams { MinObserverDelegation: DefaultMinObserverDelegation, IsSupported: false, GatewayAddress: "0xF0deebCB0E9C829519C4baa794c5445171973826", + ConfirmationParams: &ConfirmationParams{ + SafeInboundCount: 1, + FastInboundCount: 1, + SafeOutboundCount: 1, + FastOutboundCount: 1, + }, } } func GetDefaultZetaPrivnetChainParams() *ChainParams { @@ -351,5 +434,6 @@ func ChainParamsEqual(params1, params2 ChainParams) bool { params1.BallotThreshold.Equal(params2.BallotThreshold) && params1.MinObserverDelegation.Equal(params2.MinObserverDelegation) && params1.IsSupported == params2.IsSupported && - params1.GatewayAddress == params2.GatewayAddress + params1.GatewayAddress == params2.GatewayAddress && + params1.ConfirmationParams == params2.ConfirmationParams } diff --git a/x/observer/types/chain_params_test.go b/x/observer/types/chain_params_test.go index 04cae4e99a..83b64b3b85 100644 --- a/x/observer/types/chain_params_test.go +++ b/x/observer/types/chain_params_test.go @@ -36,8 +36,9 @@ func TestChainParamsList_Validate(t *testing.T) { type UpdateChainParamsSuite struct { suite.Suite - evmParams *types.ChainParams - btcParams *types.ChainParams + zetaParams *types.ChainParams + evmParams *types.ChainParams + btcParams *types.ChainParams } var _ = Suite(&UpdateChainParamsSuite{}) @@ -53,6 +54,23 @@ func TestChainParamsEqual(t *testing.T) { } func (s *UpdateChainParamsSuite) SetupTest() { + s.zetaParams = &types.ChainParams{ + ConfirmationCount: 0, + GasPriceTicker: 0, + InboundTicker: 0, + OutboundTicker: 0, + WatchUtxoTicker: 0, + ZetaTokenContractAddress: "0x0000000000000000000000000000000000000000", + ConnectorContractAddress: "0x0000000000000000000000000000000000000000", + Erc20CustodyContractAddress: "0x0000000000000000000000000000000000000000", + ChainId: 7000, + OutboundScheduleInterval: 0, + OutboundScheduleLookahead: 0, + BallotThreshold: types.DefaultBallotThreshold, + MinObserverDelegation: types.DefaultMinObserverDelegation, + IsSupported: true, + GatewayAddress: "", + } s.evmParams = &types.ChainParams{ ConfirmationCount: 1, GasPriceTicker: 1, @@ -69,6 +87,12 @@ func (s *UpdateChainParamsSuite) SetupTest() { MinObserverDelegation: types.DefaultMinObserverDelegation, IsSupported: false, GatewayAddress: "0xF0deebCB0E9C829519C4baa794c5445171973826", + ConfirmationParams: &types.ConfirmationParams{ + SafeInboundCount: 2, + FastInboundCount: 0, // zero means fast observation is disabled + SafeOutboundCount: 2, + FastOutboundCount: 0, // zero means fast observation is disabled + }, } s.btcParams = &types.ChainParams{ ConfirmationCount: 1, @@ -85,11 +109,19 @@ func (s *UpdateChainParamsSuite) SetupTest() { BallotThreshold: types.DefaultBallotThreshold, MinObserverDelegation: types.DefaultMinObserverDelegation, IsSupported: false, + ConfirmationParams: &types.ConfirmationParams{ + SafeInboundCount: 2, + FastInboundCount: 1, + SafeOutboundCount: 2, + FastOutboundCount: 1, + }, } } func (s *UpdateChainParamsSuite) TestValidParams() { - err := types.ValidateChainParams(s.evmParams) + err := types.ValidateChainParams(s.zetaParams) + require.Nil(s.T(), err) + err = types.ValidateChainParams(s.evmParams) require.Nil(s.T(), err) err = types.ValidateChainParams(s.btcParams) require.Nil(s.T(), err) @@ -140,82 +172,126 @@ func (s *UpdateChainParamsSuite) TestCoreContractAddresses() { } func (s *UpdateChainParamsSuite) Validate(params *types.ChainParams) { - copy := *params + copy := copyParams(params) copy.ConfirmationCount = 0 - err := types.ValidateChainParams(©) + err := types.ValidateChainParams(copy) + require.NotNil(s.T(), err) + + copy = copyParams(params) + copy.ConfirmationParams = nil + err = types.ValidateChainParams(copy) + require.NotNil(s.T(), err) + + copy = copyParams(params) + copy.ConfirmationParams.SafeInboundCount = 0 + err = types.ValidateChainParams(copy) + require.NotNil(s.T(), err) + copy = copyParams(params) + copy.ConfirmationParams.FastInboundCount = copy.ConfirmationParams.SafeInboundCount + 1 + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) + copy.ConfirmationParams.SafeOutboundCount = 0 + err = types.ValidateChainParams(copy) + require.NotNil(s.T(), err) + copy = copyParams(params) + copy.ConfirmationParams.FastOutboundCount = copy.ConfirmationParams.SafeOutboundCount + 1 + err = types.ValidateChainParams(copy) + require.NotNil(s.T(), err) + + copy = copyParams(params) copy.GasPriceTicker = 0 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.GasPriceTicker = 300 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) copy.GasPriceTicker = 301 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) copy.InboundTicker = 0 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.InboundTicker = 300 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) copy.InboundTicker = 301 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) copy.OutboundTicker = 0 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.OutboundTicker = 300 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) copy.OutboundTicker = 301 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) copy.OutboundScheduleInterval = 0 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.OutboundScheduleInterval = 100 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) copy.OutboundScheduleInterval = 101 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) copy.OutboundScheduleLookahead = 0 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.OutboundScheduleLookahead = 500 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) copy.OutboundScheduleLookahead = 501 - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) - copy = *params + copy = copyParams(params) copy.BallotThreshold = sdkmath.LegacyDec{} - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.BallotThreshold = sdkmath.LegacyMustNewDecFromStr("1.2") - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.BallotThreshold = sdkmath.LegacyMustNewDecFromStr("0.9") - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) - copy = *params + copy = copyParams(params) copy.MinObserverDelegation = sdkmath.LegacyDec{} - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.NotNil(s.T(), err) copy.MinObserverDelegation = sdkmath.LegacyMustNewDecFromStr("0.9") - err = types.ValidateChainParams(©) + err = types.ValidateChainParams(copy) require.Nil(s.T(), err) } + +// copyParams creates a deep copy of the given ChainParams. +func copyParams(src *types.ChainParams) *types.ChainParams { + if src == nil { + return nil + } + + copy := *src + if src.ConfirmationParams == nil { + return © + } + + copy.ConfirmationParams = &types.ConfirmationParams{ + SafeInboundCount: src.ConfirmationParams.SafeInboundCount, + FastInboundCount: src.ConfirmationParams.FastInboundCount, + SafeOutboundCount: src.ConfirmationParams.SafeOutboundCount, + FastOutboundCount: src.ConfirmationParams.FastOutboundCount, + } + + return © +} diff --git a/x/observer/types/confirmation_params.pb.go b/x/observer/types/confirmation_params.pb.go new file mode 100644 index 0000000000..bd0306deab --- /dev/null +++ b/x/observer/types/confirmation_params.pb.go @@ -0,0 +1,419 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: zetachain/zetacore/observer/confirmation_params.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type ConfirmationParams struct { + // This is the safe number of confirmations to wait before an inbound is + // considered finalized. + SafeInboundCount uint64 `protobuf:"varint,1,opt,name=safe_inbound_count,json=safeInboundCount,proto3" json:"safe_inbound_count,omitempty"` + // This is the number of confirmations for fast inbound observation, which is + // shorter than safe_inbound_count. + FastInboundCount uint64 `protobuf:"varint,2,opt,name=fast_inbound_count,json=fastInboundCount,proto3" json:"fast_inbound_count,omitempty"` + // This is the safe number of confirmations to wait before an outbound is + // considered finalized. + SafeOutboundCount uint64 `protobuf:"varint,3,opt,name=safe_outbound_count,json=safeOutboundCount,proto3" json:"safe_outbound_count,omitempty"` + // This is the number of confirmations for fast outbound observation, which is + // shorter than safe_outbound_count. + FastOutboundCount uint64 `protobuf:"varint,4,opt,name=fast_outbound_count,json=fastOutboundCount,proto3" json:"fast_outbound_count,omitempty"` +} + +func (m *ConfirmationParams) Reset() { *m = ConfirmationParams{} } +func (m *ConfirmationParams) String() string { return proto.CompactTextString(m) } +func (*ConfirmationParams) ProtoMessage() {} +func (*ConfirmationParams) Descriptor() ([]byte, []int) { + return fileDescriptor_3d50fce477b3e8db, []int{0} +} +func (m *ConfirmationParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfirmationParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConfirmationParams.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 *ConfirmationParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfirmationParams.Merge(m, src) +} +func (m *ConfirmationParams) XXX_Size() int { + return m.Size() +} +func (m *ConfirmationParams) XXX_DiscardUnknown() { + xxx_messageInfo_ConfirmationParams.DiscardUnknown(m) +} + +var xxx_messageInfo_ConfirmationParams proto.InternalMessageInfo + +func (m *ConfirmationParams) GetSafeInboundCount() uint64 { + if m != nil { + return m.SafeInboundCount + } + return 0 +} + +func (m *ConfirmationParams) GetFastInboundCount() uint64 { + if m != nil { + return m.FastInboundCount + } + return 0 +} + +func (m *ConfirmationParams) GetSafeOutboundCount() uint64 { + if m != nil { + return m.SafeOutboundCount + } + return 0 +} + +func (m *ConfirmationParams) GetFastOutboundCount() uint64 { + if m != nil { + return m.FastOutboundCount + } + return 0 +} + +func init() { + proto.RegisterType((*ConfirmationParams)(nil), "zetachain.zetacore.observer.ConfirmationParams") +} + +func init() { + proto.RegisterFile("zetachain/zetacore/observer/confirmation_params.proto", fileDescriptor_3d50fce477b3e8db) +} + +var fileDescriptor_3d50fce477b3e8db = []byte{ + // 244 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x90, 0xbf, 0x4e, 0xc5, 0x20, + 0x14, 0x87, 0x8b, 0xde, 0x38, 0x74, 0xd2, 0xba, 0x98, 0x98, 0x10, 0xe3, 0x64, 0xa2, 0xc2, 0x60, + 0x7c, 0x01, 0x6f, 0x1c, 0x9c, 0x34, 0x8e, 0x2e, 0x0d, 0x70, 0xa9, 0x97, 0xa1, 0x9c, 0x06, 0x0e, + 0x46, 0x7d, 0x0a, 0x1f, 0xcb, 0xb1, 0xa3, 0xa3, 0x69, 0x5f, 0xc4, 0x00, 0xde, 0x7f, 0xdd, 0x08, + 0xdf, 0xf7, 0x9d, 0xe1, 0x57, 0xde, 0x7e, 0x6a, 0x14, 0x6a, 0x29, 0x8c, 0xe5, 0xe9, 0x05, 0x4e, + 0x73, 0x90, 0x5e, 0xbb, 0x37, 0xed, 0xb8, 0x02, 0xdb, 0x18, 0xd7, 0x0a, 0x34, 0x60, 0xeb, 0x4e, + 0x38, 0xd1, 0x7a, 0xd6, 0x39, 0x40, 0xa8, 0x4e, 0xd7, 0x19, 0x5b, 0x65, 0x6c, 0x95, 0x9d, 0xf7, + 0xa4, 0xac, 0xe6, 0x5b, 0xe9, 0x53, 0x2a, 0xab, 0xab, 0xb2, 0xf2, 0xa2, 0xd1, 0xb5, 0xb1, 0x12, + 0x82, 0x5d, 0xd4, 0x0a, 0x82, 0xc5, 0x13, 0x72, 0x46, 0x2e, 0x66, 0xcf, 0x87, 0x91, 0x3c, 0x64, + 0x30, 0x8f, 0xff, 0xd1, 0x6e, 0x84, 0xc7, 0x89, 0xbd, 0x97, 0xed, 0x48, 0x76, 0x6c, 0x56, 0x1e, + 0xa7, 0xdb, 0x10, 0x70, 0x5b, 0xdf, 0x4f, 0xfa, 0x51, 0x44, 0x8f, 0xff, 0x64, 0xed, 0xa7, 0xeb, + 0x13, 0x7f, 0x96, 0xfd, 0x88, 0x76, 0xfc, 0xbb, 0xfb, 0xef, 0x81, 0x92, 0x7e, 0xa0, 0xe4, 0x77, + 0xa0, 0xe4, 0x6b, 0xa4, 0x45, 0x3f, 0xd2, 0xe2, 0x67, 0xa4, 0xc5, 0xcb, 0xe5, 0xab, 0xc1, 0x65, + 0x90, 0x4c, 0x41, 0x9b, 0x16, 0xbc, 0xce, 0x63, 0x5a, 0x58, 0x68, 0xfe, 0xbe, 0x99, 0x12, 0x3f, + 0x3a, 0xed, 0xe5, 0x41, 0x5a, 0xef, 0xe6, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xa0, 0x5a, 0xf5, 0x7c, + 0x76, 0x01, 0x00, 0x00, +} + +func (m *ConfirmationParams) 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 *ConfirmationParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfirmationParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.FastOutboundCount != 0 { + i = encodeVarintConfirmationParams(dAtA, i, uint64(m.FastOutboundCount)) + i-- + dAtA[i] = 0x20 + } + if m.SafeOutboundCount != 0 { + i = encodeVarintConfirmationParams(dAtA, i, uint64(m.SafeOutboundCount)) + i-- + dAtA[i] = 0x18 + } + if m.FastInboundCount != 0 { + i = encodeVarintConfirmationParams(dAtA, i, uint64(m.FastInboundCount)) + i-- + dAtA[i] = 0x10 + } + if m.SafeInboundCount != 0 { + i = encodeVarintConfirmationParams(dAtA, i, uint64(m.SafeInboundCount)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintConfirmationParams(dAtA []byte, offset int, v uint64) int { + offset -= sovConfirmationParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ConfirmationParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SafeInboundCount != 0 { + n += 1 + sovConfirmationParams(uint64(m.SafeInboundCount)) + } + if m.FastInboundCount != 0 { + n += 1 + sovConfirmationParams(uint64(m.FastInboundCount)) + } + if m.SafeOutboundCount != 0 { + n += 1 + sovConfirmationParams(uint64(m.SafeOutboundCount)) + } + if m.FastOutboundCount != 0 { + n += 1 + sovConfirmationParams(uint64(m.FastOutboundCount)) + } + return n +} + +func sovConfirmationParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozConfirmationParams(x uint64) (n int) { + return sovConfirmationParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ConfirmationParams) 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 ErrIntOverflowConfirmationParams + } + 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: ConfirmationParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConfirmationParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SafeInboundCount", wireType) + } + m.SafeInboundCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SafeInboundCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FastInboundCount", wireType) + } + m.FastInboundCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FastInboundCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SafeOutboundCount", wireType) + } + m.SafeOutboundCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SafeOutboundCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FastOutboundCount", wireType) + } + m.FastOutboundCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FastOutboundCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipConfirmationParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConfirmationParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipConfirmationParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowConfirmationParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthConfirmationParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupConfirmationParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthConfirmationParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthConfirmationParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowConfirmationParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupConfirmationParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/observer/types/params.pb.go b/x/observer/types/params.pb.go index 803bdb97bf..03c02b0b73 100644 --- a/x/observer/types/params.pb.go +++ b/x/observer/types/params.pb.go @@ -69,8 +69,9 @@ func (m *ChainParamsList) GetChainParams() []*ChainParams { } type ChainParams struct { - ChainId int64 `protobuf:"varint,11,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - ConfirmationCount uint64 `protobuf:"varint,1,opt,name=confirmation_count,json=confirmationCount,proto3" json:"confirmation_count,omitempty"` + ChainId int64 `protobuf:"varint,11,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // Deprecated(v28): use confirmation_params instead + ConfirmationCount uint64 `protobuf:"varint,1,opt,name=confirmation_count,json=confirmationCount,proto3" json:"confirmation_count,omitempty"` // Deprecated: Do not use. GasPriceTicker uint64 `protobuf:"varint,2,opt,name=gas_price_ticker,json=gasPriceTicker,proto3" json:"gas_price_ticker,omitempty"` InboundTicker uint64 `protobuf:"varint,3,opt,name=inbound_ticker,json=inboundTicker,proto3" json:"inbound_ticker,omitempty"` OutboundTicker uint64 `protobuf:"varint,4,opt,name=outbound_ticker,json=outboundTicker,proto3" json:"outbound_ticker,omitempty"` @@ -84,6 +85,8 @@ type ChainParams struct { MinObserverDelegation cosmossdk_io_math.LegacyDec `protobuf:"bytes,15,opt,name=min_observer_delegation,json=minObserverDelegation,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_observer_delegation"` IsSupported bool `protobuf:"varint,16,opt,name=is_supported,json=isSupported,proto3" json:"is_supported,omitempty"` GatewayAddress string `protobuf:"bytes,17,opt,name=gateway_address,json=gatewayAddress,proto3" json:"gateway_address,omitempty"` + // Advanced confirmation parameters for chain to support fast observation + ConfirmationParams *ConfirmationParams `protobuf:"bytes,18,opt,name=confirmation_params,json=confirmationParams,proto3" json:"confirmation_params,omitempty"` } func (m *ChainParams) Reset() { *m = ChainParams{} } @@ -126,6 +129,7 @@ func (m *ChainParams) GetChainId() int64 { return 0 } +// Deprecated: Do not use. func (m *ChainParams) GetConfirmationCount() uint64 { if m != nil { return m.ConfirmationCount @@ -210,6 +214,13 @@ func (m *ChainParams) GetGatewayAddress() string { return "" } +func (m *ChainParams) GetConfirmationParams() *ConfirmationParams { + if m != nil { + return m.ConfirmationParams + } + return nil +} + // Deprecated(v17) type Params struct { // Deprecated(v17):Moved into the emissions module @@ -267,48 +278,49 @@ func init() { } var fileDescriptor_e7fa4666eddf88e5 = []byte{ - // 641 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xd1, 0x4e, 0xd4, 0x4e, - 0x14, 0xc6, 0xb7, 0xff, 0xe5, 0x8f, 0x30, 0x0b, 0xbb, 0xd0, 0xa0, 0x16, 0x36, 0x29, 0x2b, 0xc6, - 0xd8, 0x60, 0xe8, 0x1a, 0xf4, 0x52, 0x49, 0x64, 0xf1, 0x82, 0x88, 0x4a, 0x0a, 0xde, 0x68, 0xe2, - 0x64, 0x76, 0x3a, 0xb6, 0x93, 0x6d, 0x7b, 0x36, 0x33, 0x53, 0x60, 0x7d, 0x0a, 0x9f, 0xc6, 0x67, - 0xe0, 0x92, 0x4b, 0xe3, 0x05, 0x31, 0xf0, 0x22, 0xa6, 0xd3, 0xe9, 0x82, 0xac, 0x21, 0xde, 0xcd, - 0x9c, 0xef, 0xf7, 0x7d, 0x3b, 0x3b, 0x73, 0x7a, 0x90, 0xf7, 0x95, 0x29, 0x42, 0x63, 0xc2, 0xb3, - 0xae, 0x5e, 0x81, 0x60, 0x5d, 0xe8, 0x4b, 0x26, 0x8e, 0x98, 0xe8, 0x0e, 0x89, 0x20, 0xa9, 0xf4, - 0x87,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7, 0x53, 0x9e, 0xe1, 0xaa, - 0x71, 0x71, 0xc8, 0x12, 0x16, 0xe9, 0xae, 0x72, 0x5a, 0xff, 0x1e, 0x7b, 0x37, 0xe5, 0xd9, 0x7b, - 0x13, 0xb1, 0x33, 0x4e, 0xb0, 0x1f, 0xa0, 0x39, 0x2e, 0xb1, 0xcc, 0x87, 0x43, 0x10, 0x8a, 0x85, - 0xce, 0x42, 0xc7, 0xf2, 0x66, 0x82, 0x06, 0x97, 0x07, 0x55, 0xa9, 0x68, 0xb2, 0x88, 0x28, 0x76, - 0x4c, 0x46, 0xe3, 0x37, 0x58, 0xd4, 0x6f, 0xd0, 0x34, 0x65, 0x73, 0xed, 0x6b, 0x5b, 0x68, 0xda, - 0x7c, 0x32, 0xcf, 0xd1, 0x3d, 0x73, 0x05, 0x29, 0x51, 0xb9, 0xe0, 0x6a, 0x84, 0xfb, 0x09, 0xd0, - 0x81, 0xd4, 0x6d, 0x5c, 0x0f, 0x96, 0x4a, 0xf5, 0xad, 0x11, 0xb7, 0xb5, 0xb6, 0xfd, 0xfa, 0xf4, - 0xc2, 0xb5, 0xce, 0x2e, 0x5c, 0xeb, 0xd7, 0x85, 0x6b, 0x7d, 0xbb, 0x74, 0x6b, 0x67, 0x97, 0x6e, - 0xed, 0xc7, 0xa5, 0x5b, 0xfb, 0xf8, 0x24, 0xe2, 0x2a, 0xce, 0xfb, 0x3e, 0x85, 0x54, 0xcf, 0x87, - 0x8d, 0x72, 0x54, 0x64, 0x10, 0xb2, 0xee, 0xc9, 0xd5, 0xa0, 0x50, 0xa3, 0x21, 0x93, 0xfd, 0x69, - 0x3d, 0x26, 0x9e, 0xfd, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x11, 0xa1, 0x1e, 0xfe, 0xb1, 0x04, 0x00, - 0x00, + // 671 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xdd, 0x6e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 0xa7, 0xfb, 0xf2, 0x42, 0x77, 0xe9, 0xf6, 0xdc, 0x40, 0x53, 0xba, 0x31, 0x9f, + 0xa3, 0xdb, 0xfa, 0x90, 0x13, 0x2c, 0x33, 0xce, 0xe4, 0xd0, 0xef, 0xc5, 0x40, 0xfa, 0x42, 0x35, + 0x4a, 0xd5, 0x5b, 0x2a, 0xd4, 0x77, 0x5a, 0xec, 0x28, 0xad, 0xf3, 0xe6, 0xe8, 0xb4, 0x65, 0x1c, + 0x9f, 0xb6, 0x8c, 0x3f, 0xa7, 0x2d, 0xe3, 0xc7, 0x59, 0xab, 0x72, 0x7c, 0xd6, 0xaa, 0xfc, 0x3a, + 0x6b, 0x55, 0x3e, 0x3d, 0x0a, 0x99, 0x8c, 0xb2, 0x9e, 0x43, 0x20, 0x51, 0x03, 0xe9, 0x71, 0x31, + 0x9b, 0x52, 0x08, 0xa8, 0x7b, 0x78, 0x3e, 0x99, 0xe4, 0x70, 0x40, 0x45, 0x6f, 0x4a, 0x0d, 0xa3, + 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x2b, 0x18, 0x7c, 0x22, 0x05, 0x00, 0x00, } func (m *ChainParamsList) Marshal() (dAtA []byte, err error) { @@ -368,6 +380,20 @@ func (m *ChainParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ConfirmationParams != nil { + { + size, err := m.ConfirmationParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + } if len(m.GatewayAddress) > 0 { i -= len(m.GatewayAddress) copy(dAtA[i:], m.GatewayAddress) @@ -580,6 +606,10 @@ func (m *ChainParams) Size() (n int) { if l > 0 { n += 2 + l + sovParams(uint64(l)) } + if m.ConfirmationParams != nil { + l = m.ConfirmationParams.Size() + n += 2 + l + sovParams(uint64(l)) + } return n } @@ -1082,6 +1112,42 @@ func (m *ChainParams) Unmarshal(dAtA []byte) error { } m.GatewayAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 18: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConfirmationParams", 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 m.ConfirmationParams == nil { + m.ConfirmationParams = &ConfirmationParams{} + } + if err := m.ConfirmationParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/zetaclient/testutils/mocks/chain_params.go b/zetaclient/testutils/mocks/chain_params.go index 4458589ab8..f43df14f3f 100644 --- a/zetaclient/testutils/mocks/chain_params.go +++ b/zetaclient/testutils/mocks/chain_params.go @@ -45,6 +45,10 @@ func MockChainParams(chainID int64, confirmation uint64) observertypes.ChainPara MinObserverDelegation: observertypes.DefaultMinObserverDelegation, GatewayAddress: gwAddress, IsSupported: true, + ConfirmationParams: &observertypes.ConfirmationParams{ + SafeInboundCount: confirmation, + SafeOutboundCount: confirmation, + }, } }