From 544684b6ba7156ff5535c7e6a1bcff4dd0bfe3ed Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Thu, 25 Apr 2024 09:23:37 -0400 Subject: [PATCH 1/6] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5b7bba1b..cb5f4bf0be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930). * Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930). * Use fields of the SimulationState for the encoders needed for simulations [#1931](https://github.com/provenance-io/provenance/pull/1931). +* Update statesync for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760). ### Dependencies From 9b9004f73a1440afbbcb15ffbed6eb3c80d470d9 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Thu, 25 Apr 2024 10:53:50 -0400 Subject: [PATCH 2/6] First attempt at state-sync. --- internal/statesync/statesync.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/internal/statesync/statesync.go b/internal/statesync/statesync.go index 08b02fc923..d485922823 100644 --- a/internal/statesync/statesync.go +++ b/internal/statesync/statesync.go @@ -1,28 +1,31 @@ package statesync import ( - // cmtrpccore "github.com/cometbft/cometbft/rpc/core" // TODO[1760]: sync-info - // cmtrpc "github.com/cometbft/cometbft/rpc/jsonrpc/server" // TODO[1760]: sync-info + cmtrpccore "github.com/cometbft/cometbft/rpc/core" // TODO[1760]: sync-info + server "github.com/cometbft/cometbft/rpc/jsonrpc/server" // TODO[1760]: sync-info cmtrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" "github.com/cosmos/cosmos-sdk/version" ) -func RegisterSyncStatus() { - // TODO[1760]: sync-info: Figure out how to still set a custom route. - // cmtrpccore.Routes["sync_info"] = cmtrpc.NewRPCFunc(GetSyncInfoAtBlock, "height") +func RegisterSyncStatus(env cmtrpccore.Environment) { + routes := env.GetRoutes() + routes["sync_info"] = server.NewRPCFunc(GetSyncInfoAtBlock, "height") } func GetSyncInfoAtBlock(ctx *cmtrpctypes.Context, height *int64) (*GetSyncInfo, error) { // TODO[1760]: sync-info: Figure out the new way to get the current block. - // block, err := cmtrpccore.Block(ctx, height) - // if err != nil { - // return nil, err - // } + // How do we get env? + var env cmtrpccore.Environment + + block, err := env.Block(ctx, height) + if err != nil { + return nil, err + } versionInfo := version.NewInfo() si := &GetSyncInfo{ - BlockHeight: 123, // block.Block.Header.Height, // TODO[1760]: sync-info - BlockHash: "finishme", // block.Block.Header.Hash().String(), // TODO[1760]: sync-info + BlockHeight: block.Block.Header.Height, + BlockHash: block.Block.Header.Hash().String(), Version: versionInfo.Version, } return si, nil From 1fe846864271c3b3c29817bfaf3aa3d6c06f04a6 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Fri, 26 Apr 2024 15:16:19 -0400 Subject: [PATCH 3/6] Temporary commit with changes. --- app/app.go | 35 +++++++++++++++++++++------------ internal/statesync/statesync.go | 16 +++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/app/app.go b/app/app.go index ca045c2a13..81a720fe96 100644 --- a/app/app.go +++ b/app/app.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + "fmt" "io" "net/http" "os" @@ -16,8 +17,11 @@ import ( "github.com/spf13/cast" "github.com/spf13/viper" + cmtDbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" cmtos "github.com/cometbft/cometbft/libs/os" + cmtrpccore "github.com/cometbft/cometbft/rpc/core" + "github.com/cometbft/cometbft/store" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" @@ -326,18 +330,16 @@ func New( homePath string, invCheckPeriod uint, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - signingOptions := signing.Options{ - AddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - }, - ValidatorAddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), - }, - } - exchange.DefineCustomGetSigners(&signingOptions) interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - SigningOptions: signingOptions, + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() @@ -403,7 +405,15 @@ func New( } // Register helpers for state-sync status. - statesync.RegisterSyncStatus() + if appOpts.Get("db_backend") != nil { + dbBackend := fmt.Sprintf("%v", appOpts.Get("db_backend")) + dbDir := fmt.Sprintf("%v", appOpts.Get("db_dir")) + dbType := cmtDbm.BackendType(dbBackend) + blockStoreDB, _ := cmtDbm.NewDB("blockstore", dbType, dbDir) + blockStore := store.NewBlockStore(blockStoreDB) + env := cmtrpccore.Environment{BlockStore: blockStore} + statesync.RegisterSyncStatus(env) + } app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -1120,7 +1130,6 @@ func New( app.ScopedICQKeeper = scopedICQKeeper app.ScopedICAHostKeeper = scopedICAHostKeeper - simappparams.AppEncodingConfig = app.GetEncodingConfig() return app } diff --git a/internal/statesync/statesync.go b/internal/statesync/statesync.go index d485922823..82fb85c31a 100644 --- a/internal/statesync/statesync.go +++ b/internal/statesync/statesync.go @@ -1,23 +1,23 @@ package statesync import ( - cmtrpccore "github.com/cometbft/cometbft/rpc/core" // TODO[1760]: sync-info - server "github.com/cometbft/cometbft/rpc/jsonrpc/server" // TODO[1760]: sync-info + cmtrpccore "github.com/cometbft/cometbft/rpc/core" + server "github.com/cometbft/cometbft/rpc/jsonrpc/server" cmtrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" "github.com/cosmos/cosmos-sdk/version" ) +type ProvenanceEnvironment struct { + cmtrpccore.Environment +} + func RegisterSyncStatus(env cmtrpccore.Environment) { routes := env.GetRoutes() - routes["sync_info"] = server.NewRPCFunc(GetSyncInfoAtBlock, "height") + routes["sync_info"] = server.NewRPCFunc(env.Header, "height") } -func GetSyncInfoAtBlock(ctx *cmtrpctypes.Context, height *int64) (*GetSyncInfo, error) { - // TODO[1760]: sync-info: Figure out the new way to get the current block. - // How do we get env? - var env cmtrpccore.Environment - +func (env *ProvenanceEnvironment) GetSyncInfoAtBlock(ctx *cmtrpctypes.Context, height *int64) (*GetSyncInfo, error) { block, err := env.Block(ctx, height) if err != nil { return nil, err From 4a39c438c80f3754374d26a46af84fd59075d872 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Wed, 1 May 2024 10:34:32 -0400 Subject: [PATCH 4/6] Update changelog. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c29d6f0a..bc2c368f98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930). * Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930). * Use fields of the SimulationState for the encoders needed for simulations [#1931](https://github.com/provenance-io/provenance/pull/1931). -* Update statesync for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760). +* Removes sync-info code for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760). * Fix most of the failing unit tests [#1943](https://github.com/provenance-io/provenance/pull/1943) ### Dependencies From ef072fc748c20fe7a419d8082764f89f1c17b47c Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Wed, 1 May 2024 10:35:18 -0400 Subject: [PATCH 5/6] Revert to what is in main. --- app/app.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/app/app.go b/app/app.go index 81a720fe96..ca045c2a13 100644 --- a/app/app.go +++ b/app/app.go @@ -2,7 +2,6 @@ package app import ( "encoding/json" - "fmt" "io" "net/http" "os" @@ -17,11 +16,8 @@ import ( "github.com/spf13/cast" "github.com/spf13/viper" - cmtDbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" cmtos "github.com/cometbft/cometbft/libs/os" - cmtrpccore "github.com/cometbft/cometbft/rpc/core" - "github.com/cometbft/cometbft/store" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" @@ -330,16 +326,18 @@ func New( homePath string, invCheckPeriod uint, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ - ProtoFiles: proto.HybridResolver, - SigningOptions: signing.Options{ - AddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), - }, - ValidatorAddressCodec: address.Bech32Codec{ - Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), - }, + signingOptions := signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), }, + } + exchange.DefineCustomGetSigners(&signingOptions) + interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signingOptions, }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() @@ -405,15 +403,7 @@ func New( } // Register helpers for state-sync status. - if appOpts.Get("db_backend") != nil { - dbBackend := fmt.Sprintf("%v", appOpts.Get("db_backend")) - dbDir := fmt.Sprintf("%v", appOpts.Get("db_dir")) - dbType := cmtDbm.BackendType(dbBackend) - blockStoreDB, _ := cmtDbm.NewDB("blockstore", dbType, dbDir) - blockStore := store.NewBlockStore(blockStoreDB) - env := cmtrpccore.Environment{BlockStore: blockStore} - statesync.RegisterSyncStatus(env) - } + statesync.RegisterSyncStatus() app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -1130,6 +1120,7 @@ func New( app.ScopedICQKeeper = scopedICQKeeper app.ScopedICAHostKeeper = scopedICAHostKeeper + simappparams.AppEncodingConfig = app.GetEncodingConfig() return app } From 30b2adcf970dee59385ed01b4d46f081fb526b40 Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Wed, 1 May 2024 10:36:51 -0400 Subject: [PATCH 6/6] Remove sync-info. --- app/app.go | 4 ---- internal/statesync/statesync.go | 38 --------------------------------- 2 files changed, 42 deletions(-) delete mode 100644 internal/statesync/statesync.go diff --git a/app/app.go b/app/app.go index ca045c2a13..0a7d688a05 100644 --- a/app/app.go +++ b/app/app.go @@ -129,7 +129,6 @@ import ( piohandlers "github.com/provenance-io/provenance/internal/handlers" "github.com/provenance-io/provenance/internal/pioconfig" "github.com/provenance-io/provenance/internal/provwasm" - "github.com/provenance-io/provenance/internal/statesync" "github.com/provenance-io/provenance/x/attribute" attributekeeper "github.com/provenance-io/provenance/x/attribute/keeper" attributetypes "github.com/provenance-io/provenance/x/attribute/types" @@ -402,9 +401,6 @@ func New( os.Exit(1) } - // Register helpers for state-sync status. - statesync.RegisterSyncStatus() - app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // set the BaseApp's parameter store diff --git a/internal/statesync/statesync.go b/internal/statesync/statesync.go deleted file mode 100644 index 82fb85c31a..0000000000 --- a/internal/statesync/statesync.go +++ /dev/null @@ -1,38 +0,0 @@ -package statesync - -import ( - cmtrpccore "github.com/cometbft/cometbft/rpc/core" - server "github.com/cometbft/cometbft/rpc/jsonrpc/server" - cmtrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types" - - "github.com/cosmos/cosmos-sdk/version" -) - -type ProvenanceEnvironment struct { - cmtrpccore.Environment -} - -func RegisterSyncStatus(env cmtrpccore.Environment) { - routes := env.GetRoutes() - routes["sync_info"] = server.NewRPCFunc(env.Header, "height") -} - -func (env *ProvenanceEnvironment) GetSyncInfoAtBlock(ctx *cmtrpctypes.Context, height *int64) (*GetSyncInfo, error) { - block, err := env.Block(ctx, height) - if err != nil { - return nil, err - } - versionInfo := version.NewInfo() - si := &GetSyncInfo{ - BlockHeight: block.Block.Header.Height, - BlockHash: block.Block.Header.Hash().String(), - Version: versionInfo.Version, - } - return si, nil -} - -type GetSyncInfo struct { - BlockHeight int64 `json:"block_height"` - BlockHash string `json:"block_hash"` - Version string `json:"version"` -}