From 65b954c0beef2cb996aa2433346236ab7d5f9654 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 31 Oct 2023 17:11:55 +0100 Subject: [PATCH 01/26] test: add minor version upgrade testing --- Makefile | 5 +- test/e2e/node.go | 10 +++- test/e2e/simple_test.go | 7 ++- test/e2e/upgrade_test.go | 82 +++++++++++++++++++++++++ test/e2e/versions.go | 122 ++++++++++++++++++++++++++++++++++++++ test/e2e/versions_test.go | 40 +++++++++++++ 6 files changed, 262 insertions(+), 4 deletions(-) create mode 100644 test/e2e/upgrade_test.go create mode 100644 test/e2e/versions.go create mode 100644 test/e2e/versions_test.go diff --git a/Makefile b/Makefile index 27dbcec62d..4ed74c0a07 100644 --- a/Makefile +++ b/Makefile @@ -117,8 +117,9 @@ test-short: ## test-e2e: Run end to end tests via knuu. test-e2e: - @echo "--> Running e2e tests on version: $(shell git rev-parse --short HEAD)" - @KNUU_NAMESPACE=test E2E_VERSION=$(shell git rev-parse --short HEAD) E2E=true go test ./test/e2e/... -timeout 10m -v + @export E2E_VERSION=$(git tag -l) + @echo "--> Running end to end tests" + @KNUU_NAMESPACE=test E2E=true go test ./test/e2e/... -timeout 10m -v .PHONY: test-e2e ## test-race: Run tests in race mode. diff --git a/test/e2e/node.go b/test/e2e/node.go index 57bd165d6e..c73c45dcb7 100644 --- a/test/e2e/node.go +++ b/test/e2e/node.go @@ -50,7 +50,7 @@ func NewNode( if err != nil { return nil, err } - err = instance.SetImage(fmt.Sprintf("%s:%s", dockerSrcURL, version)) + err = instance.SetImage(DockerImageName(version)) if err != nil { return nil, err } @@ -260,3 +260,11 @@ func (n *Node) Start() error { n.grpcProxyPort = grpcProxyPort return nil } + +func (n *Node) Upgrade(version string) error { + return n.Instance.SetImageInstant(DockerImageName(version)) +} + +func DockerImageName(version string) string { + return fmt.Sprintf("%s:%s", dockerSrcURL, version) +} diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index dc668ad3b9..a305893b13 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -3,6 +3,7 @@ package e2e import ( "context" "errors" + "fmt" "os" "testing" "time" @@ -27,8 +28,12 @@ func TestE2ESimple(t *testing.T) { } if os.Getenv("E2E_VERSION") != "" { - latestVersion = os.Getenv("E2E_VERSION") + versionsStr := os.Getenv("E2E_VERSION") + versions := ParseVersions(versionsStr) + fmt.Println(versions.String()) + latestVersion = versions.GetLatest().String() } + t.Log("Running simple e2e test", "version", latestVersion) testnet, err := New(t.Name(), seed) require.NoError(t, err) diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go new file mode 100644 index 0000000000..a6cfecf849 --- /dev/null +++ b/test/e2e/upgrade_test.go @@ -0,0 +1,82 @@ +package e2e + +import ( + "context" + "errors" + "math/rand" + "os" + "testing" + "time" + + "github.com/celestiaorg/celestia-app/app" + "github.com/celestiaorg/celestia-app/app/encoding" + "github.com/celestiaorg/celestia-app/test/txsim" + "github.com/celestiaorg/knuu/pkg/knuu" + "github.com/stretchr/testify/require" +) + +// This will only run tests within the v1 major release cycle +const MajorVersion = 1 + +func TestMinorVersionCompatibility(t *testing.T) { + versionStr := os.Getenv("E2E_VERSION") + versions := ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates() + numNodes := 4 + r := rand.New(rand.NewSource(seed)) + t.Log("Running minor version compatibility test", "versions", versions) + + testnet, err := New(t.Name(), seed) + require.NoError(t, err) + t.Cleanup(testnet.Cleanup) + + // preload all docker images + preloader, err := knuu.NewPreloader() + require.NoError(t, err) + t.Cleanup(func() { _ = preloader.EmptyImages() }) + for _, v := range versions { + err := preloader.AddImage(DockerImageName(v.String())) + require.NoError(t, err) + } + + for i := 0; i < numNodes; i++ { + // each node begins with a random version within the same major version set + v := versions.Random(r).String() + t.Log("Starting node", "node", i, "version", v) + require.NoError(t, testnet.CreateGenesisNode(v, 10000000)) + } + + kr, err := testnet.CreateAccount("alice", 1e12) + require.NoError(t, err) + + require.NoError(t, testnet.Setup()) + require.NoError(t, testnet.Start()) + + sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5) + sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...) + + errCh := make(chan error) + encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) + opts := txsim.DefaultOptions().WithSeed(seed) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go func() { + errCh <- txsim.Run(ctx, testnet.GRPCEndpoints()[0], kr, encCfg, opts, sequences...) + }() + + for i := 0; i < len(versions)*2; i++ { + // FIXME: skip the first node because we need them available to + // submit txs + if i%numNodes == 0 { + continue + } + newVersion := versions.Random(r).String() + t.Log("Upgrading node", "node", i%numNodes, "version", newVersion) + err := testnet.Node(i % numNodes).Upgrade(newVersion) + require.NoError(t, err) + time.Sleep(2 * time.Second) + } + cancel() + + err = <-errCh + require.True(t, errors.Is(err, context.Canceled), err.Error()) +} diff --git a/test/e2e/versions.go b/test/e2e/versions.go new file mode 100644 index 0000000000..b6600259c3 --- /dev/null +++ b/test/e2e/versions.go @@ -0,0 +1,122 @@ +package e2e + +import ( + "fmt" + "math/rand" + "sort" + "strings" +) + +type Version struct { + Major uint64 + Minor uint64 + Patch uint64 + IsRC bool + RC uint64 +} + +func (v Version) String() string { + if v.IsRC { + return fmt.Sprintf("v%d.%d.%d-rc%d", v.Major, v.Minor, v.Patch, v.RC) + } + return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch) +} + +func (v Version) IsGreater(v2 Version) bool { + if v.Major > v2.Major { + return true + } + if v.Major < v2.Major { + return false + } + if v.Minor > v2.Minor { + return true + } + if v.Minor < v2.Minor { + return false + } + if v.Patch > v2.Patch { + return true + } + if v.Patch < v2.Patch { + return false + } + if v.RC > v2.RC { + return true + } + return false +} + +type VersionSet []Version + +func ParseVersions(versionStr string) VersionSet { + versions := strings.Split(versionStr, "\n") + output := make(VersionSet, 0, len(versions)) + for _, v := range versions { + var major, minor, patch, rc uint64 + isRC := false + if strings.Contains(v, "rc") { + _, err := fmt.Sscanf(v, "v%d.%d.%d-rc%d", &major, &minor, &patch, &rc) + isRC = true + if err != nil { + continue + } + } else { + _, err := fmt.Sscanf(v, "v%d.%d.%d", &major, &minor, &patch) + if err != nil { + continue + } + } + output = append(output, Version{major, minor, patch, isRC, rc}) + } + return output +} + +func (v VersionSet) FilterMajor(majorVersion uint64) VersionSet { + output := make(VersionSet, 0, len(v)) + for _, version := range v { + if version.Major == majorVersion { + output = append(output, version) + } + } + return output +} + +func (v VersionSet) FilterOutReleaseCandidates() VersionSet { + output := make(VersionSet, 0, len(v)) + for _, version := range v { + if version.IsRC { + continue + } + output = append(output, version) + } + return output +} + +func (v VersionSet) GetLatest() Version { + latest := Version{} + for _, version := range v { + if version.IsGreater(latest) { + latest = version + } + } + return latest +} + +func (v VersionSet) Order() { + sort.Slice(v, func(i, j int) bool { + return v[j].IsGreater(v[i]) + }) +} + +func (v VersionSet) Random(r *rand.Rand) Version { + return v[r.Intn(len(v))] +} + +func (v VersionSet) String() string { + output := make([]string, len(v)) + for i, version := range v { + output[i] = version.String() + } + return strings.Join(output, "\t") +} diff --git a/test/e2e/versions_test.go b/test/e2e/versions_test.go new file mode 100644 index 0000000000..17f66d3257 --- /dev/null +++ b/test/e2e/versions_test.go @@ -0,0 +1,40 @@ +package e2e_test + +import ( + "testing" + + "github.com/celestiaorg/celestia-app/test/e2e" + "github.com/stretchr/testify/require" +) + +func TestVersionParsing(t *testing.T) { + versionStr := "v1.3.0\nv1.1.0\nv1.2.0-rc0" + versions := e2e.ParseVersions(versionStr) + require.Len(t, versions, 3) + require.Len(t, versions.FilterOutReleaseCandidates(), 2) + require.Equal(t, versions.GetLatest(), e2e.Version{1, 3, 0, false, 0}) +} + +// Test case with multiple major versions and filtering out a single major version +func TestFilterMajorVersions(t *testing.T) { + versionStr := "v2.0.0\nv1.1.0\nv2.1.0-rc0\nv1.2.0\nv2.2.0\nv1.3.0" + versions := e2e.ParseVersions(versionStr) + require.Len(t, versions, 6) + require.Len(t, versions.FilterMajor(1), 3) +} + +// Test case to check the Order function +func TestOrder(t *testing.T) { + versionStr := "v1.3.0\nv1.1.0\nv1.2.0-rc0\nv1.4.0\nv1.2.1\nv2.0.0" + versions := e2e.ParseVersions(versionStr) + versions.Order() + require.Equal(t, versions[0], e2e.Version{1, 1, 0, false, 0}) + require.Equal(t, versions[1], e2e.Version{1, 2, 0, true, 0}) + require.Equal(t, versions[2], e2e.Version{1, 2, 1, false, 0}) + require.Equal(t, versions[3], e2e.Version{1, 3, 0, false, 0}) + require.Equal(t, versions[4], e2e.Version{1, 4, 0, false, 0}) + require.Equal(t, versions[5], e2e.Version{2, 0, 0, false, 0}) + for i := len(versions) - 1; i > 0; i-- { + require.True(t, versions[i].IsGreater(versions[i-1])) + } +} From 2477ef47ed5e1c803088f3a0d5ee16c5f4e8771d Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 31 Oct 2023 17:13:58 +0100 Subject: [PATCH 02/26] require version to be set --- test/e2e/upgrade_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index a6cfecf849..cf9a9a9869 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -19,6 +19,14 @@ import ( const MajorVersion = 1 func TestMinorVersionCompatibility(t *testing.T) { + if os.Getenv("E2E") == "" { + t.Skip("skipping e2e test") + } + + if os.Getenv("E2E_VERSION") == "" { + t.Skip("skipping e2e test: E2E_VERSION not set") + } + versionStr := os.Getenv("E2E_VERSION") versions := ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates() numNodes := 4 From 1c7ad45d16e5154e0509a2f4ef52791622d54a61 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 31 Oct 2023 17:18:57 +0100 Subject: [PATCH 03/26] remove print statement --- test/e2e/simple_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index a305893b13..e753a417a4 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -3,7 +3,6 @@ package e2e import ( "context" "errors" - "fmt" "os" "testing" "time" @@ -30,7 +29,6 @@ func TestE2ESimple(t *testing.T) { if os.Getenv("E2E_VERSION") != "" { versionsStr := os.Getenv("E2E_VERSION") versions := ParseVersions(versionsStr) - fmt.Println(versions.String()) latestVersion = versions.GetLatest().String() } t.Log("Running simple e2e test", "version", latestVersion) From f446568191e657606f93158fbef9aeb733d2d521 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 1 Nov 2023 17:27:19 +0100 Subject: [PATCH 04/26] use an upgrade flag for v2 --- app/app.go | 23 ++--- app/deliver_tx.go | 23 ----- app/prepare_proposal.go | 30 ------- app/process_proposal.go | 22 ----- cmd/celestia-appd/cmd/root.go | 19 +++- test/tokenfilter/setup.go | 2 +- test/util/malicious/app.go | 2 +- test/util/network/network.go | 2 +- test/util/test_app.go | 2 +- x/upgrade/keeper.go | 26 +++--- x/upgrade/types.go | 73 --------------- x/upgrade/types_test.go | 69 -------------- x/upgrade/upgrade.go | 40 --------- x/upgrade/upgrade_test.go | 165 +--------------------------------- 14 files changed, 41 insertions(+), 457 deletions(-) delete mode 100644 app/deliver_tx.go delete mode 100644 x/upgrade/types_test.go delete mode 100644 x/upgrade/upgrade.go diff --git a/app/app.go b/app/app.go index 8803240b5b..b7b93f9ace 100644 --- a/app/app.go +++ b/app/app.go @@ -85,6 +85,7 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" + v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/pkg/proof" blobmodule "github.com/celestiaorg/celestia-app/x/blob" blobmodulekeeper "github.com/celestiaorg/celestia-app/x/blob/keeper" @@ -246,16 +247,10 @@ func New( loadLatest bool, invCheckPeriod uint, encodingConfig encoding.Config, - upgradeSchedule map[string]upgrade.Schedule, + upgradeHeight int64, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - for _, schedule := range upgradeSchedule { - if err := schedule.ValidateVersions(supportedVersions); err != nil { - panic(err) - } - } - appCodec := encodingConfig.Codec cdc := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry @@ -334,7 +329,7 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], upgradeSchedule) + app.UpgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], upgradeHeight) app.BlobstreamKeeper = *bsmodulekeeper.NewKeeper( appCodec, @@ -574,14 +569,10 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker application updates every end block func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { res := app.mm.EndBlock(ctx, req) - if app.UpgradeKeeper.ShouldUpgrade() { - newAppVersion := app.UpgradeKeeper.GetNextAppVersion() - app.SetProtocolVersion(newAppVersion) - _, err := app.mm.RunMigrations(ctx, app.configurator, GetModuleVersion(newAppVersion)) - if err != nil { - panic(err) - } - app.UpgradeKeeper.MarkUpgradeComplete() + // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected + // to be coordinated through the signalling protocol + if app.UpgradeKeeper.ShouldUpgrade(req.Height) { + app.SetProtocolVersion(v2.Version) } return res } diff --git a/app/deliver_tx.go b/app/deliver_tx.go deleted file mode 100644 index 1b3dbc3d6f..0000000000 --- a/app/deliver_tx.go +++ /dev/null @@ -1,23 +0,0 @@ -package app - -import ( - "fmt" - - "github.com/celestiaorg/celestia-app/x/upgrade" - abci "github.com/tendermint/tendermint/abci/types" -) - -func (app *App) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { - sdkTx, err := app.txConfig.TxDecoder()(req.Tx) - if err == nil { - if appVersion, ok := upgrade.IsUpgradeMsg(sdkTx.GetMsgs()); ok { - if !IsSupported(appVersion) { - panic(fmt.Sprintf("network has upgraded to version %d which is not supported by this node. Please upgrade and restart", appVersion)) - } - app.UpgradeKeeper.PrepareUpgradeAtEndBlock(appVersion) - // TODO: we may want to emit an event for this - return abci.ResponseDeliverTx{Code: abci.CodeTypeOK} - } - } - return app.BaseApp.DeliverTx(req) -} diff --git a/app/prepare_proposal.go b/app/prepare_proposal.go index 8929c31cd5..2240f79371 100644 --- a/app/prepare_proposal.go +++ b/app/prepare_proposal.go @@ -7,7 +7,6 @@ import ( "github.com/celestiaorg/celestia-app/pkg/da" "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" - "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/cosmos/cosmos-sdk/telemetry" abci "github.com/tendermint/tendermint/abci/types" core "github.com/tendermint/tendermint/proto/tendermint/types" @@ -59,27 +58,6 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr txs = make([][]byte, 0) } else { txs = FilterTxs(app.Logger(), sdkCtx, handler, app.txConfig, req.BlockData.Txs) - - // TODO: this would be improved if we only attempted the upgrade in the first round of the - // height to still allow transactions to pass through without being delayed from trying - // to coordinate the upgrade height - if newVersion, ok := app.UpgradeKeeper.ShouldProposeUpgrade(req.ChainId, req.Height); ok && newVersion > app.GetBaseApp().AppVersion() { - upgradeTx, err := upgrade.NewMsgVersionChange(app.txConfig, newVersion) - if err != nil { - panic(err) - } - // the upgrade transaction must be the first transaction in the block - txs = append([][]byte{upgradeTx}, txs...) - - // because we are adding bytes, we need to check that we are not going over the limit - // if we are, we continually prune the last tx (the lowest paying blobTx). - size := sizeOf(txs) - for size > int(req.BlockDataSize) { - lastTx := txs[len(txs)-1] - txs = txs[:len(txs)-1] - size -= len(lastTx) - } - } } // build the square from the set of valid and prioritised transactions. @@ -124,11 +102,3 @@ func (app *App) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePr }, } } - -func sizeOf(txs [][]byte) int { - size := 0 - for _, tx := range txs { - size += len(tx) - } - return size -} diff --git a/app/process_proposal.go b/app/process_proposal.go index 9a09731871..b95bc48d8e 100644 --- a/app/process_proposal.go +++ b/app/process_proposal.go @@ -11,7 +11,6 @@ import ( "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" - "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -76,27 +75,6 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp return reject() } - if appVersion, ok := upgrade.IsUpgradeMsg(msgs); ok { - if idx != 0 { - logInvalidPropBlock(app.Logger(), req.Header, fmt.Sprintf("upgrade message %d is not the first transaction", idx)) - return reject() - } - - if !IsSupported(appVersion) { - logInvalidPropBlock(app.Logger(), req.Header, fmt.Sprintf("block proposes an unsupported app version %d", appVersion)) - return reject() - } - - // app version must always increase - if appVersion <= app.GetBaseApp().AppVersion() { - logInvalidPropBlock(app.Logger(), req.Header, fmt.Sprintf("block proposes an app version %d that is not greater than the current app version %d", appVersion, app.GetBaseApp().AppVersion())) - return reject() - } - - // we don't need to pass this message through the ante handler - continue - } - // we need to increment the sequence for every transaction so that // the signature check below is accurate. this error only gets hit // if the account in question doens't exist. diff --git a/cmd/celestia-appd/cmd/root.go b/cmd/celestia-appd/cmd/root.go index be95396665..5c824510b0 100644 --- a/cmd/celestia-appd/cmd/root.go +++ b/cmd/celestia-appd/cmd/root.go @@ -4,6 +4,7 @@ import ( "io" "os" "path/filepath" + "strconv" bscmd "github.com/celestiaorg/celestia-app/x/blobstream/client" @@ -44,6 +45,8 @@ const ( // FlagLogToFile specifies whether to log to file or not. FlagLogToFile = "log-to-file" + + UpgradeHeightFlag = "upgrade-height" ) // NewRootCmd creates a new root command for celestia-appd. It is called once in the @@ -152,6 +155,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig encoding.Config) { func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) + startCmd.Flags().Int64(UpgradeHeightFlag, 0, "Upgrade height to switch to v2. Must be coordinated amongst all validators") } func queryCommand() *cobra.Command { @@ -228,11 +232,20 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts se panic(err) } + var upgradeHeight int64 + upgradeHeightStr, ok := appOpts.Get(UpgradeHeightFlag).(string) + if ok { + upgradeHeight, err = strconv.ParseInt(upgradeHeightStr, 10, 64) + if err != nil { + panic(err) + } + } + return app.New( logger, db, traceStore, true, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), // Ideally, we would reuse the one created by NewRootCmd. - nil, + upgradeHeight, appOpts, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), @@ -255,13 +268,13 @@ func createAppAndExport( encCfg.Codec = codec.NewProtoCodec(encCfg.InterfaceRegistry) var capp *app.App if height != -1 { - capp = app.New(logger, db, traceStore, false, uint(1), encCfg, nil, appOpts) + capp = app.New(logger, db, traceStore, false, uint(1), encCfg, 0, appOpts) if err := capp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - capp = app.New(logger, db, traceStore, true, uint(1), encCfg, nil, appOpts) + capp = app.New(logger, db, traceStore, true, uint(1), encCfg, 0, appOpts) } return capp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) diff --git a/test/tokenfilter/setup.go b/test/tokenfilter/setup.go index 454ea97e93..54e6706cef 100644 --- a/test/tokenfilter/setup.go +++ b/test/tokenfilter/setup.go @@ -140,7 +140,7 @@ func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs encCdc := encoding.MakeConfig(app.ModuleEncodingRegisters...) genesisState := app.NewDefaultGenesisState(encCdc.Codec) app := app.New( - log.NewNopLogger(), db, nil, true, 5, encCdc, nil, simapp.EmptyAppOptions{}, + log.NewNopLogger(), db, nil, true, 5, encCdc, 0, simapp.EmptyAppOptions{}, ) // set genesis accounts diff --git a/test/util/malicious/app.go b/test/util/malicious/app.go index 20e813748c..09d610dcca 100644 --- a/test/util/malicious/app.go +++ b/test/util/malicious/app.go @@ -57,7 +57,7 @@ func New( appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - goodApp := app.New(logger, db, traceStore, loadLatest, invCheckPeriod, encodingConfig, nil, appOpts, baseAppOptions...) + goodApp := app.New(logger, db, traceStore, loadLatest, invCheckPeriod, encodingConfig, 0, appOpts, baseAppOptions...) badApp := &App{App: goodApp} // set the malicious prepare proposal handler if it is set in the app options diff --git a/test/util/network/network.go b/test/util/network/network.go index fc130e7d23..8149c55141 100644 --- a/test/util/network/network.go +++ b/test/util/network/network.go @@ -77,7 +77,7 @@ func DefaultConfig() network.Config { AppConstructor: func(val network.Validator) servertypes.Application { return app.New( val.Ctx.Logger, tmdb.NewMemDB(), nil, true, 0, - encCfg, nil, + encCfg, 0, simapp.EmptyAppOptions{}, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), diff --git a/test/util/test_app.go b/test/util/test_app.go index f13ace9243..56e805fd67 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -62,7 +62,7 @@ func SetupTestAppWithGenesisValSet(cparams *tmproto.ConsensusParams, genAccounts log.NewNopLogger(), db, nil, true, cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), encCfg, - nil, + 0, emptyOpts, ) diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index 2b8b15c81f..54b03dd7d9 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -1,8 +1,6 @@ package upgrade import ( - fmt "fmt" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -16,26 +14,18 @@ type Keeper struct { // safely be ported over without any migration storeKey storetypes.StoreKey - // in memory copy of the upgrade schedule if any. This is local per node + // in memory copy of the upgrade height if any. This is local per node // and configured from the config. - upgradeSchedule map[string]Schedule - - // the app version that should be set in end blocker - pendingAppVersion uint64 + upgradeHeight int64 } type VersionSetter func(version uint64) // NewKeeper constructs an upgrade keeper -func NewKeeper(storeKey storetypes.StoreKey, upgradeSchedule map[string]Schedule) Keeper { - for chainID, schedule := range upgradeSchedule { - if err := schedule.ValidateBasic(); err != nil { - panic(fmt.Sprintf("invalid schedule %s: %v", chainID, err)) - } - } +func NewKeeper(storeKey storetypes.StoreKey, upgradeHeight int64) Keeper { return Keeper{ - storeKey: storeKey, - upgradeSchedule: upgradeSchedule, + storeKey: storeKey, + upgradeHeight: upgradeHeight, } } @@ -99,3 +89,9 @@ func (k Keeper) ClearIBCState(ctx sdk.Context, lastHeight int64) { store.Delete(types.UpgradedClientKey(lastHeight)) store.Delete(types.UpgradedConsStateKey(lastHeight)) } + +// ShouldUpgrade returns true if the current height is one before +// the locally provided upgrade height that is passed as a flag +func (k Keeper) ShouldUpgrade(height int64) bool { + return k.upgradeHeight == height+1 +} diff --git a/x/upgrade/types.go b/x/upgrade/types.go index 79fe78cfdb..ba3270a9c0 100644 --- a/x/upgrade/types.go +++ b/x/upgrade/types.go @@ -1,8 +1,6 @@ package upgrade import ( - fmt "fmt" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -65,74 +63,3 @@ func IsUpgradeMsg(msg []sdk.Msg) (uint64, bool) { } return msgVersionChange.Version, true } - -func (s Schedule) ValidateBasic() error { - lastHeight := 0 - lastVersion := uint64(0) - for idx, plan := range s { - if err := plan.ValidateBasic(); err != nil { - return fmt.Errorf("plan %d: %w", idx, err) - } - if plan.Start <= int64(lastHeight) { - return fmt.Errorf("plan %d: start height must be greater than %d, got %d", idx, lastHeight, plan.Start) - } - if plan.Version <= lastVersion { - return fmt.Errorf("plan %d: version must be greater than %d, got %d", idx, lastVersion, plan.Version) - } - lastHeight = int(plan.End) - lastVersion = plan.Version - } - return nil -} - -// ValidateVersions checks if all plan versions are covered by all the app versions -// that the state machine supports. -func (s Schedule) ValidateVersions(appVersions []uint64) error { - versionMap := make(map[uint64]struct{}) - for _, version := range appVersions { - versionMap[version] = struct{}{} - } - for _, plan := range s { - if _, ok := versionMap[plan.Version]; !ok { - return fmt.Errorf("plan version %d not found in app versions %v", plan.Version, appVersions) - } - } - return nil -} - -func (s Schedule) ShouldProposeUpgrade(height int64) (uint64, bool) { - for _, plan := range s { - if height >= plan.Start-1 && height < plan.End { - return plan.Version, true - } - } - return 0, false -} - -func (p Plan) ValidateBasic() error { - if p.Start < 1 { - return fmt.Errorf("plan start height cannot be negative or zero: %d", p.Start) - } - if p.End < 1 { - return fmt.Errorf("plan end height cannot be negative or zero: %d", p.End) - } - if p.Start > p.End { - return fmt.Errorf("plan end height must be greater or equal than start height: %d >= %d", p.Start, p.End) - } - if p.Version == 0 { - return fmt.Errorf("plan version cannot be zero") - } - return nil -} - -func NewSchedule(plans ...Plan) Schedule { - return plans -} - -func NewPlan(startHeight, endHeight int64, version uint64) Plan { - return Plan{ - Start: startHeight, - End: endHeight, - Version: version, - } -} diff --git a/x/upgrade/types_test.go b/x/upgrade/types_test.go deleted file mode 100644 index aef2e8bb5e..0000000000 --- a/x/upgrade/types_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package upgrade_test - -import ( - fmt "fmt" - "testing" - - "github.com/celestiaorg/celestia-app/x/upgrade" - "github.com/stretchr/testify/require" -) - -func TestScheduleValidity(t *testing.T) { - testCases := []struct { - schedule upgrade.Schedule - valid bool - }{ - // can be empty - {upgrade.Schedule{}, true}, - // plan can not start at height 0 - {upgrade.Schedule{upgrade.Plan{Start: 0, End: 2, Version: 1}}, false}, - // end height can not be 0 - {upgrade.Schedule{upgrade.Plan{Version: 1}}, false}, - {upgrade.Schedule{upgrade.Plan{Start: 1, End: 2, Version: 1}}, true}, - // version can't be 0 - {upgrade.Schedule{upgrade.Plan{Start: 1, End: 2, Version: 0}}, false}, - // start and end height can be the same - {upgrade.Schedule{upgrade.Plan{Start: 2, End: 2, Version: 1}}, true}, - // end height must be greater than start height - {upgrade.Schedule{upgrade.Plan{Start: 2, End: 1, Version: 1}}, false}, - // plans can not overlap - {upgrade.Schedule{upgrade.Plan{Start: 1, End: 2, Version: 1}, upgrade.Plan{Start: 2, End: 3, Version: 2}}, false}, - // plans must be in order. They can skip versions - {upgrade.Schedule{upgrade.Plan{Start: 1, End: 2, Version: 1}, upgrade.Plan{Start: 3, End: 4, Version: 2}, upgrade.Plan{Start: 5, End: 6, Version: 4}}, true}, - {upgrade.Schedule{upgrade.Plan{Start: 1, End: 2, Version: 1}, upgrade.Plan{Start: 3, End: 4, Version: 2}, upgrade.Plan{Start: 5, End: 10, Version: 1}}, false}, - } - - for idx, tc := range testCases { - t.Run(fmt.Sprintf("case%d", idx), func(t *testing.T) { - if tc.valid { - require.NoError(t, tc.schedule.ValidateBasic()) - } else { - require.Error(t, tc.schedule.ValidateBasic()) - } - }) - } -} - -func TestScheduleValidateVersions(t *testing.T) { - testCases := []struct { - schedule upgrade.Schedule - appVersions []uint64 - valid bool - }{ - // can be empty - {upgrade.Schedule{}, []uint64{1, 2, 3}, true}, - {upgrade.Schedule{upgrade.Plan{Version: 3}}, []uint64{1, 2, 3}, true}, - {upgrade.Schedule{upgrade.Plan{Version: 4}}, []uint64{1, 2, 3}, false}, - {upgrade.Schedule{upgrade.Plan{Version: 2}, upgrade.Plan{Version: 5}}, []uint64{1, 2, 3}, false}, - } - - for idx, tc := range testCases { - t.Run(fmt.Sprintf("case%d", idx), func(t *testing.T) { - if tc.valid { - require.NoError(t, tc.schedule.ValidateVersions(tc.appVersions)) - } else { - require.Error(t, tc.schedule.ValidateVersions(tc.appVersions)) - } - }) - } -} diff --git a/x/upgrade/upgrade.go b/x/upgrade/upgrade.go deleted file mode 100644 index aedf46aa91..0000000000 --- a/x/upgrade/upgrade.go +++ /dev/null @@ -1,40 +0,0 @@ -package upgrade - -type Schedule []Plan - -type Plan struct { - Start int64 - End int64 - Version uint64 -} - -// ShouldUpgradeNextHeight returns true if the network of the given chainID should -// modify the app version in the following block. This can be used for both upgrading -// and downgrading. This relies on social consensus to work. At least 2/3+ of the -// validators must have the same app version and height in their schedule for the -// upgrade to happen successfully. -func (k Keeper) ShouldProposeUpgrade(chainID string, height int64) (uint64, bool) { - if k.upgradeSchedule == nil { - return 0, false - } - if schedule, ok := k.upgradeSchedule[chainID]; ok { - return schedule.ShouldProposeUpgrade(height) - } - return 0, false -} - -func (k *Keeper) PrepareUpgradeAtEndBlock(version uint64) { - k.pendingAppVersion = version -} - -func (k *Keeper) ShouldUpgrade() bool { - return k.pendingAppVersion != 0 -} - -func (k Keeper) GetNextAppVersion() uint64 { - return k.pendingAppVersion -} - -func (k *Keeper) MarkUpgradeComplete() { - k.pendingAppVersion = 0 -} diff --git a/x/upgrade/upgrade_test.go b/x/upgrade/upgrade_test.go index 2921d472e5..5cf6b9fe78 100644 --- a/x/upgrade/upgrade_test.go +++ b/x/upgrade/upgrade_test.go @@ -7,17 +7,8 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/appconsts" - "github.com/celestiaorg/celestia-app/pkg/da" - "github.com/celestiaorg/celestia-app/pkg/shares" - "github.com/celestiaorg/celestia-app/pkg/square" - "github.com/celestiaorg/celestia-app/pkg/user" "github.com/celestiaorg/celestia-app/test/util" - "github.com/celestiaorg/celestia-app/test/util/testfactory" - "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/types" - bank "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -26,174 +17,24 @@ import ( ) func TestUpgradeAppVersion(t *testing.T) { - testApp, kr := setupTestApp(t, upgrade.NewSchedule(upgrade.NewPlan(3, 5, 2))) - addr := testfactory.GetAddress(kr, "account") - encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - signer, err := user.NewSigner(kr, nil, addr, encCfg.TxConfig, testApp.GetChainID(), 1, 0) - require.NoError(t, err) - coins := types.NewCoins(types.NewCoin("utia", types.NewInt(10))) - sendMsg := bank.NewMsgSend(addr, addr, coins) - sendTx, err := signer.CreateTx([]types.Msg{sendMsg}, user.SetGasLimitAndFee(1e6, 1)) - require.NoError(t, err) - - upgradeTx, err := upgrade.NewMsgVersionChange(testApp.GetTxConfig(), 3) - require.NoError(t, err) - respCheckTx := testApp.CheckTx(abci.RequestCheckTx{Tx: upgradeTx}) - // we expect that a new msg version change should always be rejected - // by checkTx - require.EqualValues(t, 15, respCheckTx.Code, respCheckTx.Log) - - resp := testApp.PrepareProposal(abci.RequestPrepareProposal{ - Height: 2, - ChainId: testApp.GetChainID(), - BlockData: &tmproto.Data{}, - BlockDataSize: 1e6, - }) - - // At the height before the first height in the upgrade plan, the - // node should prepend a signal upgrade message. - require.Len(t, resp.BlockData.Txs, 1) - tx, err := testApp.GetTxConfig().TxDecoder()(resp.BlockData.Txs[0]) - require.NoError(t, err) - require.Len(t, tx.GetMsgs(), 1) - msg, ok := tx.GetMsgs()[0].(*upgrade.MsgVersionChange) - require.True(t, ok) - require.EqualValues(t, 2, msg.Version) - - { - // the same thing should happen if we run prepare proposal - // at height 4 as it is within the range - resp := testApp.PrepareProposal(abci.RequestPrepareProposal{ - Height: 4, - ChainId: testApp.GetChainID(), - BlockData: &tmproto.Data{}, - BlockDataSize: 1e6, - }) - - require.Len(t, resp.BlockData.Txs, 1) - tx, err := testApp.GetTxConfig().TxDecoder()(resp.BlockData.Txs[0]) - require.NoError(t, err) - require.Len(t, tx.GetMsgs(), 1) - msg, ok := tx.GetMsgs()[0].(*upgrade.MsgVersionChange) - require.True(t, ok) - require.EqualValues(t, 2, msg.Version) - } - - { - // we send the same proposal but now with an existing message and a - // smaller BlockDataSize. It should kick out the tx in place of the - // upgrade tx - resp := testApp.PrepareProposal(abci.RequestPrepareProposal{ - Height: 2, - ChainId: testApp.GetChainID(), - BlockData: &tmproto.Data{Txs: [][]byte{sendTx}}, - BlockDataSize: 1e2, - }) - require.Len(t, resp.BlockData.Txs, 1) - tx, err := testApp.GetTxConfig().TxDecoder()(resp.BlockData.Txs[0]) - require.NoError(t, err) - require.Len(t, tx.GetMsgs(), 1) - msg, ok := tx.GetMsgs()[0].(*upgrade.MsgVersionChange) - require.True(t, ok) - require.EqualValues(t, 2, msg.Version) - } - - { - // Height 5 however is outside the range and thus the upgrade - // message should not be prepended - resp := testApp.PrepareProposal(abci.RequestPrepareProposal{ - Height: 5, - ChainId: testApp.GetChainID(), - BlockData: &tmproto.Data{}, - BlockDataSize: 1e6, - }) - require.Len(t, resp.BlockData.Txs, 0) - } - - // We should accept this proposal as valid - processProposalResp := testApp.ProcessProposal(abci.RequestProcessProposal{ - Header: tmproto.Header{ - Height: 2, - DataHash: resp.BlockData.Hash, - }, - BlockData: resp.BlockData, - }) - require.True(t, processProposalResp.IsOK()) - - { - // to assert that the upgrade tx must be the first tx - // we insert a tx before the upgrade tx. To get the hash - // we need to build the square and data availability header - txs := [][]byte{[]byte("hello world"), upgradeTx} - dataSquare, txs, err := square.Build(txs, appconsts.LatestVersion, appconsts.DefaultGovMaxSquareSize) - require.NoError(t, err) - eds, err := da.ExtendShares(shares.ToBytes(dataSquare)) - require.NoError(t, err) - dah, err := da.NewDataAvailabilityHeader(eds) - require.NoError(t, err) - blockData := &tmproto.Data{ - Txs: txs, - SquareSize: uint64(dataSquare.Size()), - Hash: dah.Hash(), - } - - processProposalResp := testApp.ProcessProposal(abci.RequestProcessProposal{ - Header: tmproto.Header{ - Height: 2, - DataHash: blockData.Hash, - }, - BlockData: blockData, - }) - require.True(t, processProposalResp.IsRejected()) - } + testApp, _ := setupTestApp(t, 3) testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}}) - respDeliverTx := testApp.DeliverTx(abci.RequestDeliverTx{Tx: resp.BlockData.Txs[0]}) - require.EqualValues(t, 0, respDeliverTx.Code, respDeliverTx.Log) // app version should not have changed yet require.EqualValues(t, 1, testApp.AppVersion()) respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) // now the app version changes require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) require.EqualValues(t, 2, testApp.AppVersion()) - - _ = testApp.Commit() - - // If another node proposes a block with a version change that is - // not supported by the nodes own state machine then the node - // rejects the proposed block - respProcessProposal := testApp.ProcessProposal(abci.RequestProcessProposal{ - Header: tmproto.Header{ - Height: 3, - }, - BlockData: &tmproto.Data{ - Txs: [][]byte{upgradeTx}, - }, - }) - require.True(t, respProcessProposal.IsRejected()) - - // if we ask the application to prepare another proposal - // it will not add the upgrade signal message even though - // its within the range of the plan because the application - // has already upgraded to that height - respPrepareProposal := testApp.PrepareProposal(abci.RequestPrepareProposal{ - Height: 3, - ChainId: testApp.GetChainID(), - BlockData: &tmproto.Data{}, - BlockDataSize: 1e6, - }) - require.Len(t, respPrepareProposal.BlockData.Txs, 0) } -func setupTestApp(t *testing.T, schedule upgrade.Schedule) (*app.App, keyring.Keyring) { +func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { t.Helper() db := dbm.NewMemDB() chainID := "test_chain" encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - upgradeSchedule := make(map[string]upgrade.Schedule) - upgradeSchedule[chainID] = schedule - testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeSchedule, util.EmptyAppOptions{}) + testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account") From 4ac4bdbd765328471ed8c1e5f31160c3cbeaa739 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 1 Nov 2023 18:22:22 +0100 Subject: [PATCH 05/26] incorporate suggestions --- Makefile | 2 +- test/e2e/simple_test.go | 6 +++--- test/e2e/upgrade_test.go | 6 +++--- test/e2e/versions.go | 6 ++++++ test/e2e/versions_test.go | 9 +++++++++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4ed74c0a07..fd83daf612 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ test-short: ## test-e2e: Run end to end tests via knuu. test-e2e: - @export E2E_VERSION=$(git tag -l) + @export E2E_VERSIONS=$(git tag -l) @echo "--> Running end to end tests" @KNUU_NAMESPACE=test E2E=true go test ./test/e2e/... -timeout 10m -v .PHONY: test-e2e diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index e753a417a4..c632265c10 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -22,12 +22,12 @@ var latestVersion = "latest" // and MsgSends over 30 seconds and then asserts that at least 10 transactions were // committed. func TestE2ESimple(t *testing.T) { - if os.Getenv("E2E") == "" { + if os.Getenv("E2E") != "true" { t.Skip("skipping e2e test") } - if os.Getenv("E2E_VERSION") != "" { - versionsStr := os.Getenv("E2E_VERSION") + if os.Getenv("E2E_VERSIONS") != "" { + versionsStr := os.Getenv("E2E_VERSIONS") versions := ParseVersions(versionsStr) latestVersion = versions.GetLatest().String() } diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index cf9a9a9869..704e240095 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -19,15 +19,15 @@ import ( const MajorVersion = 1 func TestMinorVersionCompatibility(t *testing.T) { - if os.Getenv("E2E") == "" { + if os.Getenv("E2E") != "true" { t.Skip("skipping e2e test") } - if os.Getenv("E2E_VERSION") == "" { + if os.Getenv("E2E_VERSIONS") == "" { t.Skip("skipping e2e test: E2E_VERSION not set") } - versionStr := os.Getenv("E2E_VERSION") + versionStr := os.Getenv("E2E_VERSIONS") versions := ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates() numNodes := 4 r := rand.New(rand.NewSource(seed)) diff --git a/test/e2e/versions.go b/test/e2e/versions.go index b6600259c3..c829ac1c60 100644 --- a/test/e2e/versions.go +++ b/test/e2e/versions.go @@ -41,6 +41,12 @@ func (v Version) IsGreater(v2 Version) bool { if v.Patch < v2.Patch { return false } + if !v.IsRC && v2.IsRC { + return true + } + if v.IsRC && !v2.IsRC { + return false + } if v.RC > v2.RC { return true } diff --git a/test/e2e/versions_test.go b/test/e2e/versions_test.go index 17f66d3257..d6e20415ac 100644 --- a/test/e2e/versions_test.go +++ b/test/e2e/versions_test.go @@ -38,3 +38,12 @@ func TestOrder(t *testing.T) { require.True(t, versions[i].IsGreater(versions[i-1])) } } + +func TestOrderOfReleaseCandidates(t *testing.T) { + versionsStr := "v1.0.0\nv1.0.0-rc0\nv1.0.0-rc1\n" + versions := e2e.ParseVersions(versionsStr) + versions.Order() + require.Equal(t, versions[0], e2e.Version{1, 0, 0, true, 0}) + require.Equal(t, versions[1], e2e.Version{1, 0, 0, true, 1}) + require.Equal(t, versions[2], e2e.Version{1, 0, 0, false, 0}) +} From 93a42f9e55734d8037d25b1a2ded6c31451ae960 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 2 Nov 2023 17:07:48 +0100 Subject: [PATCH 06/26] Simplify IsGreater Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> --- test/e2e/versions.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/test/e2e/versions.go b/test/e2e/versions.go index c829ac1c60..d729ef1bd9 100644 --- a/test/e2e/versions.go +++ b/test/e2e/versions.go @@ -23,34 +23,19 @@ func (v Version) String() string { } func (v Version) IsGreater(v2 Version) bool { - if v.Major > v2.Major { - return true + if v.Major != v2.Major { + return v.Major > v2.Major } - if v.Major < v2.Major { - return false + if v.Minor != v2.Minor { + return v.Minor > v2.Minor } - if v.Minor > v2.Minor { - return true + if v.Patch != v2.Patch { + return v.Patch > v2.Patch } - if v.Minor < v2.Minor { - return false + if v.IsRC != v2.IsRC { + return !v.IsRC } - if v.Patch > v2.Patch { - return true - } - if v.Patch < v2.Patch { - return false - } - if !v.IsRC && v2.IsRC { - return true - } - if v.IsRC && !v2.IsRC { - return false - } - if v.RC > v2.RC { - return true - } - return false + return v.RC > v2.RC } type VersionSet []Version From f36db3ae2ed2adf02726d55aecd36259bb1f1bae Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 12:13:21 +0100 Subject: [PATCH 07/26] add assertions that the network progresses --- Makefile | 3 +- test/e2e/upgrade_test.go | 70 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fd83daf612..06a674d1cc 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,8 @@ test-short: @go test ./... -short -timeout 1m .PHONY: test-short -## test-e2e: Run end to end tests via knuu. +## test-e2e: Run end to end tests via knuu. This requires a kube/config file to configure the kubernetes. Without +## this, the test will not work test-e2e: @export E2E_VERSIONS=$(git tag -l) @echo "--> Running end to end tests" diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index 704e240095..cd6ae69ebd 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -3,6 +3,7 @@ package e2e import ( "context" "errors" + "fmt" "math/rand" "os" "testing" @@ -13,6 +14,7 @@ import ( "github.com/celestiaorg/celestia-app/test/txsim" "github.com/celestiaorg/knuu/pkg/knuu" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/rpc/client/http" ) // This will only run tests within the v1 major release cycle @@ -77,14 +79,78 @@ func TestMinorVersionCompatibility(t *testing.T) { if i%numNodes == 0 { continue } + client, err := testnet.Node(i % numNodes).Client() + require.NoError(t, err) + heightBefore, err := getHeight(ctx, client, time.Second) + require.NoError(t, err) newVersion := versions.Random(r).String() t.Log("Upgrading node", "node", i%numNodes, "version", newVersion) - err := testnet.Node(i % numNodes).Upgrade(newVersion) + err = testnet.Node(i % numNodes).Upgrade(newVersion) + require.NoError(t, err) + // wait for the node to reach two more heights + err = waitForHeight(ctx, client, heightBefore+2, 30*time.Second) + require.NoError(t, err) + } + + heights := make([]int64, 4) + for i := 0; i < numNodes; i++ { + client, err := testnet.Node(i).Client() + require.NoError(t, err) + heights[i], err = getHeight(ctx, client, time.Second) require.NoError(t, err) - time.Sleep(2 * time.Second) } + + const maxPermissableDiff = 2 + for i := 0; i < len(heights); i++ { + for j := i + 1; j < len(heights); j++ { + diff := heights[i] - heights[j] + if diff > maxPermissableDiff { + t.Fatalf("node %d is behind node %d by %d blocks", j, i, diff) + } + } + } + + // end the tx sim cancel() err = <-errCh require.True(t, errors.Is(err, context.Canceled), err.Error()) } + +func getHeight(ctx context.Context, client *http.HTTP, period time.Duration) (int64, error) { + timer := time.NewTimer(period) + ticker := time.NewTicker(100 * time.Millisecond) + for { + select { + case <-timer.C: + return 0, fmt.Errorf("failed to get height after %.2f seconds", period.Seconds()) + case <-ticker.C: + status, err := client.Status(ctx) + if err == nil { + return status.SyncInfo.LatestBlockHeight, nil + } + if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + return 0, err + } + } + } +} + +func waitForHeight(ctx context.Context, client *http.HTTP, height int64, period time.Duration) error { + timer := time.NewTimer(period) + ticker := time.NewTicker(100 * time.Millisecond) + for { + select { + case <-timer.C: + return fmt.Errorf("failed to reach height %d in %.2f seconds", height, period.Seconds()) + case <-ticker.C: + status, err := client.Status(ctx) + if err != nil { + return err + } + if status.SyncInfo.LatestBlockHeight >= height { + return nil + } + } + } +} From a4eb85d0c9a222f06b761015889cd8ac79ac96b2 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 14:36:09 +0100 Subject: [PATCH 08/26] Apply suggestions from code review Co-authored-by: Rootul P --- Makefile | 3 +-- test/e2e/upgrade_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 06a674d1cc..58b683d0d1 100644 --- a/Makefile +++ b/Makefile @@ -115,8 +115,7 @@ test-short: @go test ./... -short -timeout 1m .PHONY: test-short -## test-e2e: Run end to end tests via knuu. This requires a kube/config file to configure the kubernetes. Without -## this, the test will not work +## test-e2e: Run end to end tests via knuu. This command requires a kube/config file to configure kubernetes. test-e2e: @export E2E_VERSIONS=$(git tag -l) @echo "--> Running end to end tests" diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index cd6ae69ebd..899c4f8a7a 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -26,7 +26,7 @@ func TestMinorVersionCompatibility(t *testing.T) { } if os.Getenv("E2E_VERSIONS") == "" { - t.Skip("skipping e2e test: E2E_VERSION not set") + t.Skip("skipping e2e test: E2E_VERSIONS not set") } versionStr := os.Getenv("E2E_VERSIONS") From 59c3b5dc4c40dd22780e2a67c998e78788a7c6fc Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 15:13:17 +0100 Subject: [PATCH 09/26] fix parsing e2e_version env --- Makefile | 4 ++-- test/e2e/simple_test.go | 5 ++++- test/e2e/upgrade_test.go | 3 +++ test/e2e/versions.go | 5 ++++- test/e2e/versions_test.go | 8 ++++---- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 58b683d0d1..830850c782 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ VERSION := $(shell echo $(shell git describe --tags 2>/dev/null || git log -1 --format='%h') | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') DOCKER := $(shell which docker) +ALL_VERSIONS := $(shell git tag -l) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf IMAGE := ghcr.io/tendermint/docker-build-proto:latest DOCKER_PROTO_BUILDER := docker run -v $(shell pwd):/workspace --workdir /workspace $(IMAGE) @@ -117,9 +118,8 @@ test-short: ## test-e2e: Run end to end tests via knuu. This command requires a kube/config file to configure kubernetes. test-e2e: - @export E2E_VERSIONS=$(git tag -l) @echo "--> Running end to end tests" - @KNUU_NAMESPACE=test E2E=true go test ./test/e2e/... -timeout 10m -v + @KNUU_NAMESPACE=test E2E_VERSIONS="$(ALL_VERSIONS)" E2E=true go test ./test/e2e/... -timeout 10m -v .PHONY: test-e2e ## test-race: Run tests in race mode. diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index c632265c10..1c7f133781 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -22,6 +22,7 @@ var latestVersion = "latest" // and MsgSends over 30 seconds and then asserts that at least 10 transactions were // committed. func TestE2ESimple(t *testing.T) { + t.Skip() if os.Getenv("E2E") != "true" { t.Skip("skipping e2e test") } @@ -29,7 +30,9 @@ func TestE2ESimple(t *testing.T) { if os.Getenv("E2E_VERSIONS") != "" { versionsStr := os.Getenv("E2E_VERSIONS") versions := ParseVersions(versionsStr) - latestVersion = versions.GetLatest().String() + if len(versions) > 0 { + latestVersion = versions.GetLatest().String() + } } t.Log("Running simple e2e test", "version", latestVersion) diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index 899c4f8a7a..a9d7a36881 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -31,6 +31,9 @@ func TestMinorVersionCompatibility(t *testing.T) { versionStr := os.Getenv("E2E_VERSIONS") versions := ParseVersions(versionStr).FilterMajor(MajorVersion).FilterOutReleaseCandidates() + if len(versions) == 0 { + t.Skip("skipping e2e test: no versions to test") + } numNodes := 4 r := rand.New(rand.NewSource(seed)) t.Log("Running minor version compatibility test", "versions", versions) diff --git a/test/e2e/versions.go b/test/e2e/versions.go index d729ef1bd9..4d3329a2c8 100644 --- a/test/e2e/versions.go +++ b/test/e2e/versions.go @@ -41,7 +41,7 @@ func (v Version) IsGreater(v2 Version) bool { type VersionSet []Version func ParseVersions(versionStr string) VersionSet { - versions := strings.Split(versionStr, "\n") + versions := strings.Split(versionStr, " ") output := make(VersionSet, 0, len(versions)) for _, v := range versions { var major, minor, patch, rc uint64 @@ -101,6 +101,9 @@ func (v VersionSet) Order() { } func (v VersionSet) Random(r *rand.Rand) Version { + if len(v) == 0 { + panic("there are no versions to pick from") + } return v[r.Intn(len(v))] } diff --git a/test/e2e/versions_test.go b/test/e2e/versions_test.go index d6e20415ac..428b53bac8 100644 --- a/test/e2e/versions_test.go +++ b/test/e2e/versions_test.go @@ -8,7 +8,7 @@ import ( ) func TestVersionParsing(t *testing.T) { - versionStr := "v1.3.0\nv1.1.0\nv1.2.0-rc0" + versionStr := "v1.3.0 v1.1.0 v1.2.0-rc0" versions := e2e.ParseVersions(versionStr) require.Len(t, versions, 3) require.Len(t, versions.FilterOutReleaseCandidates(), 2) @@ -17,7 +17,7 @@ func TestVersionParsing(t *testing.T) { // Test case with multiple major versions and filtering out a single major version func TestFilterMajorVersions(t *testing.T) { - versionStr := "v2.0.0\nv1.1.0\nv2.1.0-rc0\nv1.2.0\nv2.2.0\nv1.3.0" + versionStr := "v2.0.0 v1.1.0 v2.1.0-rc0 v1.2.0 v2.2.0 v1.3.0" versions := e2e.ParseVersions(versionStr) require.Len(t, versions, 6) require.Len(t, versions.FilterMajor(1), 3) @@ -25,7 +25,7 @@ func TestFilterMajorVersions(t *testing.T) { // Test case to check the Order function func TestOrder(t *testing.T) { - versionStr := "v1.3.0\nv1.1.0\nv1.2.0-rc0\nv1.4.0\nv1.2.1\nv2.0.0" + versionStr := "v1.3.0 v1.1.0 v1.2.0-rc0 v1.4.0 v1.2.1 v2.0.0" versions := e2e.ParseVersions(versionStr) versions.Order() require.Equal(t, versions[0], e2e.Version{1, 1, 0, false, 0}) @@ -40,7 +40,7 @@ func TestOrder(t *testing.T) { } func TestOrderOfReleaseCandidates(t *testing.T) { - versionsStr := "v1.0.0\nv1.0.0-rc0\nv1.0.0-rc1\n" + versionsStr := "v1.0.0 v1.0.0-rc0 v1.0.0-rc1 " versions := e2e.ParseVersions(versionsStr) versions.Order() require.Equal(t, versions[0], e2e.Version{1, 0, 0, true, 0}) From cfcfa5c9758dc9d7a332a9dfa3cd393e89914374 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 15:20:19 +0100 Subject: [PATCH 10/26] set global knuu timeout --- Makefile | 2 +- test/e2e/simple_test.go | 1 - test/e2e/upgrade_test.go | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 830850c782..918a1e639e 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ test-short: ## test-e2e: Run end to end tests via knuu. This command requires a kube/config file to configure kubernetes. test-e2e: @echo "--> Running end to end tests" - @KNUU_NAMESPACE=test E2E_VERSIONS="$(ALL_VERSIONS)" E2E=true go test ./test/e2e/... -timeout 10m -v + @KNUU_NAMESPACE=test KNUU_TIMEOUT=20m E2E_VERSIONS="$(ALL_VERSIONS)" E2E=true go test ./test/e2e/... -timeout 20m -v .PHONY: test-e2e ## test-race: Run tests in race mode. diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index 1c7f133781..76ad15b479 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -22,7 +22,6 @@ var latestVersion = "latest" // and MsgSends over 30 seconds and then asserts that at least 10 transactions were // committed. func TestE2ESimple(t *testing.T) { - t.Skip() if os.Getenv("E2E") != "true" { t.Skip("skipping e2e test") } diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index a9d7a36881..d025a65aa9 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -103,6 +103,7 @@ func TestMinorVersionCompatibility(t *testing.T) { require.NoError(t, err) } + t.Log("checking that all nodes are at the same height") const maxPermissableDiff = 2 for i := 0; i < len(heights); i++ { for j := i + 1; j < len(heights); j++ { From 4aa82eac02b1bd4b894e77a32e736e50eda0daf9 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 15:35:37 +0100 Subject: [PATCH 11/26] Update test/e2e/versions_test.go Co-authored-by: Rootul P --- test/e2e/versions_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/versions_test.go b/test/e2e/versions_test.go index 428b53bac8..41d87efe77 100644 --- a/test/e2e/versions_test.go +++ b/test/e2e/versions_test.go @@ -40,7 +40,7 @@ func TestOrder(t *testing.T) { } func TestOrderOfReleaseCandidates(t *testing.T) { - versionsStr := "v1.0.0 v1.0.0-rc0 v1.0.0-rc1 " + versionsStr := "v1.0.0 v1.0.0-rc0 v1.0.0-rc1" versions := e2e.ParseVersions(versionsStr) versions.Order() require.Equal(t, versions[0], e2e.Version{1, 0, 0, true, 0}) From 9e2ebabf5dbdf3f485483b4886a8edf7890c03a7 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 6 Nov 2023 15:56:50 +0100 Subject: [PATCH 12/26] add go doc to upgrade --- app/app.go | 4 ++++ cmd/celestia-appd/cmd/root.go | 4 ++-- test/e2e/simple_test.go | 2 +- test/e2e/upgrade_test.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index b7b93f9ace..1e6d312d2a 100644 --- a/app/app.go +++ b/app/app.go @@ -240,6 +240,10 @@ type App struct { } // New returns a reference to an initialized celestia app. +// +// NOTE: upgradeHeight refers specifically to the height that +// a node will upgrade from v1 to v2. It will be deprecated in v3 +// in place for a dynamically signalling scheme func New( logger log.Logger, db dbm.DB, diff --git a/cmd/celestia-appd/cmd/root.go b/cmd/celestia-appd/cmd/root.go index 6037c3347e..a060d5e316 100644 --- a/cmd/celestia-appd/cmd/root.go +++ b/cmd/celestia-appd/cmd/root.go @@ -46,7 +46,7 @@ const ( // FlagLogToFile specifies whether to log to file or not. FlagLogToFile = "log-to-file" - UpgradeHeightFlag = "upgrade-height" + UpgradeHeightFlag = "v2-upgrade-height" ) // NewRootCmd creates a new root command for celestia-appd. It is called once in the @@ -156,7 +156,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig encoding.Config) { func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) - startCmd.Flags().Int64(UpgradeHeightFlag, 0, "Upgrade height to switch to v2. Must be coordinated amongst all validators") + startCmd.Flags().Int64(UpgradeHeightFlag, 0, "Upgrade height to switch from v1 to v2. Must be coordinated amongst all validators") } func queryCommand() *cobra.Command { diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index 76ad15b479..0843e1e1ba 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -52,7 +52,7 @@ func TestE2ESimple(t *testing.T) { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() - opts := txsim.DefaultOptions().WithSeed(seed) + opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs() err = txsim.Run(ctx, testnet.GRPCEndpoints()[0], kr, encCfg, opts, sequences...) require.True(t, errors.Is(err, context.DeadlineExceeded), err.Error()) diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index d025a65aa9..ebbc7d3c1f 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -69,7 +69,7 @@ func TestMinorVersionCompatibility(t *testing.T) { errCh := make(chan error) encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - opts := txsim.DefaultOptions().WithSeed(seed) + opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs() ctx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { From e36e241e5aa031a2ef263a1d2d9ba0f82399adab Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 9 Nov 2023 09:35:59 +0100 Subject: [PATCH 13/26] define upgrade protos --- proto/celestia/upgrade/v1/params.proto | 11 + proto/celestia/upgrade/v1/query.proto | 36 + proto/celestia/upgrade/v1/tx.proto | 24 + proto/celestia/upgrade/v1/types.proto | 10 - x/upgrade/params.pb.go | 301 +++++++++ x/upgrade/query.pb.go | 893 +++++++++++++++++++++++++ x/upgrade/query.pb.gw.go | 236 +++++++ x/upgrade/tx.pb.go | 567 ++++++++++++++++ x/upgrade/tx.pb.gw.go | 171 +++++ 9 files changed, 2239 insertions(+), 10 deletions(-) create mode 100644 proto/celestia/upgrade/v1/params.proto create mode 100644 proto/celestia/upgrade/v1/query.proto create mode 100644 proto/celestia/upgrade/v1/tx.proto delete mode 100644 proto/celestia/upgrade/v1/types.proto create mode 100644 x/upgrade/params.pb.go create mode 100644 x/upgrade/query.pb.go create mode 100644 x/upgrade/query.pb.gw.go create mode 100644 x/upgrade/tx.pb.go create mode 100644 x/upgrade/tx.pb.gw.go diff --git a/proto/celestia/upgrade/v1/params.proto b/proto/celestia/upgrade/v1/params.proto new file mode 100644 index 0000000000..86159c812c --- /dev/null +++ b/proto/celestia/upgrade/v1/params.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package celestia.upgrade.v1; + +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; + +// Params defines the parameters for the upgrade module. +message Params { + // Quorum represents the minimum voting power for an upgrade to go through. + // It must be at least 2/3. + uint64 quorum = 1; +} diff --git a/proto/celestia/upgrade/v1/query.proto b/proto/celestia/upgrade/v1/query.proto new file mode 100644 index 0000000000..5ce38f3934 --- /dev/null +++ b/proto/celestia/upgrade/v1/query.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; +package celestia.blob.v1; + +import "google/api/annotations.proto"; +import "celestia/blob/v1/params.proto"; + +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; + +// Query defines the upgrade Query service. +service Query { + // Params allows the querying of the params + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/upgrade/v1/params"; + } + + // UpgradeStatus allows the querying of the tally of voting power by all + // validators that have signalled for each version + rpc UpgradeStatus(QueryUpgradeStatusRequest) + returns (QueryUpgradeStatusResponse) { + option (google.api.http).get = "/upgrade/v1/status"; + } +} + +// QueryParamsRequest is the request type for the Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Params RPC method. +message QueryParamsResponse { Params params = 1; } + +// QueryUpgradeStatusRequest is the request type for the UpgradeStatus RPC +// method. +message QueryUpgradeStatusRequest { uint64 version = 1; } + +// QueryUpgradeStatusResponse is the response type for the UpgradeStatus RPC +// method. +message QueryUpgradeStatusResponse { uint64 voting_power = 1; } diff --git a/proto/celestia/upgrade/v1/tx.proto b/proto/celestia/upgrade/v1/tx.proto new file mode 100644 index 0000000000..5adb255c3e --- /dev/null +++ b/proto/celestia/upgrade/v1/tx.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; +package celestia.upgrade.v1; + +import "google/api/annotations.proto"; + +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; + +// Msg defines the upgrade Msg service. +service Msg { + // SignalUpgrade allows the validator to signal for an upgrade + rpc SignalUpgrade(MsgSignalUpgrade) returns (MsgSignalUpgradeResponse) { + option (google.api.http).get = "/upgrade/v1/signal"; + } +} + +// MsgSignalUpgrade signals for an upgrade +message MsgSignalUpgrade { + string validator_address = 1; + uint64 version = 2; +} + +// MsgSignalUpgradeResponse describes the response returned after the submission +// of a SignalUpgrade +message MsgSignalUpgradeResponse {} diff --git a/proto/celestia/upgrade/v1/types.proto b/proto/celestia/upgrade/v1/types.proto deleted file mode 100644 index cee2591479..0000000000 --- a/proto/celestia/upgrade/v1/types.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package celestia.upgrade.v1; - -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; - -// MsgVersionChange is a message that signals an app version change -message MsgVersionChange { - // the app version this message proposes upgrading to - uint64 version = 1; -} diff --git a/x/upgrade/params.pb.go b/x/upgrade/params.pb.go new file mode 100644 index 0000000000..c63afae38f --- /dev/null +++ b/x/upgrade/params.pb.go @@ -0,0 +1,301 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: celestia/upgrade/v1/params.proto + +package upgrade + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/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 + +// Params defines the parameters for the upgrade module. +type Params struct { + // Quorum represents the minimum voting power for an upgrade to go through. + // It must be at least 2/3. + Quorum uint64 `protobuf:"varint,1,opt,name=quorum,proto3" json:"quorum,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_b4f657414f35d610, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetQuorum() uint64 { + if m != nil { + return m.Quorum + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "celestia.upgrade.v1.Params") +} + +func init() { proto.RegisterFile("celestia/upgrade/v1/params.proto", fileDescriptor_b4f657414f35d610) } + +var fileDescriptor_b4f657414f35d610 = []byte{ + // 155 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, + 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, + 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa9, + 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x54, 0x52, 0xe0, 0x62, 0x0b, 0x00, 0x2b, 0x12, 0x12, 0xe3, + 0x62, 0x2b, 0x2c, 0xcd, 0x2f, 0x2a, 0xcd, 0x95, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x09, 0x82, 0xf2, + 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x66, 0x76, 0x7e, 0x51, 0x3a, 0x9c, 0xad, + 0x9b, 0x58, 0x50, 0xa0, 0x5f, 0x01, 0x73, 0x4f, 0x12, 0x1b, 0xd8, 0x19, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xc2, 0x56, 0x00, 0xb6, 0xaa, 0x00, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Quorum != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.Quorum)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Quorum != 0 { + n += 1 + sovParams(uint64(m.Quorum)) + } + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Quorum", wireType) + } + m.Quorum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Quorum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrIntOverflowParams + } + 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, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/upgrade/query.pb.go b/x/upgrade/query.pb.go new file mode 100644 index 0000000000..4694da54d6 --- /dev/null +++ b/x/upgrade/query.pb.go @@ -0,0 +1,893 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: celestia/upgrade/v1/query.proto + +package upgrade + +import ( + context "context" + fmt "fmt" + types "github.com/celestiaorg/celestia-app/x/blob/types" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// QueryParamsRequest is the request type for the Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7dd2290b21d03efa, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Params RPC method. +type QueryParamsResponse struct { + Params *types.Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7dd2290b21d03efa, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *types.Params { + if m != nil { + return m.Params + } + return nil +} + +// QueryUpgradeStatusRequest is the request type for the UpgradeStatus RPC method. +type QueryUpgradeStatusRequest struct { + Version uint64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` +} + +func (m *QueryUpgradeStatusRequest) Reset() { *m = QueryUpgradeStatusRequest{} } +func (m *QueryUpgradeStatusRequest) String() string { return proto.CompactTextString(m) } +func (*QueryUpgradeStatusRequest) ProtoMessage() {} +func (*QueryUpgradeStatusRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_7dd2290b21d03efa, []int{2} +} +func (m *QueryUpgradeStatusRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUpgradeStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUpgradeStatusRequest.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 *QueryUpgradeStatusRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUpgradeStatusRequest.Merge(m, src) +} +func (m *QueryUpgradeStatusRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryUpgradeStatusRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUpgradeStatusRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUpgradeStatusRequest proto.InternalMessageInfo + +func (m *QueryUpgradeStatusRequest) GetVersion() uint64 { + if m != nil { + return m.Version + } + return 0 +} + +// QueryUpgradeStatusResponse is the response type for the UpgradeStatus RPC method. +type QueryUpgradeStatusResponse struct { + VotingPower uint64 `protobuf:"varint,1,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` +} + +func (m *QueryUpgradeStatusResponse) Reset() { *m = QueryUpgradeStatusResponse{} } +func (m *QueryUpgradeStatusResponse) String() string { return proto.CompactTextString(m) } +func (*QueryUpgradeStatusResponse) ProtoMessage() {} +func (*QueryUpgradeStatusResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7dd2290b21d03efa, []int{3} +} +func (m *QueryUpgradeStatusResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryUpgradeStatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryUpgradeStatusResponse.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 *QueryUpgradeStatusResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryUpgradeStatusResponse.Merge(m, src) +} +func (m *QueryUpgradeStatusResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryUpgradeStatusResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryUpgradeStatusResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryUpgradeStatusResponse proto.InternalMessageInfo + +func (m *QueryUpgradeStatusResponse) GetVotingPower() uint64 { + if m != nil { + return m.VotingPower + } + return 0 +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "celestia.blob.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "celestia.blob.v1.QueryParamsResponse") + proto.RegisterType((*QueryUpgradeStatusRequest)(nil), "celestia.blob.v1.QueryUpgradeStatusRequest") + proto.RegisterType((*QueryUpgradeStatusResponse)(nil), "celestia.blob.v1.QueryUpgradeStatusResponse") +} + +func init() { proto.RegisterFile("celestia/upgrade/v1/query.proto", fileDescriptor_7dd2290b21d03efa) } + +var fileDescriptor_7dd2290b21d03efa = []byte{ + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x4b, 0xc3, 0x30, + 0x18, 0xc6, 0xd7, 0xa1, 0x13, 0x32, 0x05, 0x89, 0x3b, 0xcc, 0xa2, 0x55, 0x8b, 0x82, 0xa0, 0x6b, + 0xdc, 0xc4, 0xb3, 0xe0, 0x65, 0xd7, 0x39, 0xf1, 0xe2, 0x45, 0xd2, 0x19, 0x6a, 0x61, 0xeb, 0x9b, + 0x25, 0x69, 0xd5, 0xab, 0x82, 0x67, 0xc1, 0x2f, 0xe5, 0x71, 0xe0, 0xc5, 0xa3, 0x6c, 0x7e, 0x10, + 0x69, 0xd2, 0x0e, 0xe7, 0xe6, 0x9f, 0x5b, 0xfb, 0xf4, 0x79, 0x7e, 0xef, 0xf3, 0x36, 0x41, 0x1b, + 0x1d, 0xd6, 0x65, 0x52, 0x85, 0x94, 0xc4, 0x3c, 0x10, 0xf4, 0x8a, 0x91, 0xa4, 0x4e, 0xfa, 0x31, + 0x13, 0x77, 0x1e, 0x17, 0xa0, 0x00, 0x2f, 0xe7, 0x06, 0xcf, 0xef, 0x82, 0xef, 0x25, 0x75, 0x7b, + 0x2d, 0x00, 0x08, 0xba, 0x8c, 0x50, 0x1e, 0x12, 0x1a, 0x45, 0xa0, 0xa8, 0x0a, 0x21, 0x92, 0xc6, + 0x6f, 0xaf, 0x8f, 0x81, 0xa9, 0x3f, 0xa5, 0x71, 0x2a, 0x68, 0x2f, 0xfb, 0xec, 0x56, 0x10, 0x3e, + 0x4d, 0xe9, 0x2d, 0x2d, 0xb6, 0x59, 0x3f, 0x66, 0x52, 0xb9, 0x4d, 0xb4, 0x32, 0xa1, 0x4a, 0x0e, + 0x91, 0x64, 0xf8, 0x00, 0x95, 0x4c, 0xb8, 0x6a, 0x6d, 0x5a, 0xbb, 0xe5, 0x46, 0xd5, 0xfb, 0x5e, + 0xc6, 0xcb, 0x12, 0x99, 0xcf, 0x3d, 0x42, 0xab, 0x1a, 0x74, 0x6e, 0x96, 0x39, 0x53, 0x54, 0xc5, + 0xf9, 0x14, 0x5c, 0x45, 0x0b, 0x09, 0x13, 0x32, 0x84, 0x48, 0xf3, 0xe6, 0xda, 0xf9, 0xab, 0x7b, + 0x8c, 0xec, 0x59, 0xb1, 0xac, 0xc6, 0x16, 0x5a, 0x4c, 0x40, 0x85, 0x51, 0x70, 0xc9, 0xe1, 0x86, + 0x89, 0x2c, 0x5c, 0x36, 0x5a, 0x2b, 0x95, 0x1a, 0x0f, 0x45, 0x34, 0xaf, 0x09, 0xb8, 0x8f, 0x4a, + 0xa6, 0x13, 0xde, 0x9e, 0x6e, 0x3b, 0xbd, 0xba, 0xbd, 0xf3, 0x87, 0xcb, 0x74, 0x70, 0xed, 0xfb, + 0xd7, 0x8f, 0xe7, 0x62, 0x05, 0xe3, 0xaf, 0xe7, 0x64, 0x96, 0xc6, 0x8f, 0x16, 0x5a, 0x9a, 0x68, + 0x8e, 0xf7, 0x7e, 0x80, 0xce, 0xfa, 0x2d, 0xf6, 0xfe, 0xff, 0xcc, 0xbf, 0x15, 0x91, 0xda, 0x73, + 0xd2, 0x7c, 0x19, 0x3a, 0xd6, 0x60, 0xe8, 0x58, 0xef, 0x43, 0xc7, 0x7a, 0x1a, 0x39, 0x85, 0xc1, + 0xc8, 0x29, 0xbc, 0x8d, 0x9c, 0xc2, 0x45, 0x2d, 0x08, 0xd5, 0x75, 0xec, 0x7b, 0x1d, 0xe8, 0x91, + 0x7c, 0x1a, 0x88, 0x60, 0xfc, 0x5c, 0xa3, 0x9c, 0x93, 0xdb, 0x1c, 0xe9, 0x97, 0xf4, 0x65, 0x39, + 0xfc, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x3a, 0x92, 0x35, 0x59, 0x9e, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params allows the querying of the params + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // UpgradeStatus allows the querying of the tally of voting power by all validators that have signalled for each version + UpgradeStatus(ctx context.Context, in *QueryUpgradeStatusRequest, opts ...grpc.CallOption) (*QueryUpgradeStatusResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/celestia.blob.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) UpgradeStatus(ctx context.Context, in *QueryUpgradeStatusRequest, opts ...grpc.CallOption) (*QueryUpgradeStatusResponse, error) { + out := new(QueryUpgradeStatusResponse) + err := c.cc.Invoke(ctx, "/celestia.blob.v1.Query/UpgradeStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params allows the querying of the params + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // UpgradeStatus allows the querying of the tally of voting power by all validators that have signalled for each version + UpgradeStatus(context.Context, *QueryUpgradeStatusRequest) (*QueryUpgradeStatusResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) UpgradeStatus(ctx context.Context, req *QueryUpgradeStatusRequest) (*QueryUpgradeStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpgradeStatus not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/celestia.blob.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_UpgradeStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryUpgradeStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).UpgradeStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/celestia.blob.v1.Query/UpgradeStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).UpgradeStatus(ctx, req.(*QueryUpgradeStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "celestia.blob.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "UpgradeStatus", + Handler: _Query_UpgradeStatus_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "celestia/upgrade/v1/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Params != nil { + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryUpgradeStatusRequest) 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 *QueryUpgradeStatusRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUpgradeStatusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Version != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Version)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryUpgradeStatusResponse) 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 *QueryUpgradeStatusResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryUpgradeStatusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.VotingPower != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.VotingPower)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryUpgradeStatusRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Version != 0 { + n += 1 + sovQuery(uint64(m.Version)) + } + return n +} + +func (m *QueryUpgradeStatusResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.VotingPower != 0 { + n += 1 + sovQuery(uint64(m.VotingPower)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Params == nil { + m.Params = &types.Params{} + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUpgradeStatusRequest) 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 ErrIntOverflowQuery + } + 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: QueryUpgradeStatusRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUpgradeStatusRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + m.Version = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Version |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryUpgradeStatusResponse) 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 ErrIntOverflowQuery + } + 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: QueryUpgradeStatusResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryUpgradeStatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) + } + m.VotingPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotingPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrIntOverflowQuery + } + 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, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/upgrade/query.pb.gw.go b/x/upgrade/query.pb.gw.go new file mode 100644 index 0000000000..9520f7c98e --- /dev/null +++ b/x/upgrade/query.pb.gw.go @@ -0,0 +1,236 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: celestia/upgrade/v1/query.proto + +/* +Package upgrade is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package upgrade + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_UpgradeStatus_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_UpgradeStatus_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUpgradeStatusRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_UpgradeStatus_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.UpgradeStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_UpgradeStatus_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryUpgradeStatusRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_UpgradeStatus_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.UpgradeStatus(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UpgradeStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_UpgradeStatus_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UpgradeStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_UpgradeStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_UpgradeStatus_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_UpgradeStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_UpgradeStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "status"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_UpgradeStatus_0 = runtime.ForwardResponseMessage +) diff --git a/x/upgrade/tx.pb.go b/x/upgrade/tx.pb.go new file mode 100644 index 0000000000..e74d2ae6dc --- /dev/null +++ b/x/upgrade/tx.pb.go @@ -0,0 +1,567 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: celestia/upgrade/v1/tx.proto + +package upgrade + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 + +// MsgSignalUpgrade signals for an upgrade +type MsgSignalUpgrade struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` +} + +func (m *MsgSignalUpgrade) Reset() { *m = MsgSignalUpgrade{} } +func (m *MsgSignalUpgrade) String() string { return proto.CompactTextString(m) } +func (*MsgSignalUpgrade) ProtoMessage() {} +func (*MsgSignalUpgrade) Descriptor() ([]byte, []int) { + return fileDescriptor_ee2a0c754324bd13, []int{0} +} +func (m *MsgSignalUpgrade) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSignalUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSignalUpgrade.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 *MsgSignalUpgrade) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSignalUpgrade.Merge(m, src) +} +func (m *MsgSignalUpgrade) XXX_Size() int { + return m.Size() +} +func (m *MsgSignalUpgrade) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSignalUpgrade.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSignalUpgrade proto.InternalMessageInfo + +func (m *MsgSignalUpgrade) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +func (m *MsgSignalUpgrade) GetVersion() uint64 { + if m != nil { + return m.Version + } + return 0 +} + +// MsgSignalUpgradeResponse describes the response returned after the submission +// of a SignalUpgrade +type MsgSignalUpgradeResponse struct { +} + +func (m *MsgSignalUpgradeResponse) Reset() { *m = MsgSignalUpgradeResponse{} } +func (m *MsgSignalUpgradeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSignalUpgradeResponse) ProtoMessage() {} +func (*MsgSignalUpgradeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ee2a0c754324bd13, []int{1} +} +func (m *MsgSignalUpgradeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSignalUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSignalUpgradeResponse.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 *MsgSignalUpgradeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSignalUpgradeResponse.Merge(m, src) +} +func (m *MsgSignalUpgradeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSignalUpgradeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSignalUpgradeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSignalUpgradeResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgSignalUpgrade)(nil), "celestia.upgrade.v1.MsgSignalUpgrade") + proto.RegisterType((*MsgSignalUpgradeResponse)(nil), "celestia.upgrade.v1.MsgSignalUpgradeResponse") +} + +func init() { proto.RegisterFile("celestia/upgrade/v1/tx.proto", fileDescriptor_ee2a0c754324bd13) } + +var fileDescriptor_ee2a0c754324bd13 = []byte{ + // 280 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x49, 0x4e, 0xcd, 0x49, + 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, + 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xc9, 0xea, 0x41, 0x65, 0xf5, + 0xca, 0x0c, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, + 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0x5a, 0x94, 0x22, 0xb9, 0x04, + 0x7c, 0x8b, 0xd3, 0x83, 0x33, 0xd3, 0xf3, 0x12, 0x73, 0x42, 0x21, 0x9a, 0x84, 0xb4, 0xb9, 0x04, + 0xcb, 0x12, 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, 0x8b, 0xe2, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, + 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x04, 0xe0, 0x12, 0x8e, 0x10, 0x71, 0x21, 0x09, + 0x2e, 0xf6, 0xb2, 0xd4, 0xa2, 0xe2, 0xcc, 0xfc, 0x3c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x96, 0x20, + 0x18, 0x57, 0x49, 0x8a, 0x4b, 0x02, 0xdd, 0xe8, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, + 0xa3, 0x4e, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x46, 0x46, 0x2e, 0x5e, 0x54, 0xcb, 0x55, + 0xf5, 0xb0, 0x78, 0x42, 0x0f, 0xdd, 0x20, 0x29, 0x5d, 0xa2, 0x94, 0xc1, 0xec, 0x53, 0x92, 0x6a, + 0xba, 0xfc, 0x64, 0x32, 0x93, 0x88, 0x90, 0x10, 0x72, 0xb8, 0x15, 0x83, 0x95, 0x3a, 0xb9, 0x9f, + 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, 0x6e, 0x7a, 0x66, 0x49, 0x46, 0x69, + 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xcc, 0xba, 0xfc, 0xa2, 0x74, 0x38, 0x5b, 0x37, 0xb1, 0xa0, + 0x40, 0xbf, 0x02, 0x66, 0x64, 0x12, 0x1b, 0x38, 0x48, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, + 0xb9, 0x4f, 0xa1, 0xbc, 0xa5, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // SignalUpgrade allows the validator to signal for an upgrade + SignalUpgrade(ctx context.Context, in *MsgSignalUpgrade, opts ...grpc.CallOption) (*MsgSignalUpgradeResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) SignalUpgrade(ctx context.Context, in *MsgSignalUpgrade, opts ...grpc.CallOption) (*MsgSignalUpgradeResponse, error) { + out := new(MsgSignalUpgradeResponse) + err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Msg/SignalUpgrade", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // SignalUpgrade allows the validator to signal for an upgrade + SignalUpgrade(context.Context, *MsgSignalUpgrade) (*MsgSignalUpgradeResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) SignalUpgrade(ctx context.Context, req *MsgSignalUpgrade) (*MsgSignalUpgradeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SignalUpgrade not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_SignalUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSignalUpgrade) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SignalUpgrade(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/celestia.upgrade.v1.Msg/SignalUpgrade", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SignalUpgrade(ctx, req.(*MsgSignalUpgrade)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "celestia.upgrade.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SignalUpgrade", + Handler: _Msg_SignalUpgrade_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "celestia/upgrade/v1/tx.proto", +} + +func (m *MsgSignalUpgrade) 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 *MsgSignalUpgrade) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSignalUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Version != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Version)) + i-- + dAtA[i] = 0x10 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSignalUpgradeResponse) 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 *MsgSignalUpgradeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSignalUpgradeResponse) 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 + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgSignalUpgrade) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Version != 0 { + n += 1 + sovTx(uint64(m.Version)) + } + return n +} + +func (m *MsgSignalUpgradeResponse) 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 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgSignalUpgrade) 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: MsgSignalUpgrade: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSignalUpgrade: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", 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.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + m.Version = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Version |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *MsgSignalUpgradeResponse) 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: MsgSignalUpgradeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSignalUpgradeResponse: 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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/upgrade/tx.pb.gw.go b/x/upgrade/tx.pb.gw.go new file mode 100644 index 0000000000..1d7b9b3a3f --- /dev/null +++ b/x/upgrade/tx.pb.gw.go @@ -0,0 +1,171 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: celestia/upgrade/v1/tx.proto + +/* +Package upgrade is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package upgrade + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Msg_SignalUpgrade_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Msg_SignalUpgrade_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSignalUpgrade + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalUpgrade_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.SignalUpgrade(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Msg_SignalUpgrade_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSignalUpgrade + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalUpgrade_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.SignalUpgrade(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterMsgHandlerServer registers the http handlers for service Msg to "mux". +// UnaryRPC :call MsgServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. +func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { + + mux.Handle("GET", pattern_Msg_SignalUpgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Msg_SignalUpgrade_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_SignalUpgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterMsgHandlerFromEndpoint is same as RegisterMsgHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterMsgHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterMsgHandler(ctx, mux, conn) +} + +// RegisterMsgHandler registers the http handlers for service Msg to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterMsgHandlerClient(ctx, mux, NewMsgClient(conn)) +} + +// RegisterMsgHandlerClient registers the http handlers for service Msg +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MsgClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MsgClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "MsgClient" to call the correct interceptors. +func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { + + mux.Handle("GET", pattern_Msg_SignalUpgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Msg_SignalUpgrade_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Msg_SignalUpgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Msg_SignalUpgrade_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "signal"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Msg_SignalUpgrade_0 = runtime.ForwardResponseMessage +) From 136542188a742b154920ec93c2afbca8b9a657cf Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 9 Nov 2023 15:32:01 +0100 Subject: [PATCH 14/26] write out a large chunk of the logic --- app/app.go | 32 ++- proto/celestia/upgrade/v1/params.proto | 8 +- proto/celestia/upgrade/v1/query.proto | 25 +- proto/celestia/upgrade/v1/tx.proto | 16 +- x/upgrade/ibc.go | 72 ++++++ x/upgrade/interfaces.go | 13 ++ x/upgrade/keeper.go | 203 ++++++++++++----- x/upgrade/module.go | 129 +++++++++++ x/upgrade/params.go | 24 ++ x/upgrade/types.go | 65 ------ x/upgrade/types.pb.go | 301 ------------------------- x/upgrade/types/codec.go | 18 ++ x/upgrade/types/errors.go | 7 + x/upgrade/types/msgs.go | 38 ++++ x/upgrade/types/params.go | 51 +++++ x/upgrade/{ => types}/params.pb.go | 43 ++-- x/upgrade/{ => types}/query.pb.go | 236 +++++++++++-------- x/upgrade/{ => types}/query.pb.gw.go | 74 +++--- x/upgrade/{ => types}/tx.pb.go | 170 +++++++------- x/upgrade/{ => types}/tx.pb.gw.go | 38 ++-- 20 files changed, 861 insertions(+), 702 deletions(-) create mode 100644 x/upgrade/ibc.go create mode 100644 x/upgrade/interfaces.go create mode 100644 x/upgrade/module.go create mode 100644 x/upgrade/params.go delete mode 100644 x/upgrade/types.go delete mode 100644 x/upgrade/types.pb.go create mode 100644 x/upgrade/types/codec.go create mode 100644 x/upgrade/types/errors.go create mode 100644 x/upgrade/types/msgs.go create mode 100644 x/upgrade/types/params.go rename x/upgrade/{ => types}/params.pb.go (80%) rename x/upgrade/{ => types}/query.pb.go (66%) rename x/upgrade/{ => types}/query.pb.gw.go (74%) rename x/upgrade/{ => types}/tx.pb.go (62%) rename x/upgrade/{ => types}/tx.pb.gw.go (84%) diff --git a/app/app.go b/app/app.go index 1e6d312d2a..7bb42c5474 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,7 @@ import ( mintkeeper "github.com/celestiaorg/celestia-app/x/mint/keeper" minttypes "github.com/celestiaorg/celestia-app/x/mint/types" "github.com/celestiaorg/celestia-app/x/upgrade" + upgradetypes "github.com/celestiaorg/celestia-app/x/upgrade/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -85,6 +86,7 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" + v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/pkg/proof" blobmodule "github.com/celestiaorg/celestia-app/x/blob" @@ -155,11 +157,12 @@ var ( vesting.AppModuleBasic{}, blobmodule.AppModuleBasic{}, bsmodule.AppModuleBasic{}, + upgrade.AppModuleBasic{}, ) // ModuleEncodingRegisters keeps track of all the module methods needed to // register interfaces and specific type to encoding config - ModuleEncodingRegisters = extractRegisters(ModuleBasics, upgrade.TypeRegister{}) + ModuleEncodingRegisters = extractRegisters(ModuleBasics) // module account permissions maccPerms = map[string][]string{ @@ -267,7 +270,7 @@ func New( keys := sdk.NewKVStoreKeys( authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, upgrade.StoreKey, feegrant.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, blobmoduletypes.StoreKey, bsmoduletypes.StoreKey, @@ -333,7 +336,7 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], upgradeHeight) + app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], upgradeHeight, app.StakingKeeper, app.GetSubspace(upgradetypes.ModuleName)) app.BlobstreamKeeper = *bsmodulekeeper.NewKeeper( appCodec, @@ -468,7 +471,7 @@ func New( paramstypes.ModuleName, authz.ModuleName, vestingtypes.ModuleName, - upgrade.ModuleName, + upgradetypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -491,7 +494,7 @@ func New( paramstypes.ModuleName, authz.ModuleName, vestingtypes.ModuleName, - upgrade.ModuleName, + upgradetypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -519,7 +522,7 @@ func New( feegrant.ModuleName, paramstypes.ModuleName, authz.ModuleName, - upgrade.ModuleName, + upgradetypes.ModuleName, ) app.QueryRouter().AddRoute(proof.TxInclusionQueryPath, proof.QueryTxInclusionProof) @@ -573,10 +576,19 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker application updates every end block func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { res := app.mm.EndBlock(ctx, req) - // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected - // to be coordinated through the signalling protocol - if app.UpgradeKeeper.ShouldUpgrade(req.Height) { - app.SetProtocolVersion(v2.Version) + + // handle upgrade logic + switch ctx.BlockHeader().Version.App { + case v1.Version: + // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected + // to be coordinated through the signalling protocol + if app.UpgradeKeeper.ShouldUpgradeToV2(req.Height) { + app.SetProtocolVersion(v2.Version) + } + default: + if ready, version := app.UpgradeKeeper.ShouldUpgrade(); ready { + app.SetProtocolVersion(version) + } } return res } diff --git a/proto/celestia/upgrade/v1/params.proto b/proto/celestia/upgrade/v1/params.proto index 86159c812c..839ac2cd94 100644 --- a/proto/celestia/upgrade/v1/params.proto +++ b/proto/celestia/upgrade/v1/params.proto @@ -1,11 +1,11 @@ syntax = "proto3"; package celestia.upgrade.v1; -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; // Params defines the parameters for the upgrade module. message Params { - // Quorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. - uint64 quorum = 1; + // SignalQuorum represents the minimum voting power for an upgrade to go through. + // It must be at least 2/3. MaxUint32 would mean 100% of the voting power. + uint32 signal_quorum = 1; } diff --git a/proto/celestia/upgrade/v1/query.proto b/proto/celestia/upgrade/v1/query.proto index 5ce38f3934..cb34404653 100644 --- a/proto/celestia/upgrade/v1/query.proto +++ b/proto/celestia/upgrade/v1/query.proto @@ -1,10 +1,10 @@ syntax = "proto3"; -package celestia.blob.v1; +package celestia.upgrade.v1; import "google/api/annotations.proto"; -import "celestia/blob/v1/params.proto"; +import "celestia/upgrade/v1/params.proto"; -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; // Query defines the upgrade Query service. service Query { @@ -13,11 +13,11 @@ service Query { option (google.api.http).get = "/upgrade/v1/params"; } - // UpgradeStatus allows the querying of the tally of voting power by all + // VersionTally allows the querying of the tally of voting power by all // validators that have signalled for each version - rpc UpgradeStatus(QueryUpgradeStatusRequest) - returns (QueryUpgradeStatusResponse) { - option (google.api.http).get = "/upgrade/v1/status"; + rpc VersionTally(QueryVersionTallyRequest) + returns (QueryVersionTallyResponse) { + option (google.api.http).get = "/upgrade/v1/tally/{version}"; } } @@ -27,10 +27,13 @@ message QueryParamsRequest {} // QueryParamsResponse is the response type for the Params RPC method. message QueryParamsResponse { Params params = 1; } -// QueryUpgradeStatusRequest is the request type for the UpgradeStatus RPC +// QueryVersionTallyRequest is the request type for the UpgradeStatus RPC // method. -message QueryUpgradeStatusRequest { uint64 version = 1; } +message QueryVersionTallyRequest { uint64 version = 1; } -// QueryUpgradeStatusResponse is the response type for the UpgradeStatus RPC +// QueryVersionTallyResponse is the response type for the UpgradeStatus RPC // method. -message QueryUpgradeStatusResponse { uint64 voting_power = 1; } +message QueryVersionTallyResponse { + uint64 voting_power = 1; + uint64 total_voting_power = 2; +} diff --git a/proto/celestia/upgrade/v1/tx.proto b/proto/celestia/upgrade/v1/tx.proto index 5adb255c3e..be11d712e7 100644 --- a/proto/celestia/upgrade/v1/tx.proto +++ b/proto/celestia/upgrade/v1/tx.proto @@ -3,22 +3,22 @@ package celestia.upgrade.v1; import "google/api/annotations.proto"; -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade"; +option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; // Msg defines the upgrade Msg service. service Msg { - // SignalUpgrade allows the validator to signal for an upgrade - rpc SignalUpgrade(MsgSignalUpgrade) returns (MsgSignalUpgradeResponse) { + // SignalVersion allows the validator to signal for an upgrade + rpc SignalVersion(MsgSignalVersion) returns (MsgSignalVersionResponse) { option (google.api.http).get = "/upgrade/v1/signal"; } } -// MsgSignalUpgrade signals for an upgrade -message MsgSignalUpgrade { +// MsgSignalVersion signals for an upgrade +message MsgSignalVersion { string validator_address = 1; uint64 version = 2; } -// MsgSignalUpgradeResponse describes the response returned after the submission -// of a SignalUpgrade -message MsgSignalUpgradeResponse {} +// MsgSignalVersionResponse describes the response returned after the submission +// of a SignalVersion +message MsgSignalVersionResponse {} diff --git a/x/upgrade/ibc.go b/x/upgrade/ibc.go new file mode 100644 index 0000000000..dcfc1ce799 --- /dev/null +++ b/x/upgrade/ibc.go @@ -0,0 +1,72 @@ +package upgrade + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ibctypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" +) + +// We need compatibility with the way that IBC uses the upgrade module. This file +// ensures that we comply to the interface that IBC expects +var _ ibctypes.UpgradeKeeper = (*Keeper)(nil) + +// ScheduleUpgrade implements the ibc upgrade keeper interface. This is a noop as +// no other process is allowed to schedule an upgrade but the upgrade keeper itself. +// This is kept around to support the interface. +func (k Keeper) ScheduleUpgrade(_ sdk.Context, _ types.Plan) error { + return nil +} + +// GetUpgradePlan implements the ibc upgrade keeper interface. This is used in BeginBlock +// to know when to write the upgraded consensus state. The IBC module needs to sign over +// the next consensus state to ensure a smooth transition for counterparty chains. This +// is implemented as a noop. Any IBC breaking change would be invoked by this upgrade module +// in end blocker. +func (k Keeper) GetUpgradePlan(_ sdk.Context) (plan types.Plan, havePlan bool) { + return types.Plan{}, false +} + +// SetUpgradedClient sets the expected upgraded client for the next version of this chain at the last height the current chain will commit. +func (k Keeper) SetUpgradedClient(ctx sdk.Context, planHeight int64, bz []byte) error { + store := ctx.KVStore(k.storeKey) + store.Set(types.UpgradedClientKey(planHeight), bz) + return nil +} + +// GetUpgradedClient gets the expected upgraded client for the next version of this chain +func (k Keeper) GetUpgradedClient(ctx sdk.Context, height int64) ([]byte, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.UpgradedClientKey(height)) + if len(bz) == 0 { + return nil, false + } + + return bz, true +} + +// SetUpgradedConsensusState set the expected upgraded consensus state for the next version of this chain +// using the last height committed on this chain. +func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error { + store := ctx.KVStore(k.storeKey) + store.Set(types.UpgradedConsStateKey(planHeight), bz) + return nil +} + +// GetUpgradedConsensusState get the expected upgraded consensus state for the next version of this chain +func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([]byte, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.UpgradedConsStateKey(lastHeight)) + if len(bz) == 0 { + return nil, false + } + + return bz, true +} + +// ClearIBCState clears any planned IBC state +func (k Keeper) ClearIBCState(ctx sdk.Context, lastHeight int64) { + // delete IBC client and consensus state from store if this is IBC plan + store := ctx.KVStore(k.storeKey) + store.Delete(types.UpgradedClientKey(lastHeight)) + store.Delete(types.UpgradedConsStateKey(lastHeight)) +} diff --git a/x/upgrade/interfaces.go b/x/upgrade/interfaces.go new file mode 100644 index 0000000000..ae745bb655 --- /dev/null +++ b/x/upgrade/interfaces.go @@ -0,0 +1,13 @@ +package upgrade + +import ( + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +type StakingKeeper interface { + GetLastValidatorPower(ctx sdk.Context, addr sdk.ValAddress) int64 + GetLastTotalPower(ctx sdk.Context) math.Int + GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) +} diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index 54b03dd7d9..d76cd748a8 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -1,13 +1,23 @@ package upgrade import ( + "context" + "encoding/binary" + "math" + + sdkmath "cosmossdk.io/math" + "github.com/celestiaorg/celestia-app/x/upgrade/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ibctypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -var _ ibctypes.UpgradeKeeper = (*Keeper)(nil) +// Keeper implements the MsgServer and QueryServer interfaces +var ( + _ types.MsgServer = Keeper{} + _ types.QueryServer = Keeper{} +) type Keeper struct { // we use the same upgrade store key so existing IBC client state can @@ -15,83 +25,172 @@ type Keeper struct { storeKey storetypes.StoreKey // in memory copy of the upgrade height if any. This is local per node - // and configured from the config. + // and configured from the config. Used just for V2 upgradeHeight int64 -} -type VersionSetter func(version uint64) + // quorumVersion is the version that has received a quorum of validators + // to signal for it. This variable is relevant just for the scope of the + // lifetime of the block + quorumVersion uint64 + + // staking keeper is used to fetch validators to calculate the total power + // signalled to a version + stakingKeeper StakingKeeper + + // paramStore provides access to the signal quorum param + paramStore paramtypes.Subspace +} // NewKeeper constructs an upgrade keeper -func NewKeeper(storeKey storetypes.StoreKey, upgradeHeight int64) Keeper { +func NewKeeper( + storeKey storetypes.StoreKey, + upgradeHeight int64, + stakingKeeper StakingKeeper, + paramStore paramtypes.Subspace, +) Keeper { return Keeper{ storeKey: storeKey, upgradeHeight: upgradeHeight, + stakingKeeper: stakingKeeper, + paramStore: paramStore, } } -// ScheduleUpgrade implements the ibc upgrade keeper interface. This is a noop as -// no other process is allowed to schedule an upgrade but the upgrade keeper itself. -// This is kept around to support the interface. -func (k Keeper) ScheduleUpgrade(_ sdk.Context, _ types.Plan) error { - return nil -} +// SignalVersion is a method required by the MsgServer interface +func (k Keeper) SignalVersion(ctx context.Context, req *types.MsgSignalVersion) (*types.MsgSignalVersionResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + valAddr, err := sdk.ValAddressFromBech32(req.ValidatorAddress) + if err != nil { + return nil, err + } -// GetUpgradePlan implements the ibc upgrade keeper interface. This is used in BeginBlock -// to know when to write the upgraded consensus state. The IBC module needs to sign over -// the next consensus state to ensure a smooth transition for counterparty chains. This -// is implemented as a noop. Any IBC breaking change would be invoked by this upgrade module -// in end blocker. -func (k Keeper) GetUpgradePlan(_ sdk.Context) (plan types.Plan, havePlan bool) { - return types.Plan{}, false -} + // check that the validator exists + power := k.stakingKeeper.GetLastValidatorPower(sdkCtx, valAddr) + if power <= 0 { + return nil, stakingtypes.ErrNoValidatorFound + } -// SetUpgradedClient sets the expected upgraded client for the next version of this chain at the last height the current chain will commit. -func (k Keeper) SetUpgradedClient(ctx sdk.Context, planHeight int64, bz []byte) error { - store := ctx.KVStore(k.storeKey) - store.Set(types.UpgradedClientKey(planHeight), bz) - return nil + // the signalled version must be either the current version (for cancelling an upgrade) + // or the very next version (for accepting an upgrade) + currentVersion := sdkCtx.BlockHeader().Version.App + if req.Version != currentVersion && req.Version != currentVersion+1 { + return nil, types.ErrInvalidVersion + } + + k.SetValidatorVersion(sdkCtx, valAddr, req.Version) + return &types.MsgSignalVersionResponse{}, nil } -// GetUpgradedClient gets the expected upgraded client for the next version of this chain -func (k Keeper) GetUpgradedClient(ctx sdk.Context, height int64) ([]byte, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UpgradedClientKey(height)) - if len(bz) == 0 { - return nil, false +// VersionTally is a method required by the QueryServer interface +func (k Keeper) VersionTally(ctx context.Context, req *types.QueryVersionTallyRequest) (*types.QueryVersionTallyResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + totalVotingPower := k.stakingKeeper.GetLastTotalPower(sdkCtx) + currentVotingPower := sdk.NewInt(0) + store := sdkCtx.KVStore(k.storeKey) + iterator := store.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + valAddress := sdk.ValAddress(iterator.Key()[1:]) + power := k.stakingKeeper.GetLastValidatorPower(sdkCtx, valAddress) + version := VersionFromBytes(iterator.Value()) + if version == req.Version { + currentVotingPower = currentVotingPower.AddRaw(power) + } } - return bz, true + return &types.QueryVersionTallyResponse{ + TotalVotingPower: totalVotingPower.Uint64(), + VotingPower: currentVotingPower.Uint64(), + }, nil } -// SetUpgradedConsensusState set the expected upgraded consensus state for the next version of this chain -// using the last height committed on this chain. -func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error { +// Params is a method required by the QueryServer interface +func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + params := k.GetParams(sdkCtx) + return &types.QueryParamsResponse{Params: ¶ms}, nil +} + +// SetValidatorVersion saves a signalled version for a validator using the keeper's store key +func (k Keeper) SetValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddress, version uint64) { store := ctx.KVStore(k.storeKey) - store.Set(types.UpgradedConsStateKey(planHeight), bz) - return nil + store.Set(valAddress, VersionToBytes(version)) } -// GetUpgradedConsensusState get the expected upgraded consensus state for the next version of this chain -func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([]byte, bool) { +// DeleteValidatorVersion deletes a signalled version for a validator using the keeper's store key +func (k Keeper) DeleteValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UpgradedConsStateKey(lastHeight)) - if len(bz) == 0 { - return nil, false - } + store.Delete(valAddress) +} - return bz, true +// EndBlock is called at the end of every block. It tallies the voting power that has +// voted on each version. If one version has quorum, it is set as the quorum version +// which the application can use as signal to upgrade to that version. +func (k Keeper) EndBlock(ctx sdk.Context) { + threshold := k.GetVotingPowerThreshold(ctx) + hasQuorum, version := k.TallyVotingPower(ctx, threshold) + if hasQuorum { + k.quorumVersion = version + } } -// ClearIBCState clears any planned IBC state -func (k Keeper) ClearIBCState(ctx sdk.Context, lastHeight int64) { - // delete IBC client and consensus state from store if this is IBC plan +// TallyVotingPower tallies the voting power for each version and returns true if +// any version has reached the quorum in voting power +func (k Keeper) TallyVotingPower(ctx sdk.Context, quorum int64) (bool, uint64) { + output := make(map[uint64]int64) store := ctx.KVStore(k.storeKey) - store.Delete(types.UpgradedClientKey(lastHeight)) - store.Delete(types.UpgradedConsStateKey(lastHeight)) + iterator := store.Iterator(nil, nil) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + valAddress := sdk.ValAddress(iterator.Key()[1:]) + // check that the validator is still part of the bonded set + if val, found := k.stakingKeeper.GetValidator(ctx, valAddress); !found || !val.IsBonded() { + k.DeleteValidatorVersion(ctx, valAddress) + continue + } + power := k.stakingKeeper.GetLastValidatorPower(ctx, valAddress) + version := VersionFromBytes(iterator.Value()) + if _, ok := output[version]; !ok { + output[version] = power + } else { + output[version] += power + } + if output[version] > quorum { + return true, version + } + } + return false, 0 +} + +// GetVotingPowerThreshold returns the voting power threshold required to +// upgrade to a new version. It converts the signal quorum parameter which +// is a number between 0 and math.MaxUint32 representing a fraction and +// then multiplies it by the total voting power +func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) int64 { + quorum := sdkmath.NewInt(int64(k.GetParams(ctx).SignalQuorum)) + totalVotingPower := k.stakingKeeper.GetLastTotalPower(ctx) + return totalVotingPower.Mul(quorum).QuoRaw(math.MaxUint32).Int64() } -// ShouldUpgrade returns true if the current height is one before +// ShouldUpgradeToV2 returns true if the current height is one before // the locally provided upgrade height that is passed as a flag -func (k Keeper) ShouldUpgrade(height int64) bool { +// NOTE: This is only used to upgrade to v2 and should be deprecated +// in v3 +func (k Keeper) ShouldUpgradeToV2(height int64) bool { return k.upgradeHeight == height+1 } + +// ShouldUpgrade returns true if the signalling mechanism has concluded +// that the network is ready to upgrade. It also returns the version +// that the node should upgrade to. +func (k *Keeper) ShouldUpgrade() (bool, uint64) { + return k.quorumVersion != 0, k.quorumVersion +} + +func VersionToBytes(version uint64) []byte { + return binary.BigEndian.AppendUint64(nil, version) +} + +func VersionFromBytes(version []byte) uint64 { + return binary.BigEndian.Uint64(version) +} diff --git a/x/upgrade/module.go b/x/upgrade/module.go new file mode 100644 index 0000000000..ae87be6a67 --- /dev/null +++ b/x/upgrade/module.go @@ -0,0 +1,129 @@ +package upgrade + +import ( + "context" + "encoding/json" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/celestiaorg/celestia-app/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" +) + +func init() { + types.RegisterLegacyAminoCodec(codec.NewLegacyAmino()) +} + +const ( + consensusVersion uint64 = 2 +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic implements the sdk.AppModuleBasic interface +type AppModuleBasic struct{} + +// Name returns the ModuleName +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the upgrade types on the LegacyAmino codec +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetQueryCmd returns the cli query commands for this module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// GetTxCmd returns the transaction commands for this module +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// AppModule implements the sdk.AppModule interface +type AppModule struct { + AppModuleBasic + keeper Keeper +} + +// NewAppModule creates a new AppModule object +func NewAppModule(keeper Keeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, + } +} + +// RegisterInvariants does nothing, there are no invariants to enforce +func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// Deprecated: Route returns the message routing key for the upgrade module. +func (AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute returns the route we respond to for abci queries +func (AppModule) QuerierRoute() string { return types.QuerierRoute } + +// LegacyQuerierHandler registers a query handler to respond to the module-specific queries +func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// InitGenesis is ignored, no sense in serializing future upgrades +func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// DefaultGenesis is an empty object +func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { + return []byte("{}") +} + +// ValidateGenesis is always successful, as we ignore the value +func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, _ json.RawMessage) error { + return nil +} + +// ExportGenesis is always empty, as InitGenesis does nothing either +func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return am.DefaultGenesis(cdc) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return consensusVersion } + +// EndBlock is used by the Endblocker +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) { + am.keeper.EndBlock(ctx) +} diff --git a/x/upgrade/params.go b/x/upgrade/params.go new file mode 100644 index 0000000000..9e2b5c4828 --- /dev/null +++ b/x/upgrade/params.go @@ -0,0 +1,24 @@ +package upgrade + +import ( + "github.com/celestiaorg/celestia-app/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// GetParams gets all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams( + k.SignalQuorum(ctx), + ) +} + +// SetParams sets the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramStore.SetParamSet(ctx, ¶ms) +} + +// SignalQuorum returns the SignalQuorum param +func (k Keeper) SignalQuorum(ctx sdk.Context) (res uint32) { + k.paramStore.Get(ctx, types.KeySignalQuorum, &res) + return res +} diff --git a/x/upgrade/types.go b/x/upgrade/types.go deleted file mode 100644 index ba3270a9c0..0000000000 --- a/x/upgrade/types.go +++ /dev/null @@ -1,65 +0,0 @@ -package upgrade - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -const ( - StoreKey = upgradetypes.StoreKey - ModuleName = upgradetypes.ModuleName -) - -var _ sdk.Msg = &MsgVersionChange{} - -// TypeRegister is used to register the upgrade module's types in the encoding -// config without defining an entire module. -type TypeRegister struct{} - -// RegisterLegacyAminoCodec registers the upgrade types on the LegacyAmino codec. -func (TypeRegister) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(upgradetypes.Plan{}, "cosmos-sdk/Plan", nil) - cdc.RegisterConcrete(MsgVersionChange{}, "celestia/MsgVersionChange", nil) -} - -// RegisterInterfaces registers the upgrade module types. -func (TypeRegister) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - registry.RegisterImplementations((*sdk.Msg)(nil), - &MsgVersionChange{}, - ) -} - -func (msg *MsgVersionChange) GetSigners() []sdk.AccAddress { - return nil -} - -func (msg *MsgVersionChange) ValidateBasic() error { - return nil -} - -// NewMsgVersionChange creates a tx in byte form used to signal to validators -// to change to a new version -func NewMsgVersionChange(txConfig client.TxConfig, version uint64) ([]byte, error) { - builder := txConfig.NewTxBuilder() - msg := &MsgVersionChange{ - Version: version, - } - if err := builder.SetMsgs(msg); err != nil { - return nil, err - } - return txConfig.TxEncoder()(builder.GetTx()) -} - -func IsUpgradeMsg(msg []sdk.Msg) (uint64, bool) { - if len(msg) != 1 { - return 0, false - } - msgVersionChange, ok := msg[0].(*MsgVersionChange) - if !ok { - return 0, false - } - return msgVersionChange.Version, true -} diff --git a/x/upgrade/types.pb.go b/x/upgrade/types.pb.go deleted file mode 100644 index 3e5eb9271e..0000000000 --- a/x/upgrade/types.pb.go +++ /dev/null @@ -1,301 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: celestia/upgrade/v1/types.proto - -package upgrade - -import ( - fmt "fmt" - proto "github.com/gogo/protobuf/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 - -// MsgVersionChange is a message that signals an app version change -type MsgVersionChange struct { - // the app version this message proposes upgrading to - Version uint64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` -} - -func (m *MsgVersionChange) Reset() { *m = MsgVersionChange{} } -func (m *MsgVersionChange) String() string { return proto.CompactTextString(m) } -func (*MsgVersionChange) ProtoMessage() {} -func (*MsgVersionChange) Descriptor() ([]byte, []int) { - return fileDescriptor_0195354c266f07b3, []int{0} -} -func (m *MsgVersionChange) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgVersionChange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgVersionChange.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 *MsgVersionChange) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgVersionChange.Merge(m, src) -} -func (m *MsgVersionChange) XXX_Size() int { - return m.Size() -} -func (m *MsgVersionChange) XXX_DiscardUnknown() { - xxx_messageInfo_MsgVersionChange.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgVersionChange proto.InternalMessageInfo - -func (m *MsgVersionChange) GetVersion() uint64 { - if m != nil { - return m.Version - } - return 0 -} - -func init() { - proto.RegisterType((*MsgVersionChange)(nil), "celestia.upgrade.v1.MsgVersionChange") -} - -func init() { proto.RegisterFile("celestia/upgrade/v1/types.proto", fileDescriptor_0195354c266f07b3) } - -var fileDescriptor_0195354c266f07b3 = []byte{ - // 164 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0x4e, 0xcd, 0x49, - 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, - 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x29, 0xd0, - 0x83, 0x2a, 0xd0, 0x2b, 0x33, 0x54, 0xd2, 0xe1, 0x12, 0xf0, 0x2d, 0x4e, 0x0f, 0x4b, 0x2d, 0x2a, - 0xce, 0xcc, 0xcf, 0x73, 0xce, 0x48, 0xcc, 0x4b, 0x4f, 0x15, 0x92, 0xe0, 0x62, 0x2f, 0x83, 0x08, - 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0xc1, 0xb8, 0x4e, 0xee, 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, 0xa5, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, - 0xab, 0x0f, 0xb3, 0x27, 0xbf, 0x28, 0x1d, 0xce, 0xd6, 0x4d, 0x2c, 0x28, 0xd0, 0xaf, 0x80, 0x39, - 0x2d, 0x89, 0x0d, 0xec, 0x24, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x04, 0x7a, 0xde, 0x74, - 0xb5, 0x00, 0x00, 0x00, -} - -func (m *MsgVersionChange) 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 *MsgVersionChange) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgVersionChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Version != 0 { - i = encodeVarintTypes(dAtA, i, uint64(m.Version)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgVersionChange) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Version != 0 { - n += 1 + sovTypes(uint64(m.Version)) - } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgVersionChange) 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 ErrIntOverflowTypes - } - 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: MsgVersionChange: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgVersionChange: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) - } - m.Version = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Version |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTypes(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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrIntOverflowTypes - } - 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, ErrInvalidLengthTypes - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTypes - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTypes - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go new file mode 100644 index 0000000000..7cf5a81e89 --- /dev/null +++ b/x/upgrade/types/codec.go @@ -0,0 +1,18 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// RegisterLegacyAminoCodec registers the upgrade types on the LegacyAmino codec. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(upgradetypes.Plan{}, "cosmos-sdk/Plan", nil) +} + +// RegisterInterfaces registers the upgrade module types. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} diff --git a/x/upgrade/types/errors.go b/x/upgrade/types/errors.go new file mode 100644 index 0000000000..1ff6064d9b --- /dev/null +++ b/x/upgrade/types/errors.go @@ -0,0 +1,7 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +var ErrInvalidVersion = errors.Register(ModuleName, 1, "signalled version must be either the current version or one greater") diff --git a/x/upgrade/types/msgs.go b/x/upgrade/types/msgs.go new file mode 100644 index 0000000000..d308ab9f74 --- /dev/null +++ b/x/upgrade/types/msgs.go @@ -0,0 +1,38 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +const ( + StoreKey = upgradetypes.StoreKey + + // Copied from cosmos/cosmos-sdk/x/upgrade/types/keys.go: + ModuleName = upgradetypes.ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) + +var _ sdk.Msg = &MsgSignalVersion{} + +func NewMsgSignalVersion(valAddress sdk.ValAddress, version uint64) *MsgSignalVersion { + return &MsgSignalVersion{ + ValidatorAddress: valAddress.String(), + Version: version, + } +} + +func (msg *MsgSignalVersion) GetSigners() []sdk.AccAddress { + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sdk.AccAddress(valAddr)} +} + +func (msg *MsgSignalVersion) ValidateBasic() error { + _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + return err +} diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go new file mode 100644 index 0000000000..6a83d9f441 --- /dev/null +++ b/x/upgrade/types/params.go @@ -0,0 +1,51 @@ +package types + +import ( + "fmt" + "math" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var KeySignalQuorum = []byte("SignalQuorum") + +// ParamKeyTable returns the param key table for the blob module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +func NewParams(signalQuorum uint32) Params { + return Params{ + SignalQuorum: signalQuorum, + } +} + +func DefaultParams() *Params { + return &Params{ + SignalQuorum: MinSignalQuorum, + } +} + +// 2/3 +const MinSignalQuorum = uint32(math.MaxUint32 * 2 / 3) + +func (p Params) Validate() error { + return validateSignalQuorum(p.SignalQuorum) +} + +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeySignalQuorum, &p.SignalQuorum, validateSignalQuorum), + } +} + +func validateSignalQuorum(i interface{}) error { + v, ok := i.(uint32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v < MinSignalQuorum { + return fmt.Errorf("quorum must be at least %d (2/3), got %d", MinSignalQuorum, v) + } + return nil +} diff --git a/x/upgrade/params.pb.go b/x/upgrade/types/params.pb.go similarity index 80% rename from x/upgrade/params.pb.go rename to x/upgrade/types/params.pb.go index c63afae38f..e9bf0b3a18 100644 --- a/x/upgrade/params.pb.go +++ b/x/upgrade/types/params.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: celestia/upgrade/v1/params.proto -package upgrade +package types import ( fmt "fmt" @@ -24,9 +24,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the upgrade module. type Params struct { - // Quorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. - Quorum uint64 `protobuf:"varint,1,opt,name=quorum,proto3" json:"quorum,omitempty"` + // SignalQuorum represents the minimum voting power for an upgrade to go through. + // It must be at least 2/3. MaxUint32 would mean 100% of the voting power. + SignalQuorum uint32 `protobuf:"varint,1,opt,name=signal_quorum,json=signalQuorum,proto3" json:"signal_quorum,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -62,9 +62,9 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetQuorum() uint64 { +func (m *Params) GetSignalQuorum() uint32 { if m != nil { - return m.Quorum + return m.SignalQuorum } return 0 } @@ -76,17 +76,18 @@ func init() { func init() { proto.RegisterFile("celestia/upgrade/v1/params.proto", fileDescriptor_b4f657414f35d610) } var fileDescriptor_b4f657414f35d610 = []byte{ - // 155 bytes of a gzipped FileDescriptorProto + // 171 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa9, - 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x54, 0x52, 0xe0, 0x62, 0x0b, 0x00, 0x2b, 0x12, 0x12, 0xe3, - 0x62, 0x2b, 0x2c, 0xcd, 0x2f, 0x2a, 0xcd, 0x95, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x09, 0x82, 0xf2, - 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, - 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, 0xb3, - 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x66, 0x76, 0x7e, 0x51, 0x3a, 0x9c, 0xad, - 0x9b, 0x58, 0x50, 0xa0, 0x5f, 0x01, 0x73, 0x4f, 0x12, 0x1b, 0xd8, 0x19, 0xc6, 0x80, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xc2, 0x56, 0x00, 0xb6, 0xaa, 0x00, 0x00, 0x00, + 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x54, 0xd2, 0xe5, 0x62, 0x0b, 0x00, 0x2b, 0x12, 0x52, 0xe6, + 0xe2, 0x2d, 0xce, 0x4c, 0xcf, 0x4b, 0xcc, 0x89, 0x2f, 0x2c, 0xcd, 0x2f, 0x2a, 0xcd, 0x95, 0x60, + 0x54, 0x60, 0xd4, 0xe0, 0x0d, 0xe2, 0x81, 0x08, 0x06, 0x82, 0xc5, 0x9c, 0x7c, 0x4f, 0x3c, 0x92, + 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, + 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x38, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, + 0x39, 0x3f, 0x57, 0x1f, 0x66, 0x51, 0x7e, 0x51, 0x3a, 0x9c, 0xad, 0x9b, 0x58, 0x50, 0xa0, 0x5f, + 0x01, 0x77, 0x5c, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x65, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x78, 0xaa, 0x4c, 0x7d, 0xbd, 0x00, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -109,8 +110,8 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Quorum != 0 { - i = encodeVarintParams(dAtA, i, uint64(m.Quorum)) + if m.SignalQuorum != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.SignalQuorum)) i-- dAtA[i] = 0x8 } @@ -134,8 +135,8 @@ func (m *Params) Size() (n int) { } var l int _ = l - if m.Quorum != 0 { - n += 1 + sovParams(uint64(m.Quorum)) + if m.SignalQuorum != 0 { + n += 1 + sovParams(uint64(m.SignalQuorum)) } return n } @@ -177,9 +178,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Quorum", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SignalQuorum", wireType) } - m.Quorum = 0 + m.SignalQuorum = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowParams @@ -189,7 +190,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Quorum |= uint64(b&0x7F) << shift + m.SignalQuorum |= uint32(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/upgrade/query.pb.go b/x/upgrade/types/query.pb.go similarity index 66% rename from x/upgrade/query.pb.go rename to x/upgrade/types/query.pb.go index 4694da54d6..f2dad257df 100644 --- a/x/upgrade/query.pb.go +++ b/x/upgrade/types/query.pb.go @@ -1,12 +1,11 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: celestia/upgrade/v1/query.proto -package upgrade +package types import ( context "context" fmt "fmt" - types "github.com/celestiaorg/celestia-app/x/blob/types" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" _ "google.golang.org/genproto/googleapis/api/annotations" @@ -68,7 +67,7 @@ var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo // QueryParamsResponse is the response type for the Params RPC method. type QueryParamsResponse struct { - Params *types.Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` + Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` } func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } @@ -104,30 +103,31 @@ func (m *QueryParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo -func (m *QueryParamsResponse) GetParams() *types.Params { +func (m *QueryParamsResponse) GetParams() *Params { if m != nil { return m.Params } return nil } -// QueryUpgradeStatusRequest is the request type for the UpgradeStatus RPC method. -type QueryUpgradeStatusRequest struct { +// QueryVersionTallyRequest is the request type for the UpgradeStatus RPC +// method. +type QueryVersionTallyRequest struct { Version uint64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` } -func (m *QueryUpgradeStatusRequest) Reset() { *m = QueryUpgradeStatusRequest{} } -func (m *QueryUpgradeStatusRequest) String() string { return proto.CompactTextString(m) } -func (*QueryUpgradeStatusRequest) ProtoMessage() {} -func (*QueryUpgradeStatusRequest) Descriptor() ([]byte, []int) { +func (m *QueryVersionTallyRequest) Reset() { *m = QueryVersionTallyRequest{} } +func (m *QueryVersionTallyRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVersionTallyRequest) ProtoMessage() {} +func (*QueryVersionTallyRequest) Descriptor() ([]byte, []int) { return fileDescriptor_7dd2290b21d03efa, []int{2} } -func (m *QueryUpgradeStatusRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryVersionTallyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryUpgradeStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryVersionTallyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryUpgradeStatusRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryVersionTallyRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -137,42 +137,44 @@ func (m *QueryUpgradeStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *QueryUpgradeStatusRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryUpgradeStatusRequest.Merge(m, src) +func (m *QueryVersionTallyRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVersionTallyRequest.Merge(m, src) } -func (m *QueryUpgradeStatusRequest) XXX_Size() int { +func (m *QueryVersionTallyRequest) XXX_Size() int { return m.Size() } -func (m *QueryUpgradeStatusRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryUpgradeStatusRequest.DiscardUnknown(m) +func (m *QueryVersionTallyRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVersionTallyRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryUpgradeStatusRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryVersionTallyRequest proto.InternalMessageInfo -func (m *QueryUpgradeStatusRequest) GetVersion() uint64 { +func (m *QueryVersionTallyRequest) GetVersion() uint64 { if m != nil { return m.Version } return 0 } -// QueryUpgradeStatusResponse is the response type for the UpgradeStatus RPC method. -type QueryUpgradeStatusResponse struct { - VotingPower uint64 `protobuf:"varint,1,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` +// QueryVersionTallyResponse is the response type for the UpgradeStatus RPC +// method. +type QueryVersionTallyResponse struct { + VotingPower uint64 `protobuf:"varint,1,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` + TotalVotingPower uint64 `protobuf:"varint,2,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` } -func (m *QueryUpgradeStatusResponse) Reset() { *m = QueryUpgradeStatusResponse{} } -func (m *QueryUpgradeStatusResponse) String() string { return proto.CompactTextString(m) } -func (*QueryUpgradeStatusResponse) ProtoMessage() {} -func (*QueryUpgradeStatusResponse) Descriptor() ([]byte, []int) { +func (m *QueryVersionTallyResponse) Reset() { *m = QueryVersionTallyResponse{} } +func (m *QueryVersionTallyResponse) String() string { return proto.CompactTextString(m) } +func (*QueryVersionTallyResponse) ProtoMessage() {} +func (*QueryVersionTallyResponse) Descriptor() ([]byte, []int) { return fileDescriptor_7dd2290b21d03efa, []int{3} } -func (m *QueryUpgradeStatusResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryVersionTallyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryUpgradeStatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryVersionTallyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryUpgradeStatusResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryVersionTallyResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -182,58 +184,67 @@ func (m *QueryUpgradeStatusResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *QueryUpgradeStatusResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryUpgradeStatusResponse.Merge(m, src) +func (m *QueryVersionTallyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVersionTallyResponse.Merge(m, src) } -func (m *QueryUpgradeStatusResponse) XXX_Size() int { +func (m *QueryVersionTallyResponse) XXX_Size() int { return m.Size() } -func (m *QueryUpgradeStatusResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryUpgradeStatusResponse.DiscardUnknown(m) +func (m *QueryVersionTallyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVersionTallyResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryUpgradeStatusResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryVersionTallyResponse proto.InternalMessageInfo -func (m *QueryUpgradeStatusResponse) GetVotingPower() uint64 { +func (m *QueryVersionTallyResponse) GetVotingPower() uint64 { if m != nil { return m.VotingPower } return 0 } +func (m *QueryVersionTallyResponse) GetTotalVotingPower() uint64 { + if m != nil { + return m.TotalVotingPower + } + return 0 +} + func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "celestia.blob.v1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "celestia.blob.v1.QueryParamsResponse") - proto.RegisterType((*QueryUpgradeStatusRequest)(nil), "celestia.blob.v1.QueryUpgradeStatusRequest") - proto.RegisterType((*QueryUpgradeStatusResponse)(nil), "celestia.blob.v1.QueryUpgradeStatusResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "celestia.upgrade.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "celestia.upgrade.v1.QueryParamsResponse") + proto.RegisterType((*QueryVersionTallyRequest)(nil), "celestia.upgrade.v1.QueryVersionTallyRequest") + proto.RegisterType((*QueryVersionTallyResponse)(nil), "celestia.upgrade.v1.QueryVersionTallyResponse") } func init() { proto.RegisterFile("celestia/upgrade/v1/query.proto", fileDescriptor_7dd2290b21d03efa) } var fileDescriptor_7dd2290b21d03efa = []byte{ - // 350 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4f, 0x4b, 0xc3, 0x30, - 0x18, 0xc6, 0xd7, 0xa1, 0x13, 0x32, 0x05, 0x89, 0x3b, 0xcc, 0xa2, 0x55, 0x8b, 0x82, 0xa0, 0x6b, - 0xdc, 0xc4, 0xb3, 0xe0, 0x65, 0xd7, 0x39, 0xf1, 0xe2, 0x45, 0xd2, 0x19, 0x6a, 0x61, 0xeb, 0x9b, - 0x25, 0x69, 0xd5, 0xab, 0x82, 0x67, 0xc1, 0x2f, 0xe5, 0x71, 0xe0, 0xc5, 0xa3, 0x6c, 0x7e, 0x10, - 0x69, 0xd2, 0x0e, 0xe7, 0xe6, 0x9f, 0x5b, 0xfb, 0xf4, 0x79, 0x7e, 0xef, 0xf3, 0x36, 0x41, 0x1b, - 0x1d, 0xd6, 0x65, 0x52, 0x85, 0x94, 0xc4, 0x3c, 0x10, 0xf4, 0x8a, 0x91, 0xa4, 0x4e, 0xfa, 0x31, - 0x13, 0x77, 0x1e, 0x17, 0xa0, 0x00, 0x2f, 0xe7, 0x06, 0xcf, 0xef, 0x82, 0xef, 0x25, 0x75, 0x7b, - 0x2d, 0x00, 0x08, 0xba, 0x8c, 0x50, 0x1e, 0x12, 0x1a, 0x45, 0xa0, 0xa8, 0x0a, 0x21, 0x92, 0xc6, - 0x6f, 0xaf, 0x8f, 0x81, 0xa9, 0x3f, 0xa5, 0x71, 0x2a, 0x68, 0x2f, 0xfb, 0xec, 0x56, 0x10, 0x3e, - 0x4d, 0xe9, 0x2d, 0x2d, 0xb6, 0x59, 0x3f, 0x66, 0x52, 0xb9, 0x4d, 0xb4, 0x32, 0xa1, 0x4a, 0x0e, - 0x91, 0x64, 0xf8, 0x00, 0x95, 0x4c, 0xb8, 0x6a, 0x6d, 0x5a, 0xbb, 0xe5, 0x46, 0xd5, 0xfb, 0x5e, - 0xc6, 0xcb, 0x12, 0x99, 0xcf, 0x3d, 0x42, 0xab, 0x1a, 0x74, 0x6e, 0x96, 0x39, 0x53, 0x54, 0xc5, - 0xf9, 0x14, 0x5c, 0x45, 0x0b, 0x09, 0x13, 0x32, 0x84, 0x48, 0xf3, 0xe6, 0xda, 0xf9, 0xab, 0x7b, - 0x8c, 0xec, 0x59, 0xb1, 0xac, 0xc6, 0x16, 0x5a, 0x4c, 0x40, 0x85, 0x51, 0x70, 0xc9, 0xe1, 0x86, - 0x89, 0x2c, 0x5c, 0x36, 0x5a, 0x2b, 0x95, 0x1a, 0x0f, 0x45, 0x34, 0xaf, 0x09, 0xb8, 0x8f, 0x4a, - 0xa6, 0x13, 0xde, 0x9e, 0x6e, 0x3b, 0xbd, 0xba, 0xbd, 0xf3, 0x87, 0xcb, 0x74, 0x70, 0xed, 0xfb, - 0xd7, 0x8f, 0xe7, 0x62, 0x05, 0xe3, 0xaf, 0xe7, 0x64, 0x96, 0xc6, 0x8f, 0x16, 0x5a, 0x9a, 0x68, - 0x8e, 0xf7, 0x7e, 0x80, 0xce, 0xfa, 0x2d, 0xf6, 0xfe, 0xff, 0xcc, 0xbf, 0x15, 0x91, 0xda, 0x73, - 0xd2, 0x7c, 0x19, 0x3a, 0xd6, 0x60, 0xe8, 0x58, 0xef, 0x43, 0xc7, 0x7a, 0x1a, 0x39, 0x85, 0xc1, - 0xc8, 0x29, 0xbc, 0x8d, 0x9c, 0xc2, 0x45, 0x2d, 0x08, 0xd5, 0x75, 0xec, 0x7b, 0x1d, 0xe8, 0x91, - 0x7c, 0x1a, 0x88, 0x60, 0xfc, 0x5c, 0xa3, 0x9c, 0x93, 0xdb, 0x1c, 0xe9, 0x97, 0xf4, 0x65, 0x39, - 0xfc, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x3a, 0x92, 0x35, 0x59, 0x9e, 0x02, 0x00, 0x00, + // 380 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4e, 0xea, 0x40, + 0x18, 0x85, 0x29, 0xb9, 0x97, 0x9b, 0x0c, 0x2c, 0x6e, 0x06, 0x16, 0xdc, 0x72, 0xad, 0x58, 0x17, + 0xb2, 0x90, 0x99, 0x00, 0x3e, 0x81, 0x4b, 0x13, 0x13, 0x24, 0x86, 0x85, 0x1b, 0x32, 0xe0, 0xa4, + 0x36, 0x29, 0x9d, 0x61, 0x66, 0x5a, 0x24, 0xc6, 0x8d, 0x4f, 0x60, 0x34, 0xbe, 0x93, 0x4b, 0x12, + 0x37, 0x2e, 0x0d, 0xf8, 0x20, 0x86, 0xe9, 0x80, 0x10, 0x6a, 0x74, 0xd7, 0x9e, 0x7e, 0xe7, 0xfc, + 0x67, 0xe6, 0x2f, 0xd8, 0x1d, 0xd0, 0x80, 0x4a, 0xe5, 0x13, 0x1c, 0x71, 0x4f, 0x90, 0x4b, 0x8a, + 0xe3, 0x06, 0x1e, 0x45, 0x54, 0x4c, 0x10, 0x17, 0x4c, 0x31, 0x58, 0x5c, 0x02, 0xc8, 0x00, 0x28, + 0x6e, 0xd8, 0xff, 0x3d, 0xc6, 0xbc, 0x80, 0x62, 0xc2, 0x7d, 0x4c, 0xc2, 0x90, 0x29, 0xa2, 0x7c, + 0x16, 0xca, 0xc4, 0x62, 0x57, 0xd3, 0x32, 0x39, 0x11, 0x64, 0x68, 0x08, 0xb7, 0x04, 0xe0, 0xd9, + 0x62, 0x46, 0x5b, 0x8b, 0x1d, 0x3a, 0x8a, 0xa8, 0x54, 0xee, 0x09, 0x28, 0x6e, 0xa8, 0x92, 0xb3, + 0x50, 0x52, 0xd8, 0x02, 0xb9, 0xc4, 0x5c, 0xb6, 0xaa, 0x56, 0x2d, 0xdf, 0xac, 0xa0, 0x94, 0x4a, + 0xc8, 0x98, 0x0c, 0xea, 0x1e, 0x81, 0xb2, 0xce, 0xea, 0x52, 0x21, 0x7d, 0x16, 0x9e, 0x93, 0x20, + 0x98, 0x98, 0x39, 0xb0, 0x0c, 0xfe, 0xc4, 0x89, 0xac, 0x13, 0x7f, 0x75, 0x96, 0xaf, 0x6e, 0x00, + 0xfe, 0xa5, 0xb8, 0x4c, 0x8f, 0x3d, 0x50, 0x88, 0x99, 0xf2, 0x43, 0xaf, 0xc7, 0xd9, 0x98, 0x0a, + 0xe3, 0xcd, 0x27, 0x5a, 0x7b, 0x21, 0xc1, 0x43, 0x00, 0x15, 0x53, 0x24, 0xe8, 0x6d, 0x80, 0x59, + 0x0d, 0xfe, 0xd5, 0x5f, 0xba, 0x9f, 0x74, 0xf3, 0x29, 0x0b, 0x7e, 0xeb, 0x71, 0x70, 0x0c, 0x72, + 0x49, 0x7f, 0x78, 0x90, 0x7a, 0xb8, 0xed, 0xcb, 0xb2, 0x6b, 0xdf, 0x83, 0x49, 0x6f, 0xd7, 0xbe, + 0x7b, 0x79, 0x7f, 0xcc, 0x96, 0x20, 0xdc, 0x5e, 0x07, 0x7c, 0xb0, 0x40, 0x61, 0xfd, 0xb0, 0xb0, + 0xfe, 0x75, 0x6c, 0xca, 0x55, 0xda, 0xe8, 0xa7, 0xb8, 0xe9, 0xb2, 0xaf, 0xbb, 0xec, 0xc0, 0xca, + 0x7a, 0x17, 0xb5, 0x40, 0xf0, 0x8d, 0x59, 0xc2, 0xed, 0xf1, 0xe9, 0xf3, 0xcc, 0xb1, 0xa6, 0x33, + 0xc7, 0x7a, 0x9b, 0x39, 0xd6, 0xfd, 0xdc, 0xc9, 0x4c, 0xe7, 0x4e, 0xe6, 0x75, 0xee, 0x64, 0x2e, + 0x5a, 0x9e, 0xaf, 0xae, 0xa2, 0x3e, 0x1a, 0xb0, 0x21, 0x5e, 0x0e, 0x66, 0xc2, 0x5b, 0x3d, 0xd7, + 0x09, 0xe7, 0xf8, 0x7a, 0x95, 0xad, 0x26, 0x9c, 0xca, 0x7e, 0x4e, 0xff, 0x73, 0xad, 0x8f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xe7, 0xf7, 0xd5, 0xf3, 0xeb, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -250,8 +261,9 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Params allows the querying of the params Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) - // UpgradeStatus allows the querying of the tally of voting power by all validators that have signalled for each version - UpgradeStatus(ctx context.Context, in *QueryUpgradeStatusRequest, opts ...grpc.CallOption) (*QueryUpgradeStatusResponse, error) + // VersionTally allows the querying of the tally of voting power by all + // validators that have signalled for each version + VersionTally(ctx context.Context, in *QueryVersionTallyRequest, opts ...grpc.CallOption) (*QueryVersionTallyResponse, error) } type queryClient struct { @@ -264,16 +276,16 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/celestia.blob.v1.Query/Params", in, out, opts...) + err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Query/Params", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *queryClient) UpgradeStatus(ctx context.Context, in *QueryUpgradeStatusRequest, opts ...grpc.CallOption) (*QueryUpgradeStatusResponse, error) { - out := new(QueryUpgradeStatusResponse) - err := c.cc.Invoke(ctx, "/celestia.blob.v1.Query/UpgradeStatus", in, out, opts...) +func (c *queryClient) VersionTally(ctx context.Context, in *QueryVersionTallyRequest, opts ...grpc.CallOption) (*QueryVersionTallyResponse, error) { + out := new(QueryVersionTallyResponse) + err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Query/VersionTally", in, out, opts...) if err != nil { return nil, err } @@ -284,8 +296,9 @@ func (c *queryClient) UpgradeStatus(ctx context.Context, in *QueryUpgradeStatusR type QueryServer interface { // Params allows the querying of the params Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) - // UpgradeStatus allows the querying of the tally of voting power by all validators that have signalled for each version - UpgradeStatus(context.Context, *QueryUpgradeStatusRequest) (*QueryUpgradeStatusResponse, error) + // VersionTally allows the querying of the tally of voting power by all + // validators that have signalled for each version + VersionTally(context.Context, *QueryVersionTallyRequest) (*QueryVersionTallyResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -295,8 +308,8 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } -func (*UnimplementedQueryServer) UpgradeStatus(ctx context.Context, req *QueryUpgradeStatusRequest) (*QueryUpgradeStatusResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpgradeStatus not implemented") +func (*UnimplementedQueryServer) VersionTally(ctx context.Context, req *QueryVersionTallyRequest) (*QueryVersionTallyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VersionTally not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -313,7 +326,7 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.blob.v1.Query/Params", + FullMethod: "/celestia.upgrade.v1.Query/Params", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) @@ -321,26 +334,26 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _Query_UpgradeStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryUpgradeStatusRequest) +func _Query_VersionTally_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVersionTallyRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).UpgradeStatus(ctx, in) + return srv.(QueryServer).VersionTally(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.blob.v1.Query/UpgradeStatus", + FullMethod: "/celestia.upgrade.v1.Query/VersionTally", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).UpgradeStatus(ctx, req.(*QueryUpgradeStatusRequest)) + return srv.(QueryServer).VersionTally(ctx, req.(*QueryVersionTallyRequest)) } return interceptor(ctx, in, info, handler) } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "celestia.blob.v1.Query", + ServiceName: "celestia.upgrade.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -348,8 +361,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_Params_Handler, }, { - MethodName: "UpgradeStatus", - Handler: _Query_UpgradeStatus_Handler, + MethodName: "VersionTally", + Handler: _Query_VersionTally_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -414,7 +427,7 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryUpgradeStatusRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryVersionTallyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -424,12 +437,12 @@ func (m *QueryUpgradeStatusRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryUpgradeStatusRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryVersionTallyRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryUpgradeStatusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryVersionTallyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -442,7 +455,7 @@ func (m *QueryUpgradeStatusRequest) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *QueryUpgradeStatusResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryVersionTallyResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -452,16 +465,21 @@ func (m *QueryUpgradeStatusResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryUpgradeStatusResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryVersionTallyResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryUpgradeStatusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryVersionTallyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l + if m.TotalVotingPower != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.TotalVotingPower)) + i-- + dAtA[i] = 0x10 + } if m.VotingPower != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.VotingPower)) i-- @@ -503,7 +521,7 @@ func (m *QueryParamsResponse) Size() (n int) { return n } -func (m *QueryUpgradeStatusRequest) Size() (n int) { +func (m *QueryVersionTallyRequest) Size() (n int) { if m == nil { return 0 } @@ -515,7 +533,7 @@ func (m *QueryUpgradeStatusRequest) Size() (n int) { return n } -func (m *QueryUpgradeStatusResponse) Size() (n int) { +func (m *QueryVersionTallyResponse) Size() (n int) { if m == nil { return 0 } @@ -524,6 +542,9 @@ func (m *QueryUpgradeStatusResponse) Size() (n int) { if m.VotingPower != 0 { n += 1 + sovQuery(uint64(m.VotingPower)) } + if m.TotalVotingPower != 0 { + n += 1 + sovQuery(uint64(m.TotalVotingPower)) + } return n } @@ -642,7 +663,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Params == nil { - m.Params = &types.Params{} + m.Params = &Params{} } if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err @@ -669,7 +690,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryUpgradeStatusRequest) Unmarshal(dAtA []byte) error { +func (m *QueryVersionTallyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -692,10 +713,10 @@ func (m *QueryUpgradeStatusRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryUpgradeStatusRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryVersionTallyRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryUpgradeStatusRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryVersionTallyRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -738,7 +759,7 @@ func (m *QueryUpgradeStatusRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryUpgradeStatusResponse) Unmarshal(dAtA []byte) error { +func (m *QueryVersionTallyResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -761,10 +782,10 @@ func (m *QueryUpgradeStatusResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryUpgradeStatusResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryVersionTallyResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryUpgradeStatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryVersionTallyResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -786,6 +807,25 @@ func (m *QueryUpgradeStatusResponse) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalVotingPower", wireType) + } + m.TotalVotingPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TotalVotingPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/upgrade/query.pb.gw.go b/x/upgrade/types/query.pb.gw.go similarity index 74% rename from x/upgrade/query.pb.gw.go rename to x/upgrade/types/query.pb.gw.go index 9520f7c98e..fb87b44f83 100644 --- a/x/upgrade/query.pb.gw.go +++ b/x/upgrade/types/query.pb.gw.go @@ -2,11 +2,11 @@ // source: celestia/upgrade/v1/query.proto /* -Package upgrade is a reverse proxy. +Package types is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package upgrade +package types import ( "context" @@ -51,38 +51,56 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } -var ( - filter_Query_UpgradeStatus_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - -func request_Query_UpgradeStatus_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryUpgradeStatusRequest +func request_Query_VersionTally_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVersionTallyRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["version"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "version") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_UpgradeStatus_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.Version, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "version", err) } - msg, err := client.UpgradeStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.VersionTally(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_UpgradeStatus_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryUpgradeStatusRequest +func local_request_Query_VersionTally_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVersionTallyRequest var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["version"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "version") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_UpgradeStatus_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.Version, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "version", err) } - msg, err := server.UpgradeStatus(ctx, &protoReq) + msg, err := server.VersionTally(ctx, &protoReq) return msg, metadata, err } @@ -116,7 +134,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_UpgradeStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_VersionTally_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -127,7 +145,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_UpgradeStatus_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_VersionTally_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -135,7 +153,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_UpgradeStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_VersionTally_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -200,7 +218,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_UpgradeStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_VersionTally_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -209,14 +227,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_UpgradeStatus_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_VersionTally_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_UpgradeStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_VersionTally_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -226,11 +244,11 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_UpgradeStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "status"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_VersionTally_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"upgrade", "v1", "tally", "version"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_UpgradeStatus_0 = runtime.ForwardResponseMessage + forward_Query_VersionTally_0 = runtime.ForwardResponseMessage ) diff --git a/x/upgrade/tx.pb.go b/x/upgrade/types/tx.pb.go similarity index 62% rename from x/upgrade/tx.pb.go rename to x/upgrade/types/tx.pb.go index e74d2ae6dc..6d90c31ca3 100644 --- a/x/upgrade/tx.pb.go +++ b/x/upgrade/types/tx.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: celestia/upgrade/v1/tx.proto -package upgrade +package types import ( context "context" @@ -28,24 +28,24 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgSignalUpgrade signals for an upgrade -type MsgSignalUpgrade struct { +// MsgSignalVersion signals for an upgrade +type MsgSignalVersion struct { ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` } -func (m *MsgSignalUpgrade) Reset() { *m = MsgSignalUpgrade{} } -func (m *MsgSignalUpgrade) String() string { return proto.CompactTextString(m) } -func (*MsgSignalUpgrade) ProtoMessage() {} -func (*MsgSignalUpgrade) Descriptor() ([]byte, []int) { +func (m *MsgSignalVersion) Reset() { *m = MsgSignalVersion{} } +func (m *MsgSignalVersion) String() string { return proto.CompactTextString(m) } +func (*MsgSignalVersion) ProtoMessage() {} +func (*MsgSignalVersion) Descriptor() ([]byte, []int) { return fileDescriptor_ee2a0c754324bd13, []int{0} } -func (m *MsgSignalUpgrade) XXX_Unmarshal(b []byte) error { +func (m *MsgSignalVersion) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgSignalUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSignalVersion) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgSignalUpgrade.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSignalVersion.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -55,49 +55,49 @@ func (m *MsgSignalUpgrade) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } -func (m *MsgSignalUpgrade) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSignalUpgrade.Merge(m, src) +func (m *MsgSignalVersion) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSignalVersion.Merge(m, src) } -func (m *MsgSignalUpgrade) XXX_Size() int { +func (m *MsgSignalVersion) XXX_Size() int { return m.Size() } -func (m *MsgSignalUpgrade) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSignalUpgrade.DiscardUnknown(m) +func (m *MsgSignalVersion) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSignalVersion.DiscardUnknown(m) } -var xxx_messageInfo_MsgSignalUpgrade proto.InternalMessageInfo +var xxx_messageInfo_MsgSignalVersion proto.InternalMessageInfo -func (m *MsgSignalUpgrade) GetValidatorAddress() string { +func (m *MsgSignalVersion) GetValidatorAddress() string { if m != nil { return m.ValidatorAddress } return "" } -func (m *MsgSignalUpgrade) GetVersion() uint64 { +func (m *MsgSignalVersion) GetVersion() uint64 { if m != nil { return m.Version } return 0 } -// MsgSignalUpgradeResponse describes the response returned after the submission -// of a SignalUpgrade -type MsgSignalUpgradeResponse struct { +// MsgSignalVersionResponse describes the response returned after the submission +// of a SignalVersion +type MsgSignalVersionResponse struct { } -func (m *MsgSignalUpgradeResponse) Reset() { *m = MsgSignalUpgradeResponse{} } -func (m *MsgSignalUpgradeResponse) String() string { return proto.CompactTextString(m) } -func (*MsgSignalUpgradeResponse) ProtoMessage() {} -func (*MsgSignalUpgradeResponse) Descriptor() ([]byte, []int) { +func (m *MsgSignalVersionResponse) Reset() { *m = MsgSignalVersionResponse{} } +func (m *MsgSignalVersionResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSignalVersionResponse) ProtoMessage() {} +func (*MsgSignalVersionResponse) Descriptor() ([]byte, []int) { return fileDescriptor_ee2a0c754324bd13, []int{1} } -func (m *MsgSignalUpgradeResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgSignalVersionResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgSignalUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgSignalVersionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgSignalUpgradeResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgSignalVersionResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -107,45 +107,45 @@ func (m *MsgSignalUpgradeResponse) XXX_Marshal(b []byte, deterministic bool) ([] return b[:n], nil } } -func (m *MsgSignalUpgradeResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgSignalUpgradeResponse.Merge(m, src) +func (m *MsgSignalVersionResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSignalVersionResponse.Merge(m, src) } -func (m *MsgSignalUpgradeResponse) XXX_Size() int { +func (m *MsgSignalVersionResponse) XXX_Size() int { return m.Size() } -func (m *MsgSignalUpgradeResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgSignalUpgradeResponse.DiscardUnknown(m) +func (m *MsgSignalVersionResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSignalVersionResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgSignalUpgradeResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgSignalVersionResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgSignalUpgrade)(nil), "celestia.upgrade.v1.MsgSignalUpgrade") - proto.RegisterType((*MsgSignalUpgradeResponse)(nil), "celestia.upgrade.v1.MsgSignalUpgradeResponse") + proto.RegisterType((*MsgSignalVersion)(nil), "celestia.upgrade.v1.MsgSignalVersion") + proto.RegisterType((*MsgSignalVersionResponse)(nil), "celestia.upgrade.v1.MsgSignalVersionResponse") } func init() { proto.RegisterFile("celestia/upgrade/v1/tx.proto", fileDescriptor_ee2a0c754324bd13) } var fileDescriptor_ee2a0c754324bd13 = []byte{ - // 280 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x49, 0x4e, 0xcd, 0x49, - 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, - 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xc9, 0xea, 0x41, 0x65, 0xf5, - 0xca, 0x0c, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, 0x13, - 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0x5a, 0x94, 0x22, 0xb9, 0x04, - 0x7c, 0x8b, 0xd3, 0x83, 0x33, 0xd3, 0xf3, 0x12, 0x73, 0x42, 0x21, 0x9a, 0x84, 0xb4, 0xb9, 0x04, - 0xcb, 0x12, 0x73, 0x32, 0x53, 0x12, 0x4b, 0xf2, 0x8b, 0xe2, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, - 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x04, 0xe0, 0x12, 0x8e, 0x10, 0x71, 0x21, 0x09, - 0x2e, 0xf6, 0xb2, 0xd4, 0xa2, 0xe2, 0xcc, 0xfc, 0x3c, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x96, 0x20, - 0x18, 0x57, 0x49, 0x8a, 0x4b, 0x02, 0xdd, 0xe8, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, - 0xa3, 0x4e, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x46, 0x46, 0x2e, 0x5e, 0x54, 0xcb, 0x55, - 0xf5, 0xb0, 0x78, 0x42, 0x0f, 0xdd, 0x20, 0x29, 0x5d, 0xa2, 0x94, 0xc1, 0xec, 0x53, 0x92, 0x6a, - 0xba, 0xfc, 0x64, 0x32, 0x93, 0x88, 0x90, 0x10, 0x72, 0xb8, 0x15, 0x83, 0x95, 0x3a, 0xb9, 0x9f, - 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, 0x6e, 0x7a, 0x66, 0x49, 0x46, 0x69, - 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xcc, 0xba, 0xfc, 0xa2, 0x74, 0x38, 0x5b, 0x37, 0xb1, 0xa0, - 0x40, 0xbf, 0x02, 0x66, 0x64, 0x12, 0x1b, 0x38, 0x48, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, - 0xb9, 0x4f, 0xa1, 0xbc, 0xa5, 0x01, 0x00, 0x00, + // 283 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x50, 0x3f, 0x4b, 0x03, 0x31, + 0x14, 0x6f, 0xaa, 0x28, 0x06, 0x84, 0x1a, 0x1d, 0x8e, 0xa3, 0x84, 0x52, 0x10, 0x0a, 0xd2, 0x84, + 0xda, 0x4f, 0xa0, 0xfb, 0x2d, 0x27, 0x08, 0xba, 0x48, 0xda, 0x0b, 0x31, 0x70, 0x26, 0x21, 0x2f, + 0x3d, 0xea, 0xa8, 0x9b, 0x9b, 0xe0, 0x97, 0x72, 0x2c, 0xb8, 0x38, 0xca, 0x9d, 0x1f, 0x44, 0xe8, + 0x79, 0x87, 0x16, 0x07, 0xb7, 0xf7, 0xde, 0xef, 0x1f, 0xef, 0x87, 0xfb, 0x73, 0x99, 0x4b, 0x08, + 0x5a, 0xf0, 0x85, 0x53, 0x5e, 0x64, 0x92, 0x17, 0x13, 0x1e, 0x96, 0xcc, 0x79, 0x1b, 0x2c, 0x39, + 0x6c, 0x50, 0xf6, 0x8d, 0xb2, 0x62, 0x12, 0xf7, 0x95, 0xb5, 0x2a, 0x97, 0x5c, 0x38, 0xcd, 0x85, + 0x31, 0x36, 0x88, 0xa0, 0xad, 0x81, 0x5a, 0x32, 0xbc, 0xc2, 0xbd, 0x04, 0xd4, 0x85, 0x56, 0x46, + 0xe4, 0x97, 0xd2, 0x83, 0xb6, 0x86, 0x9c, 0xe0, 0x83, 0x42, 0xe4, 0x3a, 0x13, 0xc1, 0xfa, 0x1b, + 0x91, 0x65, 0x5e, 0x02, 0x44, 0x68, 0x80, 0x46, 0x7b, 0x69, 0xaf, 0x05, 0xce, 0xea, 0x3b, 0x89, + 0xf0, 0x6e, 0x51, 0xeb, 0xa2, 0xee, 0x00, 0x8d, 0xb6, 0xd3, 0x66, 0x1d, 0xc6, 0x38, 0xda, 0xb4, + 0x4e, 0x25, 0x38, 0x6b, 0x40, 0x9e, 0x3e, 0x21, 0xbc, 0x95, 0x80, 0x22, 0x0f, 0x08, 0xef, 0xff, + 0x0e, 0x3f, 0x66, 0x7f, 0x3c, 0xc1, 0x36, 0x8d, 0xe2, 0xf1, 0xbf, 0x68, 0x4d, 0xde, 0x30, 0x7e, + 0x7c, 0xfb, 0x7c, 0xe9, 0x1e, 0x11, 0xf2, 0xb3, 0x37, 0x58, 0x53, 0xcf, 0x93, 0xd7, 0x92, 0xa2, + 0x55, 0x49, 0xd1, 0x47, 0x49, 0xd1, 0x73, 0x45, 0x3b, 0xab, 0x8a, 0x76, 0xde, 0x2b, 0xda, 0xb9, + 0x9e, 0x2a, 0x1d, 0x6e, 0x17, 0x33, 0x36, 0xb7, 0x77, 0xbc, 0x89, 0xb3, 0x5e, 0xb5, 0xf3, 0x58, + 0x38, 0xc7, 0x97, 0xad, 0x65, 0xb8, 0x77, 0x12, 0x66, 0x3b, 0xeb, 0x62, 0xa7, 0x5f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x56, 0x99, 0x88, 0x28, 0xab, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -160,8 +160,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - // SignalUpgrade allows the validator to signal for an upgrade - SignalUpgrade(ctx context.Context, in *MsgSignalUpgrade, opts ...grpc.CallOption) (*MsgSignalUpgradeResponse, error) + // SignalVersion allows the validator to signal for an upgrade + SignalVersion(ctx context.Context, in *MsgSignalVersion, opts ...grpc.CallOption) (*MsgSignalVersionResponse, error) } type msgClient struct { @@ -172,9 +172,9 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } -func (c *msgClient) SignalUpgrade(ctx context.Context, in *MsgSignalUpgrade, opts ...grpc.CallOption) (*MsgSignalUpgradeResponse, error) { - out := new(MsgSignalUpgradeResponse) - err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Msg/SignalUpgrade", in, out, opts...) +func (c *msgClient) SignalVersion(ctx context.Context, in *MsgSignalVersion, opts ...grpc.CallOption) (*MsgSignalVersionResponse, error) { + out := new(MsgSignalVersionResponse) + err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Msg/SignalVersion", in, out, opts...) if err != nil { return nil, err } @@ -183,36 +183,36 @@ func (c *msgClient) SignalUpgrade(ctx context.Context, in *MsgSignalUpgrade, opt // MsgServer is the server API for Msg service. type MsgServer interface { - // SignalUpgrade allows the validator to signal for an upgrade - SignalUpgrade(context.Context, *MsgSignalUpgrade) (*MsgSignalUpgradeResponse, error) + // SignalVersion allows the validator to signal for an upgrade + SignalVersion(context.Context, *MsgSignalVersion) (*MsgSignalVersionResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } -func (*UnimplementedMsgServer) SignalUpgrade(ctx context.Context, req *MsgSignalUpgrade) (*MsgSignalUpgradeResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method SignalUpgrade not implemented") +func (*UnimplementedMsgServer) SignalVersion(ctx context.Context, req *MsgSignalVersion) (*MsgSignalVersionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SignalVersion not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } -func _Msg_SignalUpgrade_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgSignalUpgrade) +func _Msg_SignalVersion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSignalVersion) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).SignalUpgrade(ctx, in) + return srv.(MsgServer).SignalVersion(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.upgrade.v1.Msg/SignalUpgrade", + FullMethod: "/celestia.upgrade.v1.Msg/SignalVersion", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).SignalUpgrade(ctx, req.(*MsgSignalUpgrade)) + return srv.(MsgServer).SignalVersion(ctx, req.(*MsgSignalVersion)) } return interceptor(ctx, in, info, handler) } @@ -222,15 +222,15 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "SignalUpgrade", - Handler: _Msg_SignalUpgrade_Handler, + MethodName: "SignalVersion", + Handler: _Msg_SignalVersion_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "celestia/upgrade/v1/tx.proto", } -func (m *MsgSignalUpgrade) Marshal() (dAtA []byte, err error) { +func (m *MsgSignalVersion) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -240,12 +240,12 @@ func (m *MsgSignalUpgrade) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSignalUpgrade) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSignalVersion) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSignalUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSignalVersion) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -265,7 +265,7 @@ func (m *MsgSignalUpgrade) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgSignalUpgradeResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgSignalVersionResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -275,12 +275,12 @@ func (m *MsgSignalUpgradeResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgSignalUpgradeResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgSignalVersionResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgSignalUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgSignalVersionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -299,7 +299,7 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *MsgSignalUpgrade) Size() (n int) { +func (m *MsgSignalVersion) Size() (n int) { if m == nil { return 0 } @@ -315,7 +315,7 @@ func (m *MsgSignalUpgrade) Size() (n int) { return n } -func (m *MsgSignalUpgradeResponse) Size() (n int) { +func (m *MsgSignalVersionResponse) Size() (n int) { if m == nil { return 0 } @@ -330,7 +330,7 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *MsgSignalUpgrade) Unmarshal(dAtA []byte) error { +func (m *MsgSignalVersion) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -353,10 +353,10 @@ func (m *MsgSignalUpgrade) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSignalUpgrade: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSignalVersion: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSignalUpgrade: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSignalVersion: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -431,7 +431,7 @@ func (m *MsgSignalUpgrade) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgSignalUpgradeResponse) Unmarshal(dAtA []byte) error { +func (m *MsgSignalVersionResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -454,10 +454,10 @@ func (m *MsgSignalUpgradeResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgSignalUpgradeResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgSignalVersionResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgSignalUpgradeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgSignalVersionResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: diff --git a/x/upgrade/tx.pb.gw.go b/x/upgrade/types/tx.pb.gw.go similarity index 84% rename from x/upgrade/tx.pb.gw.go rename to x/upgrade/types/tx.pb.gw.go index 1d7b9b3a3f..496e87adf0 100644 --- a/x/upgrade/tx.pb.gw.go +++ b/x/upgrade/types/tx.pb.gw.go @@ -2,11 +2,11 @@ // source: celestia/upgrade/v1/tx.proto /* -Package upgrade is a reverse proxy. +Package types is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package upgrade +package types import ( "context" @@ -34,37 +34,37 @@ var _ = descriptor.ForMessage var _ = metadata.Join var ( - filter_Msg_SignalUpgrade_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_Msg_SignalVersion_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_Msg_SignalUpgrade_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgSignalUpgrade +func request_Msg_SignalVersion_0(ctx context.Context, marshaler runtime.Marshaler, client MsgClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSignalVersion var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalUpgrade_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalVersion_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.SignalUpgrade(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.SignalVersion(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Msg_SignalUpgrade_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq MsgSignalUpgrade +func local_request_Msg_SignalVersion_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq MsgSignalVersion var metadata runtime.ServerMetadata if err := req.ParseForm(); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalUpgrade_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Msg_SignalVersion_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.SignalUpgrade(ctx, &protoReq) + msg, err := server.SignalVersion(ctx, &protoReq) return msg, metadata, err } @@ -75,7 +75,7 @@ func local_request_Msg_SignalUpgrade_0(ctx context.Context, marshaler runtime.Ma // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { - mux.Handle("GET", pattern_Msg_SignalUpgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -86,7 +86,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Msg_SignalUpgrade_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Msg_SignalVersion_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -94,7 +94,7 @@ func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server return } - forward_Msg_SignalUpgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Msg_SignalVersion_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -139,7 +139,7 @@ func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.C // "MsgClient" to call the correct interceptors. func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { - mux.Handle("GET", pattern_Msg_SignalUpgrade_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -148,14 +148,14 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Msg_SignalUpgrade_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Msg_SignalVersion_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Msg_SignalUpgrade_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Msg_SignalVersion_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -163,9 +163,9 @@ func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client } var ( - pattern_Msg_SignalUpgrade_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "signal"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Msg_SignalVersion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "signal"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Msg_SignalUpgrade_0 = runtime.ForwardResponseMessage + forward_Msg_SignalVersion_0 = runtime.ForwardResponseMessage ) From f4e5489dc7af04ab495f9e62cacba8e372eec856 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 20 Nov 2023 15:48:40 +0100 Subject: [PATCH 15/26] resolve conflicts --- .github/workflows/nightly.yml | 13 +----- .github/workflows/test.yml | 12 +++++ Dockerfile | 2 +- Makefile | 4 +- app/app.go | 20 +++------ go.mod | 16 +++---- go.sum | 36 +++++++-------- scripts/protocgen.sh | 5 --- test/e2e/node.go | 8 +++- test/e2e/readme.md | 6 ++- test/e2e/setup.go | 1 + test/e2e/simple_test.go | 20 ++++++--- test/e2e/testnet.go | 14 +++--- test/e2e/upgrade_test.go | 85 ++++++++++++++++++++++++++++++++++- test/e2e/versions.go | 41 +++++++++++------ test/txsim/run.go | 7 +++ x/blob/module.go | 6 ++- x/blobstream/module.go | 6 ++- x/upgrade/keeper.go | 6 +++ 19 files changed, 215 insertions(+), 93 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 40c64da4a2..116722ee89 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -27,14 +27,5 @@ jobs: - name: Run e2e tests run: make test-e2e - test-fuzz: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-go@v4 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Run fuzz tests - run: make test-fuzz + test: + uses: ./.github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 252af1b999..27f3164d1c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,3 +59,15 @@ jobs: - name: Run tests in race mode run: make test-race + + test-fuzz: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Run fuzz tests + run: make test-fuzz diff --git a/Dockerfile b/Dockerfile index 1c3640e375..c9759df126 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # stage 1 Generate celestia-appd Binary -FROM --platform=$BUILDPLATFORM docker.io/golang:1.21.3-alpine3.18 as builder +FROM --platform=$BUILDPLATFORM docker.io/golang:1.21.4-alpine3.18 as builder ARG TARGETOS ARG TARGETARCH diff --git a/Makefile b/Makefile index 918a1e639e..9f66f9035d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION := $(shell echo $(shell git describe --tags 2>/dev/null || git log -1 --format='%h') | sed 's/^v//') -COMMIT := $(shell git log -1 --format='%H') +COMMIT := $(shell git rev-parse --short HEAD) DOCKER := $(shell which docker) ALL_VERSIONS := $(shell git tag -l) DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf @@ -119,7 +119,7 @@ test-short: ## test-e2e: Run end to end tests via knuu. This command requires a kube/config file to configure kubernetes. test-e2e: @echo "--> Running end to end tests" - @KNUU_NAMESPACE=test KNUU_TIMEOUT=20m E2E_VERSIONS="$(ALL_VERSIONS)" E2E=true go test ./test/e2e/... -timeout 20m -v + @KNUU_NAMESPACE=test KNUU_TIMEOUT=20m E2E_LATEST_VERSION=$(shell git rev-parse --short main) E2E_VERSIONS="$(ALL_VERSIONS)" E2E=true go test ./test/e2e/... -timeout 20m -v .PHONY: test-e2e ## test-race: Run tests in race mode. diff --git a/app/app.go b/app/app.go index 7bb42c5474..002c147f20 100644 --- a/app/app.go +++ b/app/app.go @@ -86,7 +86,6 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/pkg/proof" blobmodule "github.com/celestiaorg/celestia-app/x/blob" @@ -336,7 +335,7 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], upgradeHeight, app.StakingKeeper, app.GetSubspace(upgradetypes.ModuleName)) + app.UpgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], upgradeHeight) app.BlobstreamKeeper = *bsmodulekeeper.NewKeeper( appCodec, @@ -576,19 +575,10 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker application updates every end block func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { res := app.mm.EndBlock(ctx, req) - - // handle upgrade logic - switch ctx.BlockHeader().Version.App { - case v1.Version: - // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected - // to be coordinated through the signalling protocol - if app.UpgradeKeeper.ShouldUpgradeToV2(req.Height) { - app.SetProtocolVersion(v2.Version) - } - default: - if ready, version := app.UpgradeKeeper.ShouldUpgrade(); ready { - app.SetProtocolVersion(version) - } + // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected + // to be coordinated through the signalling protocol + if app.UpgradeKeeper.ShouldUpgrade(req.Height) { + app.SetProtocolVersion(v2.Version) } return res } diff --git a/go.mod b/go.mod index bb7733f3b7..81c1a340b5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.1 require ( github.com/celestiaorg/nmt v0.20.0 - github.com/ethereum/go-ethereum v1.13.4 + github.com/ethereum/go-ethereum v1.13.5 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.3 github.com/google/uuid v1.3.1 // indirect @@ -25,7 +25,7 @@ require ( require ( cosmossdk.io/errors v1.0.0-beta.7 - cosmossdk.io/math v1.1.2 + cosmossdk.io/math v1.2.0 github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 github.com/celestiaorg/rsmt2d v0.11.0 github.com/cosmos/cosmos-proto v1.0.0-alpha8 @@ -45,12 +45,12 @@ require ( github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/cosmos/ledger-cosmos-go v0.13.2 // indirect - github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect + github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect - github.com/ethereum/c-kzg-4844 v0.3.1 // indirect + github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -84,9 +84,9 @@ require ( golang.org/x/tools v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c // indirect gopkg.in/inf.v0 v0.9.1 // indirect - k8s.io/api v0.28.2 // indirect - k8s.io/apimachinery v0.28.2 // indirect - k8s.io/client-go v0.28.2 // indirect + k8s.io/api v0.28.3 // indirect + k8s.io/apimachinery v0.28.3 // indirect + k8s.io/client-go v0.28.3 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect @@ -113,7 +113,7 @@ require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect - github.com/celestiaorg/knuu v0.9.0 + github.com/celestiaorg/knuu v0.10.0 github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect diff --git a/go.sum b/go.sum index b9c84e9707..74b2baa708 100644 --- a/go.sum +++ b/go.sum @@ -193,8 +193,8 @@ cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoIS collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= -cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= -cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= +cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= +cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -324,8 +324,8 @@ github.com/celestiaorg/celestia-core v1.29.0-tm-v0.34.29 h1:Fd7ymPUzExPGNl2gZw4i github.com/celestiaorg/celestia-core v1.29.0-tm-v0.34.29/go.mod h1:xrICN0PBhp3AdTaZ8q4wS5Jvi32V02HNjaC2EsWiEKk= github.com/celestiaorg/cosmos-sdk v1.18.3-sdk-v0.46.14 h1:+Te28r5Zp4Vp69f82kcON9/BIF8f1BNXb0go2+achuc= github.com/celestiaorg/cosmos-sdk v1.18.3-sdk-v0.46.14/go.mod h1:Og5KKgoBEiQlI6u56lDLG191pfknIdXctFn3COWLQP8= -github.com/celestiaorg/knuu v0.9.0 h1:tS8iBSL/Gf6MI8OMf4etU2tU442jMowxaVMmYBnyLKs= -github.com/celestiaorg/knuu v0.9.0/go.mod h1:zf8wNZd756l6S2tBx3DDQ0V9CLstDkP/VRYzqSGVUrQ= +github.com/celestiaorg/knuu v0.10.0 h1:uYO6hVsoCAJ/Q4eV0Pn8CLbbupGAjD56xQc4y2t4lf0= +github.com/celestiaorg/knuu v0.10.0/go.mod h1:2NjDX29x09hRpaaWaKvi7pw9VjI/SHo+/4HldyEW50g= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= github.com/celestiaorg/nmt v0.20.0 h1:9i7ultZ8Wv5ytt8ZRaxKQ5KOOMo4A2K2T/aPGjIlSas= @@ -427,8 +427,8 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= -github.com/crate-crypto/go-kzg-4844 v0.3.0/go.mod h1:SBP7ikXEgDnUPONgm33HtuDZEDtWa3L4QtN1ocJSEQ4= +github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= +github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM= github.com/creachadair/taskgroup v0.3.2/go.mod h1:wieWwecHVzsidg2CsUnFinW1faVN4+kq+TDlRJQ0Wbk= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= @@ -505,11 +505,11 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= -github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY= +github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/ethereum/go-ethereum v1.10.17/go.mod h1:Lt5WzjM07XlXc95YzrhosmR4J9Ahd6X2wyEV2SvGhk0= -github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM= -github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q= +github.com/ethereum/go-ethereum v1.13.5 h1:U6TCRciCqZRe4FPXmy1sMGxTfuk8P7u2UoinF3VbaFk= +github.com/ethereum/go-ethereum v1.13.5/go.mod h1:yMTu38GSuyxaYzQMViqNmQ1s3cE84abZexQmTgenWk0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= @@ -2037,8 +2037,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= -gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= -gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -2048,12 +2048,12 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= -k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= -k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= -k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= -k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= -k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= -k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= +k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM= +k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc= +k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= +k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= +k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4= +k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 670da62783..c2fc4e0253 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -23,11 +23,6 @@ done cd .. -# temporary import hack to use cosmos-sdk implementation of Any type. -# check https://github.com/celestiaorg/celestia-app/issues/507 for more information. -sed -i 's/types "github.com\/celestiaorg\/celestia-app\/codec\/types"/types "github.com\/cosmos\/cosmos-sdk\/codec\/types"/g' \ - github.com/celestiaorg/celestia-app/x/blobstream/types/query.pb.go - # move proto files to the right places cp -r github.com/celestiaorg/celestia-app/* ./ rm -rf github.com diff --git a/test/e2e/node.go b/test/e2e/node.go index c73c45dcb7..7e3c84866e 100644 --- a/test/e2e/node.go +++ b/test/e2e/node.go @@ -45,6 +45,7 @@ func NewNode( startHeight, selfDelegation int64, peers []string, signerKey, networkKey, accountKey crypto.PrivKey, + upgradeHeight int64, ) (*Node, error) { instance, err := knuu.NewInstance(name) if err != nil { @@ -75,7 +76,12 @@ func NewNode( if err != nil { return nil, err } - err = instance.SetArgs("start", fmt.Sprintf("--home=%s", remoteRootDir), "--rpc.laddr=tcp://0.0.0.0:26657") + args := []string{"start", fmt.Sprintf("--home=%s", remoteRootDir), "--rpc.laddr=tcp://0.0.0.0:26657"} + if upgradeHeight != 0 { + args = append(args, fmt.Sprintf("--v2-upgrade-height=%d", upgradeHeight)) + } + + err = instance.SetArgs(args...) if err != nil { return nil, err } diff --git a/test/e2e/readme.md b/test/e2e/readme.md index 6a20d3b72e..acdec30c7c 100644 --- a/test/e2e/readme.md +++ b/test/e2e/readme.md @@ -7,9 +7,11 @@ Celestia uses the [knuu](https://github.com/celestiaorg/knuu) framework to orche E2E tests can be simply run through go tests. They are distinguished from unit tets through an environment variable. To run all e2e tests run: ```shell -E2E=true KNUU_NAMESPACE=test go test ./test/e2e/... -timeout 30m +E2E=true KNUU_NAMESPACE=test E2E_LATEST_VERSION="$(git rev-parse --short main)" E2E_VERSIONS="$(git tag -l)" go test ./test/e2e/... -timeout 30m -v ``` +You can optionally set a global timeout using `KNUU_TIMEOUT` (default is 60m). + ## Observation -Logs of each of the nodes are posted to Grafana and can be accessed through Celestia's dashboard (using the `celestia-app` namespace). +Logs of each of the nodes are posted to Grafana and can be accessed through Celestia's dashboard (using the `test` namespace). diff --git a/test/e2e/setup.go b/test/e2e/setup.go index 709c410876..a58118409e 100644 --- a/test/e2e/setup.go +++ b/test/e2e/setup.go @@ -140,6 +140,7 @@ func MakeConfig(node *Node) (*config.Config, error) { cfg.P2P.PersistentPeers = strings.Join(node.InitialPeers, ",") cfg.Consensus.TimeoutPropose = time.Second cfg.Consensus.TimeoutCommit = time.Second + cfg.Instrumentation.Prometheus = true return cfg, nil } diff --git a/test/e2e/simple_test.go b/test/e2e/simple_test.go index 0843e1e1ba..1e7843ab85 100644 --- a/test/e2e/simple_test.go +++ b/test/e2e/simple_test.go @@ -9,6 +9,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" + v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" "github.com/celestiaorg/celestia-app/test/txsim" "github.com/celestiaorg/celestia-app/test/util/testnode" "github.com/stretchr/testify/require" @@ -26,11 +27,17 @@ func TestE2ESimple(t *testing.T) { t.Skip("skipping e2e test") } - if os.Getenv("E2E_VERSIONS") != "" { - versionsStr := os.Getenv("E2E_VERSIONS") - versions := ParseVersions(versionsStr) - if len(versions) > 0 { - latestVersion = versions.GetLatest().String() + if os.Getenv("E2E_LATEST_VERSION") != "" { + latestVersion = os.Getenv("E2E_LATEST_VERSION") + _, isSemVer := ParseVersion(latestVersion) + switch { + case isSemVer: + case latestVersion == "latest": + case len(latestVersion) == 8: + // assume this is a git commit hash (we need to trim the last digit to match the docker image tag) + latestVersion = latestVersion[:7] + default: + t.Fatalf("unrecognised version: %s", latestVersion) } } t.Log("Running simple e2e test", "version", latestVersion) @@ -38,7 +45,7 @@ func TestE2ESimple(t *testing.T) { testnet, err := New(t.Name(), seed) require.NoError(t, err) t.Cleanup(testnet.Cleanup) - require.NoError(t, testnet.CreateGenesisNodes(4, latestVersion, 10000000)) + require.NoError(t, testnet.CreateGenesisNodes(4, latestVersion, 10000000, 0)) kr, err := testnet.CreateAccount("alice", 1e12) require.NoError(t, err) @@ -61,6 +68,7 @@ func TestE2ESimple(t *testing.T) { totalTxs := 0 for _, block := range blockchain { + require.Equal(t, v1.Version, block.Version.App) totalTxs += len(block.Data.Txs) } require.Greater(t, totalTxs, 10) diff --git a/test/e2e/testnet.go b/test/e2e/testnet.go index 3bda11279e..1bbb5ee804 100644 --- a/test/e2e/testnet.go +++ b/test/e2e/testnet.go @@ -34,11 +34,11 @@ func New(name string, seed int64) (*Testnet, error) { }, nil } -func (t *Testnet) CreateGenesisNode(version string, selfDelegation int64) error { +func (t *Testnet) CreateGenesisNode(version string, selfDelegation, upgradeHeight int64) error { signerKey := t.keygen.Generate(ed25519Type) networkKey := t.keygen.Generate(ed25519Type) accountKey := t.keygen.Generate(secp256k1Type) - node, err := NewNode(fmt.Sprintf("val%d", len(t.nodes)), version, 0, selfDelegation, nil, signerKey, networkKey, accountKey) + node, err := NewNode(fmt.Sprintf("val%d", len(t.nodes)), version, 0, selfDelegation, nil, signerKey, networkKey, accountKey, upgradeHeight) if err != nil { return err } @@ -46,20 +46,20 @@ func (t *Testnet) CreateGenesisNode(version string, selfDelegation int64) error return nil } -func (t *Testnet) CreateGenesisNodes(num int, version string, selfDelegation int64) error { - for i := -0; i < num; i++ { - if err := t.CreateGenesisNode(version, selfDelegation); err != nil { +func (t *Testnet) CreateGenesisNodes(num int, version string, selfDelegation, upgradeHeight int64) error { + for i := 0; i < num; i++ { + if err := t.CreateGenesisNode(version, selfDelegation, upgradeHeight); err != nil { return err } } return nil } -func (t *Testnet) CreateNode(version string, startHeight int64) error { +func (t *Testnet) CreateNode(version string, startHeight, upgradeHeight int64) error { signerKey := t.keygen.Generate(ed25519Type) networkKey := t.keygen.Generate(ed25519Type) accountKey := t.keygen.Generate(secp256k1Type) - node, err := NewNode(fmt.Sprintf("val%d", len(t.nodes)), version, startHeight, 0, nil, signerKey, networkKey, accountKey) + node, err := NewNode(fmt.Sprintf("val%d", len(t.nodes)), version, startHeight, 0, nil, signerKey, networkKey, accountKey, upgradeHeight) if err != nil { return err } diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index ebbc7d3c1f..05d5efad34 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -11,6 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" + v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/test/txsim" "github.com/celestiaorg/knuu/pkg/knuu" "github.com/stretchr/testify/require" @@ -55,7 +56,7 @@ func TestMinorVersionCompatibility(t *testing.T) { // each node begins with a random version within the same major version set v := versions.Random(r).String() t.Log("Starting node", "node", i, "version", v) - require.NoError(t, testnet.CreateGenesisNode(v, 10000000)) + require.NoError(t, testnet.CreateGenesisNode(v, 10000000, 0)) } kr, err := testnet.CreateAccount("alice", 1e12) @@ -64,6 +65,7 @@ func TestMinorVersionCompatibility(t *testing.T) { require.NoError(t, testnet.Setup()) require.NoError(t, testnet.Start()) + // TODO: with upgrade tests we should simulate a far broader range of transactions sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5) sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...) @@ -121,6 +123,87 @@ func TestMinorVersionCompatibility(t *testing.T) { require.True(t, errors.Is(err, context.Canceled), err.Error()) } +func TestMajorUpgradeToV2(t *testing.T) { + if os.Getenv("E2E") == "" { + t.Skip("skipping e2e test") + } + + if os.Getenv("E2E_LATEST_VERSION") != "" { + latestVersion = os.Getenv("E2E_LATEST_VERSION") + _, isSemVer := ParseVersion(latestVersion) + switch { + case isSemVer: + case latestVersion == "latest": + case len(latestVersion) == 8: + // assume this is a git commit hash (we need to trim the last digit to match the docker image tag) + latestVersion = latestVersion[:7] + default: + t.Fatalf("unrecognised version: %s", latestVersion) + } + } + + numNodes := 4 + upgradeHeight := int64(10) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + testnet, err := New(t.Name(), seed) + require.NoError(t, err) + t.Cleanup(testnet.Cleanup) + + preloader, err := knuu.NewPreloader() + require.NoError(t, err) + t.Cleanup(func() { _ = preloader.EmptyImages() }) + err = preloader.AddImage(DockerImageName(latestVersion)) + require.NoError(t, err) + + for i := 0; i < numNodes; i++ { + t.Log("Starting node", "node", i, "version", latestVersion) + require.NoError(t, testnet.CreateGenesisNode(latestVersion, 10000000, upgradeHeight)) + } + + kr, err := testnet.CreateAccount("alice", 1e12) + require.NoError(t, err) + + require.NoError(t, testnet.Setup()) + require.NoError(t, testnet.Start()) + + // assert that the network is initially running on v1 + for i := 0; i < numNodes; i++ { + client, err := testnet.Node(i).Client() + require.NoError(t, err) + resp, err := client.Header(ctx, nil) + require.NoError(t, err) + // FIXME: we are not correctly setting the app version at genesis + require.Equal(t, uint64(0), resp.Header.Version.App, "version mismatch before upgrade") + } + + errCh := make(chan error) + encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) + opts := txsim.DefaultOptions().WithSeed(seed).SuppressLogs() + sequences := txsim.NewBlobSequence(txsim.NewRange(200, 4000), txsim.NewRange(1, 3)).Clone(5) + sequences = append(sequences, txsim.NewSendSequence(4, 1000, 100).Clone(5)...) + go func() { + errCh <- txsim.Run(ctx, testnet.GRPCEndpoints()[0], kr, encCfg, opts, sequences...) + }() + + // wait for all nodes to move past the upgrade height + for i := 0; i < numNodes; i++ { + client, err := testnet.Node(i).Client() + require.NoError(t, err) + require.NoError(t, waitForHeight(ctx, client, upgradeHeight+2, time.Minute)) + resp, err := client.Header(ctx, nil) + require.NoError(t, err) + require.Equal(t, v2.Version, resp.Header.Version.App, "version mismatch after upgrade") + } + + // end txsim + cancel() + + err = <-errCh + require.True(t, errors.Is(err, context.Canceled), err.Error()) +} + func getHeight(ctx context.Context, client *http.HTTP, period time.Duration) (int64, error) { timer := time.NewTimer(period) ticker := time.NewTicker(100 * time.Millisecond) diff --git a/test/e2e/versions.go b/test/e2e/versions.go index 4d3329a2c8..51e0f5c329 100644 --- a/test/e2e/versions.go +++ b/test/e2e/versions.go @@ -40,29 +40,42 @@ func (v Version) IsGreater(v2 Version) bool { type VersionSet []Version +// ParseVersions takes a string of space-separated versions and returns a +// VersionSet. Invalid versions are ignored. func ParseVersions(versionStr string) VersionSet { versions := strings.Split(versionStr, " ") output := make(VersionSet, 0, len(versions)) for _, v := range versions { - var major, minor, patch, rc uint64 - isRC := false - if strings.Contains(v, "rc") { - _, err := fmt.Sscanf(v, "v%d.%d.%d-rc%d", &major, &minor, &patch, &rc) - isRC = true - if err != nil { - continue - } - } else { - _, err := fmt.Sscanf(v, "v%d.%d.%d", &major, &minor, &patch) - if err != nil { - continue - } + version, isValid := ParseVersion(v) + if !isValid { + continue } - output = append(output, Version{major, minor, patch, isRC, rc}) + output = append(output, version) } return output } +// ParseVersion takes a string and returns a Version. If the string is not a +// valid version, the second return value is false. +// Must be of the format v1.0.0 or v1.0.0-rc1 (i.e. following SemVer) +func ParseVersion(version string) (Version, bool) { + var major, minor, patch, rc uint64 + isRC := false + if strings.Contains(version, "rc") { + _, err := fmt.Sscanf(version, "v%d.%d.%d-rc%d", &major, &minor, &patch, &rc) + isRC = true + if err != nil { + return Version{}, false + } + } else { + _, err := fmt.Sscanf(version, "v%d.%d.%d", &major, &minor, &patch) + if err != nil { + return Version{}, false + } + } + return Version{major, minor, patch, isRC, rc}, true +} + func (v VersionSet) FilterMajor(majorVersion uint64) VersionSet { output := make(VersionSet, 0, len(v)) for _, version := range v { diff --git a/test/txsim/run.go b/test/txsim/run.go index d25f471f0d..c20bad99f0 100644 --- a/test/txsim/run.go +++ b/test/txsim/run.go @@ -101,10 +101,17 @@ func Run( log.Info().Err(err).Msg("sequence terminated") continue } + if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + continue + } log.Error().Err(err).Msg("sequence failed") finalErr = err } + if ctx.Err() != nil { + return ctx.Err() + } + return finalErr } diff --git a/x/blob/module.go b/x/blob/module.go index 74f1c06bf0..eaa8612894 100644 --- a/x/blob/module.go +++ b/x/blob/module.go @@ -1,6 +1,7 @@ package blob import ( + "context" "encoding/json" "fmt" @@ -75,7 +76,10 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the capability module's root tx command. diff --git a/x/blobstream/module.go b/x/blobstream/module.go index 0a18fc8ede..481697b4fd 100644 --- a/x/blobstream/module.go +++ b/x/blobstream/module.go @@ -1,6 +1,7 @@ package blobstream import ( + "context" "encoding/json" "fmt" @@ -76,7 +77,10 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. -func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) { +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } } // GetTxCmd returns the capability module's root tx command. diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index d76cd748a8..26ddbbd6cf 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -194,3 +194,9 @@ func VersionToBytes(version uint64) []byte { func VersionFromBytes(version []byte) uint64 { return binary.BigEndian.Uint64(version) } + +// ShouldUpgrade returns true if the current height is one before +// the locally provided upgrade height that is passed as a flag +func (k Keeper) ShouldUpgrade(height int64) bool { + return k.upgradeHeight == height+1 +} From 1853460beb858eb8945beb9e50c7c30ae850ccc1 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 11:37:45 +0100 Subject: [PATCH 16/26] use sdk.Dec instead of uint32. Write tests --- app/app.go | 18 +++- app/version.go | 30 ++++-- proto/celestia/upgrade/v1/params.proto | 7 +- x/upgrade/keeper.go | 38 +++---- x/upgrade/params.go | 2 +- x/upgrade/tally_test.go | 132 +++++++++++++++++++++++++ x/upgrade/types/params.go | 29 ++++-- x/upgrade/types/params.pb.go | 74 ++++++++------ 8 files changed, 252 insertions(+), 78 deletions(-) create mode 100644 x/upgrade/tally_test.go diff --git a/app/app.go b/app/app.go index d1d7600ac2..e031163337 100644 --- a/app/app.go +++ b/app/app.go @@ -86,6 +86,7 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" + v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/pkg/proof" blobmodule "github.com/celestiaorg/celestia-app/x/blob" @@ -335,7 +336,7 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], upgradeHeight) + app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], upgradeHeight, app.StakingKeeper, app.GetSubspace(upgradetypes.ModuleName)) app.BlobstreamKeeper = *bsmodulekeeper.NewKeeper( appCodec, @@ -575,10 +576,17 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker application updates every end block func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { res := app.mm.EndBlock(ctx, req) - // NOTE: this is a specific feature for upgrading to v2 as v3 and onward is expected - // to be coordinated through the signalling protocol - if app.UpgradeKeeper.ShouldUpgrade(req.Height) { - app.SetAppVersion(ctx, v2.Version) + // NOTE: this is a specific feature for upgrading from v1 to v2. It will be deprecated in v3 + if app.UpgradeKeeper.ShouldUpgradeToV2(req.Height) { + if app.AppVersion(ctx) == v1.Version { + app.SetAppVersion(ctx, v2.Version) + } + // from v2 to v3 and onwards we use a signalling mechanism + } else if shouldUpgrade, version := app.UpgradeKeeper.ShouldUpgrade(); shouldUpgrade { + // Version changes must be increasing. Downgrades are not permitted + if version > app.AppVersion(ctx) { + app.SetAppVersion(ctx, version) + } } return res } diff --git a/app/version.go b/app/version.go index 3d05ee87cf..3f4bbfdaf7 100644 --- a/app/version.go +++ b/app/version.go @@ -8,6 +8,8 @@ import ( "github.com/celestiaorg/celestia-app/x/blob" "github.com/celestiaorg/celestia-app/x/blobstream" "github.com/celestiaorg/celestia-app/x/mint" + "github.com/celestiaorg/celestia-app/x/upgrade" + upgradetypes "github.com/celestiaorg/celestia-app/x/upgrade/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -31,6 +33,15 @@ var ( // versions that the current state machine supports supportedVersions = []uint64{v1.Version, v2.Version} + v1moduleVersionMap = make(module.VersionMap) + v2moduleVersionMap = make(module.VersionMap) +) + +const DefaultInitialVersion = v1.Version + +// this is used as a compile time consistency check across different module +// based maps +func init() { v1moduleVersionMap = module.VersionMap{ "bank": bank.AppModule{}.ConsensusVersion(), "auth": auth.AppModule{}.ConsensusVersion(), @@ -53,23 +64,22 @@ var ( "transfer": transfer.AppModule{}.ConsensusVersion(), } - // There is currently complete parity between v1 and v2 modules, but this - // will likely change + // v2 has all the same modules as v1 with the addition of an upgrade module v2moduleVersionMap = v1moduleVersionMap -) - -const DefaultInitialVersion = v1.Version + v2moduleVersionMap[upgradetypes.ModuleName] = upgrade.AppModule{}.ConsensusVersion() -// this is used as a compile time consistency check across different module -// based maps -func init() { for moduleName := range ModuleBasics { + isSupported := false for _, v := range supportedVersions { versionMap := GetModuleVersion(v) - if _, ok := versionMap[moduleName]; !ok { - panic(fmt.Sprintf("inconsistency: module %s not found in module version map for version %d", moduleName, v)) + if _, ok := versionMap[moduleName]; ok { + isSupported = true + break } } + if !isSupported { + panic(fmt.Sprintf("inconsistency: module %s not found in any version", moduleName)) + } } } diff --git a/proto/celestia/upgrade/v1/params.proto b/proto/celestia/upgrade/v1/params.proto index 839ac2cd94..18508f4eac 100644 --- a/proto/celestia/upgrade/v1/params.proto +++ b/proto/celestia/upgrade/v1/params.proto @@ -3,9 +3,12 @@ package celestia.upgrade.v1; option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + // Params defines the parameters for the upgrade module. message Params { // SignalQuorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. MaxUint32 would mean 100% of the voting power. - uint32 signal_quorum = 1; + // It must be at least 2/3. + bytes signal_quorum = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; } diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index 47dd20fffa..03585f895a 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -3,7 +3,7 @@ package upgrade import ( "context" "encoding/binary" - "math" + "fmt" sdkmath "cosmossdk.io/math" "github.com/celestiaorg/celestia-app/x/upgrade/types" @@ -65,8 +65,8 @@ func (k Keeper) SignalVersion(ctx context.Context, req *types.MsgSignalVersion) } // check that the validator exists - power := k.stakingKeeper.GetLastValidatorPower(sdkCtx, valAddr) - if power <= 0 { + _, found := k.stakingKeeper.GetValidator(sdkCtx, valAddr) + if !found { return nil, stakingtypes.ErrNoValidatorFound } @@ -93,6 +93,7 @@ func (k Keeper) VersionTally(ctx context.Context, req *types.QueryVersionTallyRe valAddress := sdk.ValAddress(iterator.Key()[1:]) power := k.stakingKeeper.GetLastValidatorPower(sdkCtx, valAddress) version := VersionFromBytes(iterator.Value()) + fmt.Println("validator", valAddress, "power", power, "version", version) if version == req.Version { currentVotingPower = currentVotingPower.AddRaw(power) } @@ -128,7 +129,7 @@ func (k Keeper) DeleteValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddres // which the application can use as signal to upgrade to that version. func (k Keeper) EndBlock(ctx sdk.Context) { threshold := k.GetVotingPowerThreshold(ctx) - hasQuorum, version := k.TallyVotingPower(ctx, threshold) + hasQuorum, version := k.TallyVotingPower(ctx, threshold.Int64()) if hasQuorum { k.quorumVersion = version } @@ -136,7 +137,7 @@ func (k Keeper) EndBlock(ctx sdk.Context) { // TallyVotingPower tallies the voting power for each version and returns true if // any version has reached the quorum in voting power -func (k Keeper) TallyVotingPower(ctx sdk.Context, quorum int64) (bool, uint64) { +func (k Keeper) TallyVotingPower(ctx sdk.Context, threshold int64) (bool, uint64) { output := make(map[uint64]int64) store := ctx.KVStore(k.storeKey) iterator := store.Iterator(nil, nil) @@ -144,8 +145,13 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, quorum int64) (bool, uint64) { for ; iterator.Valid(); iterator.Next() { valAddress := sdk.ValAddress(iterator.Key()[1:]) // check that the validator is still part of the bonded set - if val, found := k.stakingKeeper.GetValidator(ctx, valAddress); !found || !val.IsBonded() { + val, found := k.stakingKeeper.GetValidator(ctx, valAddress) + if !found { + // if it no longer exists, delete the version k.DeleteValidatorVersion(ctx, valAddress) + } + // if the validator is not bonded, skip it's voting power + if !found || !val.IsBonded() { continue } power := k.stakingKeeper.GetLastValidatorPower(ctx, valAddress) @@ -155,7 +161,7 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, quorum int64) (bool, uint64) { } else { output[version] += power } - if output[version] > quorum { + if output[version] > threshold { return true, version } } @@ -166,10 +172,10 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, quorum int64) (bool, uint64) { // upgrade to a new version. It converts the signal quorum parameter which // is a number between 0 and math.MaxUint32 representing a fraction and // then multiplies it by the total voting power -func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) int64 { - quorum := sdkmath.NewInt(int64(k.GetParams(ctx).SignalQuorum)) +func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) sdkmath.Int { + quorum := k.SignalQuorum(ctx) totalVotingPower := k.stakingKeeper.GetLastTotalPower(ctx) - return totalVotingPower.Mul(quorum).QuoRaw(math.MaxUint32).Int64() + return quorum.MulInt(totalVotingPower).RoundInt() } // ShouldUpgradeToV2 returns true if the current height is one before @@ -194,15 +200,3 @@ func VersionToBytes(version uint64) []byte { func VersionFromBytes(version []byte) uint64 { return binary.BigEndian.Uint64(version) } - -// ShouldUpgrade returns true if the current height is one before -// the locally provided upgrade height that is passed as a flag -func (k Keeper) ShouldUpgrade(height int64) bool { - return k.upgradeHeight == height+1 -} - -// ShouldUpgrade returns true if the current height is one before -// the locally provided upgrade height that is passed as a flag -func (k Keeper) ShouldUpgrade(height int64) bool { - return k.upgradeHeight == height+1 -} diff --git a/x/upgrade/params.go b/x/upgrade/params.go index 9e2b5c4828..e792dd3d8b 100644 --- a/x/upgrade/params.go +++ b/x/upgrade/params.go @@ -18,7 +18,7 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { } // SignalQuorum returns the SignalQuorum param -func (k Keeper) SignalQuorum(ctx sdk.Context) (res uint32) { +func (k Keeper) SignalQuorum(ctx sdk.Context) (res sdk.Dec) { k.paramStore.Get(ctx, types.KeySignalQuorum, &res) return res } diff --git a/x/upgrade/tally_test.go b/x/upgrade/tally_test.go new file mode 100644 index 0000000000..4f7136b0ea --- /dev/null +++ b/x/upgrade/tally_test.go @@ -0,0 +1,132 @@ +package upgrade_test + +import ( + "testing" + + "cosmossdk.io/math" + "github.com/celestiaorg/celestia-app/x/upgrade" + "github.com/celestiaorg/celestia-app/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" + + testutil "github.com/celestiaorg/celestia-app/test/util" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + tmdb "github.com/tendermint/tm-db" +) + +func TestSignalQuorum(t *testing.T) { + upgradeKeeper, ctx := setup(t) + require.Equal(t, types.DefaultSignalQuorum, upgradeKeeper.SignalQuorum(ctx)) + require.EqualValues(t, 100, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) + newParams := types.DefaultParams() + newParams.SignalQuorum = types.MinSignalQuorum + upgradeKeeper.SetParams(ctx, newParams) + require.Equal(t, types.MinSignalQuorum, upgradeKeeper.SignalQuorum(ctx)) + require.EqualValues(t, 80, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) +} + +func TestSignalling(t *testing.T) { + upgradeKeeper, ctx := setup(t) + goCtx := sdk.WrapSDKContext(ctx) + _, err := upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 0, + }) + require.Error(t, err) + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 3, + }) + require.Error(t, err) + + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 2, + }) + require.NoError(t, err) + + res, err := upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + Version: 2, + }) + require.NoError(t, err) + require.EqualValues(t, 30, res.VotingPower) + require.EqualValues(t, 120, res.TotalVotingPower) +} + +func setup(t *testing.T) (upgrade.Keeper, sdk.Context) { + upgradeStore := sdk.NewKVStoreKey(types.StoreKey) + paramStoreKey := sdk.NewKVStoreKey(paramtypes.StoreKey) + tStoreKey := storetypes.NewTransientStoreKey(paramtypes.TStoreKey) + val1 := testutil.ValAddrs[0] + val2 := testutil.ValAddrs[1] + val3 := testutil.ValAddrs[2] + db := tmdb.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(paramStoreKey, storetypes.StoreTypeIAVL, nil) + stateStore.MountStoreWithDB(tStoreKey, storetypes.StoreTypeTransient, nil) + stateStore.MountStoreWithDB(upgradeStore, storetypes.StoreTypeIAVL, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + mockCtx := sdk.NewContext(stateStore, tmproto.Header{ + Version: tmversion.Consensus{ + Block: 1, + App: 1, + }, + }, false, log.NewNopLogger()) + mockStakingKeeper := mockStakingKeeper{ + totalVotingPower: 120, + validators: map[string]int64{ + val1.String(): 30, + val2.String(): 40, + val3.String(): 50, + }, + } + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := paramtypes.NewSubspace(cdc, + testutil.MakeTestCodec(), + paramStoreKey, + tStoreKey, + types.ModuleName, + ) + paramsSubspace.WithKeyTable(types.ParamKeyTable()) + upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, &mockStakingKeeper, paramsSubspace) + upgradeKeeper.SetParams(mockCtx, types.DefaultParams()) + return upgradeKeeper, mockCtx +} + +var _ upgrade.StakingKeeper = (*mockStakingKeeper)(nil) + +type mockStakingKeeper struct { + totalVotingPower int64 + validators map[string]int64 +} + +func (m *mockStakingKeeper) GetLastTotalPower(ctx sdk.Context) math.Int { + return math.NewInt(m.totalVotingPower) +} + +func (m *mockStakingKeeper) GetLastValidatorPower(ctx sdk.Context, addr sdk.ValAddress) int64 { + addrStr := addr.String() + if power, ok := m.validators[addrStr]; ok { + return power + } + return 0 +} + +func (m *mockStakingKeeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) { + addrStr := addr.String() + if _, ok := m.validators[addrStr]; ok { + return stakingtypes.Validator{Status: stakingtypes.Bonded}, true + } + return stakingtypes.Validator{}, false +} diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go index 6a83d9f441..2ad9dbfc7c 100644 --- a/x/upgrade/types/params.go +++ b/x/upgrade/types/params.go @@ -2,32 +2,36 @@ package types import ( "fmt" - "math" + sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) var KeySignalQuorum = []byte("SignalQuorum") -// ParamKeyTable returns the param key table for the blob module +// ParamKeyTable returns the param key table for the upgrade module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -func NewParams(signalQuorum uint32) Params { +func NewParams(signalQuorum sdk.Dec) Params { return Params{ SignalQuorum: signalQuorum, } } -func DefaultParams() *Params { - return &Params{ - SignalQuorum: MinSignalQuorum, +func DefaultParams() Params { + return Params{ + SignalQuorum: DefaultSignalQuorum, } } -// 2/3 -const MinSignalQuorum = uint32(math.MaxUint32 * 2 / 3) +var ( + // 2/3 + MinSignalQuorum = sdk.NewDec(2).Quo(sdk.NewDec(3)) + // 5/6 + DefaultSignalQuorum = sdk.NewDec(5).Quo(sdk.NewDec(6)) +) func (p Params) Validate() error { return validateSignalQuorum(p.SignalQuorum) @@ -40,12 +44,17 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { } func validateSignalQuorum(i interface{}) error { - v, ok := i.(uint32) + v, ok := i.(sdk.Dec) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - if v < MinSignalQuorum { + if v.LT(MinSignalQuorum) { return fmt.Errorf("quorum must be at least %d (2/3), got %d", MinSignalQuorum, v) } + + if v.GT(sdk.OneDec()) { + return fmt.Errorf("quorum must be less than or equal to 1, got %d", v) + } + return nil } diff --git a/x/upgrade/types/params.pb.go b/x/upgrade/types/params.pb.go index e9bf0b3a18..2a8326c3a5 100644 --- a/x/upgrade/types/params.pb.go +++ b/x/upgrade/types/params.pb.go @@ -5,6 +5,9 @@ package types import ( fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -25,8 +28,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the upgrade module. type Params struct { // SignalQuorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. MaxUint32 would mean 100% of the voting power. - SignalQuorum uint32 `protobuf:"varint,1,opt,name=signal_quorum,json=signalQuorum,proto3" json:"signal_quorum,omitempty"` + // It must be at least 2/3. + SignalQuorum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=signal_quorum,json=signalQuorum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"signal_quorum"` } func (m *Params) Reset() { *m = Params{} } @@ -62,13 +65,6 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetSignalQuorum() uint32 { - if m != nil { - return m.SignalQuorum - } - return 0 -} - func init() { proto.RegisterType((*Params)(nil), "celestia.upgrade.v1.Params") } @@ -76,18 +72,22 @@ func init() { func init() { proto.RegisterFile("celestia/upgrade/v1/params.proto", fileDescriptor_b4f657414f35d610) } var fileDescriptor_b4f657414f35d610 = []byte{ - // 171 bytes of a gzipped FileDescriptorProto + // 225 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa9, - 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x54, 0xd2, 0xe5, 0x62, 0x0b, 0x00, 0x2b, 0x12, 0x52, 0xe6, - 0xe2, 0x2d, 0xce, 0x4c, 0xcf, 0x4b, 0xcc, 0x89, 0x2f, 0x2c, 0xcd, 0x2f, 0x2a, 0xcd, 0x95, 0x60, - 0x54, 0x60, 0xd4, 0xe0, 0x0d, 0xe2, 0x81, 0x08, 0x06, 0x82, 0xc5, 0x9c, 0x7c, 0x4f, 0x3c, 0x92, - 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, - 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x38, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, - 0x39, 0x3f, 0x57, 0x1f, 0x66, 0x51, 0x7e, 0x51, 0x3a, 0x9c, 0xad, 0x9b, 0x58, 0x50, 0xa0, 0x5f, - 0x01, 0x77, 0x5c, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0xd8, 0x65, 0xc6, 0x80, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x78, 0xaa, 0x4c, 0x7d, 0xbd, 0x00, 0x00, 0x00, + 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x94, 0x92, 0x4c, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, 0x07, + 0x2b, 0xd1, 0x87, 0x70, 0x20, 0xea, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0x21, 0xe2, 0x20, 0x16, + 0x44, 0x54, 0x29, 0x96, 0x8b, 0x2d, 0x00, 0x6c, 0xaa, 0x50, 0x30, 0x17, 0x6f, 0x71, 0x66, 0x7a, + 0x5e, 0x62, 0x4e, 0x7c, 0x61, 0x69, 0x7e, 0x51, 0x69, 0xae, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, + 0x93, 0xde, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0xab, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, + 0xe9, 0x25, 0xe7, 0xe7, 0x42, 0xcd, 0x85, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x25, 0x95, 0x05, + 0xa9, 0xc5, 0x7a, 0x2e, 0xa9, 0xc9, 0x41, 0x3c, 0x10, 0x43, 0x02, 0xc1, 0x66, 0x38, 0xf9, 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, 0x31, 0xb2, 0x79, 0x50, 0x9f, 0xe4, + 0x17, 0xa5, 0xc3, 0xd9, 0xba, 0x89, 0x05, 0x05, 0xfa, 0x15, 0x70, 0xdf, 0x83, 0x2d, 0x48, 0x62, + 0x03, 0x3b, 0xda, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xca, 0xe4, 0x67, 0x15, 0x1e, 0x01, 0x00, + 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -110,11 +110,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.SignalQuorum != 0 { - i = encodeVarintParams(dAtA, i, uint64(m.SignalQuorum)) - i-- - dAtA[i] = 0x8 + { + size := m.SignalQuorum.Size() + i -= size + if _, err := m.SignalQuorum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -135,9 +140,8 @@ func (m *Params) Size() (n int) { } var l int _ = l - if m.SignalQuorum != 0 { - n += 1 + sovParams(uint64(m.SignalQuorum)) - } + l = m.SignalQuorum.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -177,10 +181,10 @@ func (m *Params) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field SignalQuorum", wireType) } - m.SignalQuorum = 0 + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowParams @@ -190,11 +194,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.SignalQuorum |= uint32(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } + if byteLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.SignalQuorum.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) From c81743a3ab4d313f12ca6b5aaa5bf61095e5f528 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 14:28:45 +0100 Subject: [PATCH 17/26] wrap up unit tests --- app/app.go | 1 + proto/celestia/upgrade/v1/query.proto | 3 +- x/upgrade/keeper.go | 12 +-- x/upgrade/tally_test.go | 149 +++++++++++++++++++++++--- x/upgrade/types/query.pb.go | 88 ++++++++++----- 5 files changed, 204 insertions(+), 49 deletions(-) diff --git a/app/app.go b/app/app.go index e031163337..e3e1b32cda 100644 --- a/app/app.go +++ b/app/app.go @@ -445,6 +445,7 @@ func New( transferModule, blobmod, bsmod, + upgrade.NewAppModule(app.UpgradeKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that diff --git a/proto/celestia/upgrade/v1/query.proto b/proto/celestia/upgrade/v1/query.proto index cb34404653..b4c95d63b7 100644 --- a/proto/celestia/upgrade/v1/query.proto +++ b/proto/celestia/upgrade/v1/query.proto @@ -35,5 +35,6 @@ message QueryVersionTallyRequest { uint64 version = 1; } // method. message QueryVersionTallyResponse { uint64 voting_power = 1; - uint64 total_voting_power = 2; + uint64 threshold = 2; + uint64 total_voting_power = 3; } diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index 03585f895a..db918d74aa 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -3,7 +3,6 @@ package upgrade import ( "context" "encoding/binary" - "fmt" sdkmath "cosmossdk.io/math" "github.com/celestiaorg/celestia-app/x/upgrade/types" @@ -90,18 +89,19 @@ func (k Keeper) VersionTally(ctx context.Context, req *types.QueryVersionTallyRe iterator := store.Iterator(nil, nil) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - valAddress := sdk.ValAddress(iterator.Key()[1:]) + valAddress := sdk.ValAddress(iterator.Key()) power := k.stakingKeeper.GetLastValidatorPower(sdkCtx, valAddress) version := VersionFromBytes(iterator.Value()) - fmt.Println("validator", valAddress, "power", power, "version", version) if version == req.Version { currentVotingPower = currentVotingPower.AddRaw(power) } } + threshold := k.GetVotingPowerThreshold(sdkCtx) return &types.QueryVersionTallyResponse{ - TotalVotingPower: totalVotingPower.Uint64(), VotingPower: currentVotingPower.Uint64(), + Threshold: threshold.Uint64(), + TotalVotingPower: totalVotingPower.Uint64(), }, nil } @@ -127,7 +127,7 @@ func (k Keeper) DeleteValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddres // EndBlock is called at the end of every block. It tallies the voting power that has // voted on each version. If one version has quorum, it is set as the quorum version // which the application can use as signal to upgrade to that version. -func (k Keeper) EndBlock(ctx sdk.Context) { +func (k *Keeper) EndBlock(ctx sdk.Context) { threshold := k.GetVotingPowerThreshold(ctx) hasQuorum, version := k.TallyVotingPower(ctx, threshold.Int64()) if hasQuorum { @@ -143,7 +143,7 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, threshold int64) (bool, uint64 iterator := store.Iterator(nil, nil) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - valAddress := sdk.ValAddress(iterator.Key()[1:]) + valAddress := sdk.ValAddress(iterator.Key()) // check that the validator is still part of the bonded set val, found := k.stakingKeeper.GetValidator(ctx, valAddress) if !found { diff --git a/x/upgrade/tally_test.go b/x/upgrade/tally_test.go index 4f7136b0ea..76139f73a7 100644 --- a/x/upgrade/tally_test.go +++ b/x/upgrade/tally_test.go @@ -23,7 +23,7 @@ import ( ) func TestSignalQuorum(t *testing.T) { - upgradeKeeper, ctx := setup(t) + upgradeKeeper, ctx, _ := setup(t) require.Equal(t, types.DefaultSignalQuorum, upgradeKeeper.SignalQuorum(ctx)) require.EqualValues(t, 100, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) newParams := types.DefaultParams() @@ -33,8 +33,43 @@ func TestSignalQuorum(t *testing.T) { require.EqualValues(t, 80, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) } -func TestSignalling(t *testing.T) { - upgradeKeeper, ctx := setup(t) +func TestSignalVersion(t *testing.T) { + upgradeKeeper, ctx, _ := setup(t) + goCtx := sdk.WrapSDKContext(ctx) + _, err := upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 0, + }) + require.Error(t, err) + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 3, + }) + require.Error(t, err) + + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[4].String(), + Version: 2, + }) + require.Error(t, err) + + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 2, + }) + require.NoError(t, err) + + res, err := upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + Version: 2, + }) + require.NoError(t, err) + require.EqualValues(t, 30, res.VotingPower) + require.EqualValues(t, 100, res.Threshold) + require.EqualValues(t, 120, res.TotalVotingPower) +} + +func TestTallyingLogic(t *testing.T) { + upgradeKeeper, ctx, mockStakingKeeper := setup(t) goCtx := sdk.WrapSDKContext(ctx) _, err := upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ ValidatorAddress: testutil.ValAddrs[0].String(), @@ -58,16 +93,97 @@ func TestSignalling(t *testing.T) { }) require.NoError(t, err) require.EqualValues(t, 30, res.VotingPower) + require.EqualValues(t, 100, res.Threshold) require.EqualValues(t, 120, res.TotalVotingPower) + + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[2].String(), + Version: 2, + }) + require.NoError(t, err) + + res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + Version: 2, + }) + require.NoError(t, err) + require.EqualValues(t, 80, res.VotingPower) + require.EqualValues(t, 100, res.Threshold) + require.EqualValues(t, 120, res.TotalVotingPower) + + upgradeKeeper.EndBlock(ctx) + shouldUpgrade, version := upgradeKeeper.ShouldUpgrade() + require.False(t, shouldUpgrade) + require.Equal(t, uint64(0), version) + + // modify the quorum so we are right on the boundary 80/120 = 2/3 + newParams := types.DefaultParams() + newParams.SignalQuorum = types.MinSignalQuorum + upgradeKeeper.SetParams(ctx, newParams) + + upgradeKeeper.EndBlock(ctx) + shouldUpgrade, version = upgradeKeeper.ShouldUpgrade() + require.False(t, shouldUpgrade) + require.Equal(t, uint64(0), version) + require.EqualValues(t, 80, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) + + // we now have 81/120 = 0.675 > 2/3 + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[1].String(), + Version: 2, + }) + require.NoError(t, err) + + upgradeKeeper.EndBlock(ctx) + shouldUpgrade, version = upgradeKeeper.ShouldUpgrade() + require.True(t, shouldUpgrade) + require.Equal(t, uint64(2), version) + // update the version to 2 + ctx = ctx.WithBlockHeader(tmproto.Header{ + Version: tmversion.Consensus{ + Block: 1, + App: 2, + }, + }) + goCtx = sdk.WrapSDKContext(ctx) + + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[0].String(), + Version: 3, + }) + require.NoError(t, err) + + res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + Version: 2, + }) + require.NoError(t, err) + require.EqualValues(t, 51, res.VotingPower) + require.EqualValues(t, 80, res.Threshold) + require.EqualValues(t, 120, res.TotalVotingPower) + + // remove one of the validators from the set + delete(mockStakingKeeper.validators, testutil.ValAddrs[2].String()) + mockStakingKeeper.totalVotingPower -= 50 + + res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + Version: 2, + }) + require.NoError(t, err) + require.EqualValues(t, 1, res.VotingPower) + require.EqualValues(t, 47, res.Threshold) + require.EqualValues(t, 70, res.TotalVotingPower) + + // That validator should not be able to signal a version + _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ + ValidatorAddress: testutil.ValAddrs[2].String(), + Version: 2, + }) + require.Error(t, err) } -func setup(t *testing.T) (upgrade.Keeper, sdk.Context) { +func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { upgradeStore := sdk.NewKVStoreKey(types.StoreKey) paramStoreKey := sdk.NewKVStoreKey(paramtypes.StoreKey) tStoreKey := storetypes.NewTransientStoreKey(paramtypes.TStoreKey) - val1 := testutil.ValAddrs[0] - val2 := testutil.ValAddrs[1] - val3 := testutil.ValAddrs[2] db := tmdb.NewMemDB() stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(paramStoreKey, storetypes.StoreTypeIAVL, nil) @@ -80,12 +196,13 @@ func setup(t *testing.T) (upgrade.Keeper, sdk.Context) { App: 1, }, }, false, log.NewNopLogger()) - mockStakingKeeper := mockStakingKeeper{ + mockStakingKeeper := &mockStakingKeeper{ totalVotingPower: 120, validators: map[string]int64{ - val1.String(): 30, - val2.String(): 40, - val3.String(): 50, + testutil.ValAddrs[0].String(): 30, + testutil.ValAddrs[1].String(): 1, + testutil.ValAddrs[2].String(): 50, + testutil.ValAddrs[3].String(): 39, }, } @@ -99,9 +216,9 @@ func setup(t *testing.T) (upgrade.Keeper, sdk.Context) { types.ModuleName, ) paramsSubspace.WithKeyTable(types.ParamKeyTable()) - upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, &mockStakingKeeper, paramsSubspace) + upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, mockStakingKeeper, paramsSubspace) upgradeKeeper.SetParams(mockCtx, types.DefaultParams()) - return upgradeKeeper, mockCtx + return upgradeKeeper, mockCtx, mockStakingKeeper } var _ upgrade.StakingKeeper = (*mockStakingKeeper)(nil) @@ -111,11 +228,11 @@ type mockStakingKeeper struct { validators map[string]int64 } -func (m *mockStakingKeeper) GetLastTotalPower(ctx sdk.Context) math.Int { +func (m *mockStakingKeeper) GetLastTotalPower(_ sdk.Context) math.Int { return math.NewInt(m.totalVotingPower) } -func (m *mockStakingKeeper) GetLastValidatorPower(ctx sdk.Context, addr sdk.ValAddress) int64 { +func (m *mockStakingKeeper) GetLastValidatorPower(_ sdk.Context, addr sdk.ValAddress) int64 { addrStr := addr.String() if power, ok := m.validators[addrStr]; ok { return power @@ -123,7 +240,7 @@ func (m *mockStakingKeeper) GetLastValidatorPower(ctx sdk.Context, addr sdk.ValA return 0 } -func (m *mockStakingKeeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) { +func (m *mockStakingKeeper) GetValidator(_ sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) { addrStr := addr.String() if _, ok := m.validators[addrStr]; ok { return stakingtypes.Validator{Status: stakingtypes.Bonded}, true diff --git a/x/upgrade/types/query.pb.go b/x/upgrade/types/query.pb.go index f2dad257df..fe0ad604be 100644 --- a/x/upgrade/types/query.pb.go +++ b/x/upgrade/types/query.pb.go @@ -160,7 +160,8 @@ func (m *QueryVersionTallyRequest) GetVersion() uint64 { // method. type QueryVersionTallyResponse struct { VotingPower uint64 `protobuf:"varint,1,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` - TotalVotingPower uint64 `protobuf:"varint,2,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` + Threshold uint64 `protobuf:"varint,2,opt,name=threshold,proto3" json:"threshold,omitempty"` + TotalVotingPower uint64 `protobuf:"varint,3,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` } func (m *QueryVersionTallyResponse) Reset() { *m = QueryVersionTallyResponse{} } @@ -203,6 +204,13 @@ func (m *QueryVersionTallyResponse) GetVotingPower() uint64 { return 0 } +func (m *QueryVersionTallyResponse) GetThreshold() uint64 { + if m != nil { + return m.Threshold + } + return 0 +} + func (m *QueryVersionTallyResponse) GetTotalVotingPower() uint64 { if m != nil { return m.TotalVotingPower @@ -220,31 +228,32 @@ func init() { func init() { proto.RegisterFile("celestia/upgrade/v1/query.proto", fileDescriptor_7dd2290b21d03efa) } var fileDescriptor_7dd2290b21d03efa = []byte{ - // 380 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xc1, 0x4e, 0xea, 0x40, - 0x18, 0x85, 0x29, 0xb9, 0x97, 0x9b, 0x0c, 0x2c, 0x6e, 0x06, 0x16, 0xdc, 0x72, 0xad, 0x58, 0x17, - 0xb2, 0x90, 0x99, 0x00, 0x3e, 0x81, 0x4b, 0x13, 0x13, 0x24, 0x86, 0x85, 0x1b, 0x32, 0xe0, 0xa4, - 0x36, 0x29, 0x9d, 0x61, 0x66, 0x5a, 0x24, 0xc6, 0x8d, 0x4f, 0x60, 0x34, 0xbe, 0x93, 0x4b, 0x12, - 0x37, 0x2e, 0x0d, 0xf8, 0x20, 0x86, 0xe9, 0x80, 0x10, 0x6a, 0x74, 0xd7, 0x9e, 0x7e, 0xe7, 0xfc, - 0x67, 0xe6, 0x2f, 0xd8, 0x1d, 0xd0, 0x80, 0x4a, 0xe5, 0x13, 0x1c, 0x71, 0x4f, 0x90, 0x4b, 0x8a, - 0xe3, 0x06, 0x1e, 0x45, 0x54, 0x4c, 0x10, 0x17, 0x4c, 0x31, 0x58, 0x5c, 0x02, 0xc8, 0x00, 0x28, - 0x6e, 0xd8, 0xff, 0x3d, 0xc6, 0xbc, 0x80, 0x62, 0xc2, 0x7d, 0x4c, 0xc2, 0x90, 0x29, 0xa2, 0x7c, - 0x16, 0xca, 0xc4, 0x62, 0x57, 0xd3, 0x32, 0x39, 0x11, 0x64, 0x68, 0x08, 0xb7, 0x04, 0xe0, 0xd9, - 0x62, 0x46, 0x5b, 0x8b, 0x1d, 0x3a, 0x8a, 0xa8, 0x54, 0xee, 0x09, 0x28, 0x6e, 0xa8, 0x92, 0xb3, - 0x50, 0x52, 0xd8, 0x02, 0xb9, 0xc4, 0x5c, 0xb6, 0xaa, 0x56, 0x2d, 0xdf, 0xac, 0xa0, 0x94, 0x4a, - 0xc8, 0x98, 0x0c, 0xea, 0x1e, 0x81, 0xb2, 0xce, 0xea, 0x52, 0x21, 0x7d, 0x16, 0x9e, 0x93, 0x20, - 0x98, 0x98, 0x39, 0xb0, 0x0c, 0xfe, 0xc4, 0x89, 0xac, 0x13, 0x7f, 0x75, 0x96, 0xaf, 0x6e, 0x00, - 0xfe, 0xa5, 0xb8, 0x4c, 0x8f, 0x3d, 0x50, 0x88, 0x99, 0xf2, 0x43, 0xaf, 0xc7, 0xd9, 0x98, 0x0a, - 0xe3, 0xcd, 0x27, 0x5a, 0x7b, 0x21, 0xc1, 0x43, 0x00, 0x15, 0x53, 0x24, 0xe8, 0x6d, 0x80, 0x59, - 0x0d, 0xfe, 0xd5, 0x5f, 0xba, 0x9f, 0x74, 0xf3, 0x29, 0x0b, 0x7e, 0xeb, 0x71, 0x70, 0x0c, 0x72, - 0x49, 0x7f, 0x78, 0x90, 0x7a, 0xb8, 0xed, 0xcb, 0xb2, 0x6b, 0xdf, 0x83, 0x49, 0x6f, 0xd7, 0xbe, - 0x7b, 0x79, 0x7f, 0xcc, 0x96, 0x20, 0xdc, 0x5e, 0x07, 0x7c, 0xb0, 0x40, 0x61, 0xfd, 0xb0, 0xb0, - 0xfe, 0x75, 0x6c, 0xca, 0x55, 0xda, 0xe8, 0xa7, 0xb8, 0xe9, 0xb2, 0xaf, 0xbb, 0xec, 0xc0, 0xca, - 0x7a, 0x17, 0xb5, 0x40, 0xf0, 0x8d, 0x59, 0xc2, 0xed, 0xf1, 0xe9, 0xf3, 0xcc, 0xb1, 0xa6, 0x33, - 0xc7, 0x7a, 0x9b, 0x39, 0xd6, 0xfd, 0xdc, 0xc9, 0x4c, 0xe7, 0x4e, 0xe6, 0x75, 0xee, 0x64, 0x2e, - 0x5a, 0x9e, 0xaf, 0xae, 0xa2, 0x3e, 0x1a, 0xb0, 0x21, 0x5e, 0x0e, 0x66, 0xc2, 0x5b, 0x3d, 0xd7, - 0x09, 0xe7, 0xf8, 0x7a, 0x95, 0xad, 0x26, 0x9c, 0xca, 0x7e, 0x4e, 0xff, 0x73, 0xad, 0x8f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xe7, 0xf7, 0xd5, 0xf3, 0xeb, 0x02, 0x00, 0x00, + // 399 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xbf, 0x6f, 0xda, 0x40, + 0x14, 0xc6, 0xb4, 0xa5, 0xea, 0xc1, 0x50, 0x1d, 0x0c, 0xae, 0xa1, 0x2e, 0x75, 0x87, 0x32, 0x14, + 0x9f, 0x80, 0xfe, 0x05, 0x1d, 0x2b, 0x45, 0x22, 0x28, 0x62, 0xc8, 0x82, 0x0e, 0x38, 0x19, 0x4b, + 0xc6, 0x77, 0xdc, 0x9d, 0x4d, 0x50, 0x94, 0x25, 0x63, 0xa6, 0x28, 0x51, 0xfe, 0xa7, 0x8c, 0x48, + 0x59, 0x32, 0x46, 0x90, 0x3f, 0x24, 0xe2, 0x7c, 0xfc, 0x12, 0x8e, 0x92, 0xcd, 0xfe, 0xde, 0xf7, + 0x7d, 0xef, 0x7b, 0xef, 0x1d, 0xf8, 0x31, 0x20, 0x01, 0x11, 0xd2, 0xc7, 0x28, 0x62, 0x1e, 0xc7, + 0x43, 0x82, 0xe2, 0x06, 0x9a, 0x44, 0x84, 0xcf, 0x5c, 0xc6, 0xa9, 0xa4, 0xb0, 0xb8, 0x26, 0xb8, + 0x9a, 0xe0, 0xc6, 0x0d, 0xab, 0xe2, 0x51, 0xea, 0x05, 0x04, 0x61, 0xe6, 0x23, 0x1c, 0x86, 0x54, + 0x62, 0xe9, 0xd3, 0x50, 0x24, 0x12, 0xab, 0x9a, 0xe6, 0xc9, 0x30, 0xc7, 0x63, 0xcd, 0x70, 0x4a, + 0x00, 0x1e, 0xaf, 0x7a, 0xb4, 0x15, 0xd8, 0x21, 0x93, 0x88, 0x08, 0xe9, 0xfc, 0x07, 0xc5, 0x3d, + 0x54, 0x30, 0x1a, 0x0a, 0x02, 0x5b, 0x20, 0x97, 0x88, 0x4d, 0xa3, 0x6a, 0xd4, 0xf2, 0xcd, 0xb2, + 0x9b, 0x12, 0xc9, 0xd5, 0x22, 0x4d, 0x75, 0xfe, 0x02, 0x53, 0x79, 0x75, 0x09, 0x17, 0x3e, 0x0d, + 0x4f, 0x70, 0x10, 0xcc, 0x74, 0x1f, 0x68, 0x82, 0xcf, 0x71, 0x02, 0x2b, 0xc7, 0x8f, 0x9d, 0xf5, + 0xaf, 0x73, 0x65, 0x80, 0x6f, 0x29, 0x32, 0x1d, 0xe4, 0x27, 0x28, 0xc4, 0x54, 0xfa, 0xa1, 0xd7, + 0x63, 0x74, 0x4a, 0xb8, 0x16, 0xe7, 0x13, 0xac, 0xbd, 0x82, 0x60, 0x05, 0x7c, 0x91, 0x23, 0x4e, + 0xc4, 0x88, 0x06, 0x43, 0x33, 0xab, 0xea, 0x5b, 0x00, 0xfe, 0x01, 0x50, 0x52, 0x89, 0x83, 0xde, + 0x9e, 0xcd, 0x07, 0x45, 0xfb, 0xaa, 0x2a, 0xdd, 0xad, 0x57, 0xf3, 0x2e, 0x0b, 0x3e, 0xa9, 0x30, + 0x70, 0x0a, 0x72, 0xc9, 0x78, 0xf0, 0x77, 0xea, 0xec, 0x87, 0xbb, 0xb4, 0x6a, 0x6f, 0x13, 0x93, + 0xa9, 0x1c, 0xeb, 0xf2, 0xe1, 0xf9, 0x36, 0x5b, 0x82, 0xf0, 0xf0, 0x5a, 0xf0, 0xc6, 0x00, 0x85, + 0xdd, 0x55, 0xc0, 0xfa, 0xeb, 0xb6, 0x29, 0x9b, 0xb6, 0xdc, 0xf7, 0xd2, 0x75, 0x96, 0x5f, 0x2a, + 0xcb, 0x77, 0x58, 0xde, 0xcd, 0x22, 0x57, 0x14, 0x74, 0xae, 0x6f, 0x74, 0xf1, 0xef, 0xe8, 0x7e, + 0x61, 0x1b, 0xf3, 0x85, 0x6d, 0x3c, 0x2d, 0x6c, 0xe3, 0x7a, 0x69, 0x67, 0xe6, 0x4b, 0x3b, 0xf3, + 0xb8, 0xb4, 0x33, 0xa7, 0x2d, 0xcf, 0x97, 0xa3, 0xa8, 0xef, 0x0e, 0xe8, 0x18, 0xad, 0x1b, 0x53, + 0xee, 0x6d, 0xbe, 0xeb, 0x98, 0x31, 0x74, 0xb6, 0xf1, 0x96, 0x33, 0x46, 0x44, 0x3f, 0xa7, 0x9e, + 0x64, 0xeb, 0x25, 0x00, 0x00, 0xff, 0xff, 0x37, 0x43, 0xf1, 0x62, 0x0a, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -478,6 +487,11 @@ func (m *QueryVersionTallyResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro if m.TotalVotingPower != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.TotalVotingPower)) i-- + dAtA[i] = 0x18 + } + if m.Threshold != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Threshold)) + i-- dAtA[i] = 0x10 } if m.VotingPower != 0 { @@ -542,6 +556,9 @@ func (m *QueryVersionTallyResponse) Size() (n int) { if m.VotingPower != 0 { n += 1 + sovQuery(uint64(m.VotingPower)) } + if m.Threshold != 0 { + n += 1 + sovQuery(uint64(m.Threshold)) + } if m.TotalVotingPower != 0 { n += 1 + sovQuery(uint64(m.TotalVotingPower)) } @@ -808,6 +825,25 @@ func (m *QueryVersionTallyResponse) Unmarshal(dAtA []byte) error { } } case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Threshold", wireType) + } + m.Threshold = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Threshold |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field TotalVotingPower", wireType) } From 4674c0f851c65c6cdb1adf791321578151bd3793 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 15:01:55 +0100 Subject: [PATCH 18/26] Update x/upgrade/types/params.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- x/upgrade/types/params.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go index 2ad9dbfc7c..c85d2eabf9 100644 --- a/x/upgrade/types/params.go +++ b/x/upgrade/types/params.go @@ -49,6 +49,7 @@ func validateSignalQuorum(i interface{}) error { return fmt.Errorf("invalid parameter type: %T", i) } if v.LT(MinSignalQuorum) { + return fmt.Errorf("quorum must be at least %s (2/3), got %s", MinSignalQuorum, v) return fmt.Errorf("quorum must be at least %d (2/3), got %d", MinSignalQuorum, v) } From 0580b1b0a142465ef60f16edb7b878c767638aa6 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 15:02:14 +0100 Subject: [PATCH 19/26] Update proto/celestia/upgrade/v1/tx.proto Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- proto/celestia/upgrade/v1/tx.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/celestia/upgrade/v1/tx.proto b/proto/celestia/upgrade/v1/tx.proto index be11d712e7..9d8666a7fd 100644 --- a/proto/celestia/upgrade/v1/tx.proto +++ b/proto/celestia/upgrade/v1/tx.proto @@ -9,7 +9,7 @@ option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; service Msg { // SignalVersion allows the validator to signal for an upgrade rpc SignalVersion(MsgSignalVersion) returns (MsgSignalVersionResponse) { - option (google.api.http).get = "/upgrade/v1/signal"; + option (google.api.http).post = "/upgrade/v1/signal"; } } From 9de37149fbcaf8aa0b87812e1a28df5583ada45c Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 15:03:30 +0100 Subject: [PATCH 20/26] Update x/upgrade/types/params.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- x/upgrade/types/params.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go index c85d2eabf9..f1446cf08f 100644 --- a/x/upgrade/types/params.go +++ b/x/upgrade/types/params.go @@ -50,7 +50,6 @@ func validateSignalQuorum(i interface{}) error { } if v.LT(MinSignalQuorum) { return fmt.Errorf("quorum must be at least %s (2/3), got %s", MinSignalQuorum, v) - return fmt.Errorf("quorum must be at least %d (2/3), got %d", MinSignalQuorum, v) } if v.GT(sdk.OneDec()) { From 823c1ea5411c72bbe0c14b08ac6909332864b96c Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 15:05:56 +0100 Subject: [PATCH 21/26] implement suggestions --- app/version.go | 5 ++++- x/upgrade/types/params.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/version.go b/app/version.go index 3f4bbfdaf7..45277524f1 100644 --- a/app/version.go +++ b/app/version.go @@ -65,7 +65,10 @@ func init() { } // v2 has all the same modules as v1 with the addition of an upgrade module - v2moduleVersionMap = v1moduleVersionMap + v2moduleVersionMap = make(module.VersionMap) + for k, v := range v1moduleVersionMap { + v2moduleVersionMap[k] = v + } v2moduleVersionMap[upgradetypes.ModuleName] = upgrade.AppModule{}.ConsensusVersion() for moduleName := range ModuleBasics { diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go index f1446cf08f..ef95cc0e84 100644 --- a/x/upgrade/types/params.go +++ b/x/upgrade/types/params.go @@ -53,7 +53,7 @@ func validateSignalQuorum(i interface{}) error { } if v.GT(sdk.OneDec()) { - return fmt.Errorf("quorum must be less than or equal to 1, got %d", v) + return fmt.Errorf("quorum must be less than or equal to 1, got %s", v) } return nil From 3d6160da1d3fd2fadfade8b701969ea8bb2881e1 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 28 Nov 2023 15:48:19 +0100 Subject: [PATCH 22/26] lint and rebuild protos --- app/version.go | 8 +++--- proto/celestia/upgrade/v1/params.proto | 9 ++++--- x/upgrade/types/tx.pb.go | 36 +++++++++++++------------- x/upgrade/types/tx.pb.gw.go | 4 +-- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/version.go b/app/version.go index 45277524f1..49c3cc71b0 100644 --- a/app/version.go +++ b/app/version.go @@ -65,10 +65,10 @@ func init() { } // v2 has all the same modules as v1 with the addition of an upgrade module - v2moduleVersionMap = make(module.VersionMap) - for k, v := range v1moduleVersionMap { - v2moduleVersionMap[k] = v - } + v2moduleVersionMap = make(module.VersionMap) + for k, v := range v1moduleVersionMap { + v2moduleVersionMap[k] = v + } v2moduleVersionMap[upgradetypes.ModuleName] = upgrade.AppModule{}.ConsensusVersion() for moduleName := range ModuleBasics { diff --git a/proto/celestia/upgrade/v1/params.proto b/proto/celestia/upgrade/v1/params.proto index 18508f4eac..fe8f7f8932 100644 --- a/proto/celestia/upgrade/v1/params.proto +++ b/proto/celestia/upgrade/v1/params.proto @@ -8,7 +8,10 @@ import "gogoproto/gogo.proto"; // Params defines the parameters for the upgrade module. message Params { - // SignalQuorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. - bytes signal_quorum = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + // SignalQuorum represents the minimum voting power for an upgrade to go + // through. It must be at least 2/3. + bytes signal_quorum = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } diff --git a/x/upgrade/types/tx.pb.go b/x/upgrade/types/tx.pb.go index 6d90c31ca3..fd15cd30ee 100644 --- a/x/upgrade/types/tx.pb.go +++ b/x/upgrade/types/tx.pb.go @@ -128,24 +128,24 @@ func init() { proto.RegisterFile("celestia/upgrade/v1/tx.proto", fileDescriptor_ var fileDescriptor_ee2a0c754324bd13 = []byte{ // 283 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x50, 0x3f, 0x4b, 0x03, 0x31, - 0x14, 0x6f, 0xaa, 0x28, 0x06, 0x84, 0x1a, 0x1d, 0x8e, 0xa3, 0x84, 0x52, 0x10, 0x0a, 0xd2, 0x84, - 0xda, 0x4f, 0xa0, 0xfb, 0x2d, 0x27, 0x08, 0xba, 0x48, 0xda, 0x0b, 0x31, 0x70, 0x26, 0x21, 0x2f, - 0x3d, 0xea, 0xa8, 0x9b, 0x9b, 0xe0, 0x97, 0x72, 0x2c, 0xb8, 0x38, 0xca, 0x9d, 0x1f, 0x44, 0xe8, - 0x79, 0x87, 0x16, 0x07, 0xb7, 0xf7, 0xde, 0xef, 0x1f, 0xef, 0x87, 0xfb, 0x73, 0x99, 0x4b, 0x08, - 0x5a, 0xf0, 0x85, 0x53, 0x5e, 0x64, 0x92, 0x17, 0x13, 0x1e, 0x96, 0xcc, 0x79, 0x1b, 0x2c, 0x39, - 0x6c, 0x50, 0xf6, 0x8d, 0xb2, 0x62, 0x12, 0xf7, 0x95, 0xb5, 0x2a, 0x97, 0x5c, 0x38, 0xcd, 0x85, - 0x31, 0x36, 0x88, 0xa0, 0xad, 0x81, 0x5a, 0x32, 0xbc, 0xc2, 0xbd, 0x04, 0xd4, 0x85, 0x56, 0x46, - 0xe4, 0x97, 0xd2, 0x83, 0xb6, 0x86, 0x9c, 0xe0, 0x83, 0x42, 0xe4, 0x3a, 0x13, 0xc1, 0xfa, 0x1b, - 0x91, 0x65, 0x5e, 0x02, 0x44, 0x68, 0x80, 0x46, 0x7b, 0x69, 0xaf, 0x05, 0xce, 0xea, 0x3b, 0x89, - 0xf0, 0x6e, 0x51, 0xeb, 0xa2, 0xee, 0x00, 0x8d, 0xb6, 0xd3, 0x66, 0x1d, 0xc6, 0x38, 0xda, 0xb4, - 0x4e, 0x25, 0x38, 0x6b, 0x40, 0x9e, 0x3e, 0x21, 0xbc, 0x95, 0x80, 0x22, 0x0f, 0x08, 0xef, 0xff, - 0x0e, 0x3f, 0x66, 0x7f, 0x3c, 0xc1, 0x36, 0x8d, 0xe2, 0xf1, 0xbf, 0x68, 0x4d, 0xde, 0x30, 0x7e, - 0x7c, 0xfb, 0x7c, 0xe9, 0x1e, 0x11, 0xf2, 0xb3, 0x37, 0x58, 0x53, 0xcf, 0x93, 0xd7, 0x92, 0xa2, - 0x55, 0x49, 0xd1, 0x47, 0x49, 0xd1, 0x73, 0x45, 0x3b, 0xab, 0x8a, 0x76, 0xde, 0x2b, 0xda, 0xb9, - 0x9e, 0x2a, 0x1d, 0x6e, 0x17, 0x33, 0x36, 0xb7, 0x77, 0xbc, 0x89, 0xb3, 0x5e, 0xb5, 0xf3, 0x58, - 0x38, 0xc7, 0x97, 0xad, 0x65, 0xb8, 0x77, 0x12, 0x66, 0x3b, 0xeb, 0x62, 0xa7, 0x5f, 0x01, 0x00, - 0x00, 0xff, 0xff, 0x56, 0x99, 0x88, 0x28, 0xab, 0x01, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x50, 0x4f, 0x4b, 0xc3, 0x30, + 0x14, 0x6f, 0xa6, 0x28, 0x06, 0x84, 0x59, 0x3d, 0x94, 0x32, 0xc2, 0x28, 0x08, 0x03, 0x59, 0xc2, + 0xdc, 0x27, 0xd0, 0x7b, 0x2f, 0x15, 0x04, 0xbd, 0x48, 0xb6, 0x86, 0x18, 0xa8, 0x49, 0xc8, 0xcb, + 0xca, 0x3c, 0xea, 0xcd, 0x9b, 0xe0, 0x97, 0xf2, 0x38, 0xf0, 0xe2, 0x51, 0x5a, 0x3f, 0x88, 0xb0, + 0xda, 0xa2, 0xc3, 0x83, 0xb7, 0xf7, 0xde, 0xef, 0x1f, 0xef, 0x87, 0x07, 0x73, 0x51, 0x08, 0xf0, + 0x8a, 0xb3, 0x85, 0x95, 0x8e, 0xe7, 0x82, 0x95, 0x13, 0xe6, 0x97, 0xd4, 0x3a, 0xe3, 0x4d, 0x78, + 0xd8, 0xa2, 0xf4, 0x1b, 0xa5, 0xe5, 0x24, 0x1e, 0x48, 0x63, 0x64, 0x21, 0x18, 0xb7, 0x8a, 0x71, + 0xad, 0x8d, 0xe7, 0x5e, 0x19, 0x0d, 0x8d, 0x24, 0xb9, 0xc2, 0xfd, 0x14, 0xe4, 0x85, 0x92, 0x9a, + 0x17, 0x97, 0xc2, 0x81, 0x32, 0x3a, 0x3c, 0xc1, 0x07, 0x25, 0x2f, 0x54, 0xce, 0xbd, 0x71, 0x37, + 0x3c, 0xcf, 0x9d, 0x00, 0x88, 0xd0, 0x10, 0x8d, 0xf6, 0xb2, 0x7e, 0x07, 0x9c, 0x35, 0xf7, 0x30, + 0xc2, 0xbb, 0x65, 0xa3, 0x8b, 0x7a, 0x43, 0x34, 0xda, 0xce, 0xda, 0x35, 0x89, 0x71, 0xb4, 0x69, + 0x9d, 0x09, 0xb0, 0x46, 0x83, 0x38, 0x7d, 0x42, 0x78, 0x2b, 0x05, 0x19, 0x3e, 0x20, 0xbc, 0xff, + 0x3b, 0xfc, 0x98, 0xfe, 0xf1, 0x04, 0xdd, 0x34, 0x8a, 0xc7, 0xff, 0xa2, 0xb5, 0x79, 0x49, 0xfc, + 0xf8, 0xf6, 0xf9, 0xd2, 0x3b, 0x4a, 0xc2, 0x9f, 0xbd, 0xc1, 0x9a, 0x7a, 0x9e, 0xbe, 0x56, 0x04, + 0xad, 0x2a, 0x82, 0x3e, 0x2a, 0x82, 0x9e, 0x6b, 0x12, 0xac, 0x6a, 0x12, 0xbc, 0xd7, 0x24, 0xb8, + 0x9e, 0x4a, 0xe5, 0x6f, 0x17, 0x33, 0x3a, 0x37, 0x77, 0xac, 0x8d, 0x33, 0x4e, 0x76, 0xf3, 0x98, + 0x5b, 0xcb, 0x96, 0x9d, 0xa5, 0xbf, 0xb7, 0x02, 0x66, 0x3b, 0xeb, 0x62, 0xa7, 0x5f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x7d, 0x45, 0x22, 0x3c, 0xab, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/upgrade/types/tx.pb.gw.go b/x/upgrade/types/tx.pb.gw.go index 496e87adf0..429e98cf87 100644 --- a/x/upgrade/types/tx.pb.gw.go +++ b/x/upgrade/types/tx.pb.gw.go @@ -75,7 +75,7 @@ func local_request_Msg_SignalVersion_0(ctx context.Context, marshaler runtime.Ma // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterMsgHandlerFromEndpoint instead. func RegisterMsgHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServer) error { - mux.Handle("GET", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -139,7 +139,7 @@ func RegisterMsgHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.C // "MsgClient" to call the correct interceptors. func RegisterMsgHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgClient) error { - mux.Handle("GET", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_Msg_SignalVersion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) From 6418b64fb308ad6ef84fd0b5474c009540f84586 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Tue, 28 Nov 2023 15:55:05 -0500 Subject: [PATCH 23/26] chore: make proto-gen --- x/upgrade/types/params.pb.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/upgrade/types/params.pb.go b/x/upgrade/types/params.pb.go index 2a8326c3a5..2e93ae61ec 100644 --- a/x/upgrade/types/params.pb.go +++ b/x/upgrade/types/params.pb.go @@ -27,8 +27,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the upgrade module. type Params struct { - // SignalQuorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. + // SignalQuorum represents the minimum voting power for an upgrade to go + // through. It must be at least 2/3. SignalQuorum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=signal_quorum,json=signalQuorum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"signal_quorum"` } From 6156f3e5270dff980a0708f77fe5309da5152126 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 29 Nov 2023 15:18:56 +0100 Subject: [PATCH 24/26] remove params and fix the threshold calculation --- app/app.go | 2 +- proto/celestia/upgrade/v1/params.proto | 17 - proto/celestia/upgrade/v1/query.proto | 14 +- x/upgrade/keeper.go | 43 +-- x/upgrade/module.go | 2 +- x/upgrade/params.go | 24 -- x/upgrade/tally_test.go | 78 ++--- x/upgrade/types/params.go | 60 ---- x/upgrade/types/params.pb.go | 320 ------------------- x/upgrade/types/query.pb.go | 410 ++----------------------- x/upgrade/types/query.pb.gw.go | 65 ---- 11 files changed, 80 insertions(+), 955 deletions(-) delete mode 100644 proto/celestia/upgrade/v1/params.proto delete mode 100644 x/upgrade/params.go delete mode 100644 x/upgrade/types/params.go delete mode 100644 x/upgrade/types/params.pb.go diff --git a/app/app.go b/app/app.go index e3e1b32cda..1676818832 100644 --- a/app/app.go +++ b/app/app.go @@ -336,7 +336,7 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], upgradeHeight, app.StakingKeeper, app.GetSubspace(upgradetypes.ModuleName)) + app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], upgradeHeight, app.StakingKeeper) app.BlobstreamKeeper = *bsmodulekeeper.NewKeeper( appCodec, diff --git a/proto/celestia/upgrade/v1/params.proto b/proto/celestia/upgrade/v1/params.proto deleted file mode 100644 index fe8f7f8932..0000000000 --- a/proto/celestia/upgrade/v1/params.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; -package celestia.upgrade.v1; - -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; - -import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; - -// Params defines the parameters for the upgrade module. -message Params { - // SignalQuorum represents the minimum voting power for an upgrade to go - // through. It must be at least 2/3. - bytes signal_quorum = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; -} diff --git a/proto/celestia/upgrade/v1/query.proto b/proto/celestia/upgrade/v1/query.proto index b4c95d63b7..d8580d6268 100644 --- a/proto/celestia/upgrade/v1/query.proto +++ b/proto/celestia/upgrade/v1/query.proto @@ -2,17 +2,11 @@ syntax = "proto3"; package celestia.upgrade.v1; import "google/api/annotations.proto"; -import "celestia/upgrade/v1/params.proto"; option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; // Query defines the upgrade Query service. service Query { - // Params allows the querying of the params - rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/upgrade/v1/params"; - } - // VersionTally allows the querying of the tally of voting power by all // validators that have signalled for each version rpc VersionTally(QueryVersionTallyRequest) @@ -21,12 +15,6 @@ service Query { } } -// QueryParamsRequest is the request type for the Params RPC method. -message QueryParamsRequest {} - -// QueryParamsResponse is the response type for the Params RPC method. -message QueryParamsResponse { Params params = 1; } - // QueryVersionTallyRequest is the request type for the UpgradeStatus RPC // method. message QueryVersionTallyRequest { uint64 version = 1; } @@ -35,6 +23,6 @@ message QueryVersionTallyRequest { uint64 version = 1; } // method. message QueryVersionTallyResponse { uint64 voting_power = 1; - uint64 threshold = 2; + uint64 threshold_power = 2; uint64 total_voting_power = 3; } diff --git a/x/upgrade/keeper.go b/x/upgrade/keeper.go index db918d74aa..483f68ee66 100644 --- a/x/upgrade/keeper.go +++ b/x/upgrade/keeper.go @@ -8,7 +8,6 @@ import ( "github.com/celestiaorg/celestia-app/x/upgrade/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -16,8 +15,27 @@ import ( var ( _ types.MsgServer = Keeper{} _ types.QueryServer = Keeper{} + + defaultSignalTheshold = Fraction{Numerator: 5, Denominator: 6} ) +type Fraction struct { + Numerator int64 + Denominator int64 +} + +// SignalThreshold is the fraction of voting power that is required +// to signal for a version change. It is set to 5/6 as the middle point +// between 2/3 and 3/3 providing 1/6 fault tolerance to halting the +// network during an upgrade period. It can be modified through a +// hard fork change that modified the app version +func SignalThreshold(version uint64) Fraction { + switch version { + default: + return defaultSignalTheshold + } +} + type Keeper struct { // we use the same upgrade store key so existing IBC client state can // safely be ported over without any migration @@ -35,9 +53,6 @@ type Keeper struct { // staking keeper is used to fetch validators to calculate the total power // signalled to a version stakingKeeper StakingKeeper - - // paramStore provides access to the signal quorum param - paramStore paramtypes.Subspace } // NewKeeper constructs an upgrade keeper @@ -45,13 +60,11 @@ func NewKeeper( storeKey storetypes.StoreKey, upgradeHeight int64, stakingKeeper StakingKeeper, - paramStore paramtypes.Subspace, ) Keeper { return Keeper{ storeKey: storeKey, upgradeHeight: upgradeHeight, stakingKeeper: stakingKeeper, - paramStore: paramStore, } } @@ -100,18 +113,11 @@ func (k Keeper) VersionTally(ctx context.Context, req *types.QueryVersionTallyRe threshold := k.GetVotingPowerThreshold(sdkCtx) return &types.QueryVersionTallyResponse{ VotingPower: currentVotingPower.Uint64(), - Threshold: threshold.Uint64(), + ThresholdPower: threshold.Uint64(), TotalVotingPower: totalVotingPower.Uint64(), }, nil } -// Params is a method required by the QueryServer interface -func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - params := k.GetParams(sdkCtx) - return &types.QueryParamsResponse{Params: ¶ms}, nil -} - // SetValidatorVersion saves a signalled version for a validator using the keeper's store key func (k Keeper) SetValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddress, version uint64) { store := ctx.KVStore(k.storeKey) @@ -169,13 +175,12 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, threshold int64) (bool, uint64 } // GetVotingPowerThreshold returns the voting power threshold required to -// upgrade to a new version. It converts the signal quorum parameter which -// is a number between 0 and math.MaxUint32 representing a fraction and -// then multiplies it by the total voting power +// upgrade to a new version. func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) sdkmath.Int { - quorum := k.SignalQuorum(ctx) + // contract: totalVotingPower should not exceed MaxUit64 totalVotingPower := k.stakingKeeper.GetLastTotalPower(ctx) - return quorum.MulInt(totalVotingPower).RoundInt() + thresholdFraction := SignalThreshold(ctx.BlockHeader().Version.App) + return totalVotingPower.MulRaw(thresholdFraction.Numerator).QuoRaw(thresholdFraction.Denominator) } // ShouldUpgradeToV2 returns true if the current height is one before diff --git a/x/upgrade/module.go b/x/upgrade/module.go index ae87be6a67..a69c54dd24 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -22,7 +22,7 @@ func init() { } const ( - consensusVersion uint64 = 2 + consensusVersion uint64 = 3 ) var ( diff --git a/x/upgrade/params.go b/x/upgrade/params.go deleted file mode 100644 index e792dd3d8b..0000000000 --- a/x/upgrade/params.go +++ /dev/null @@ -1,24 +0,0 @@ -package upgrade - -import ( - "github.com/celestiaorg/celestia-app/x/upgrade/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GetParams gets all parameters as types.Params -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams( - k.SignalQuorum(ctx), - ) -} - -// SetParams sets the params -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramStore.SetParamSet(ctx, ¶ms) -} - -// SignalQuorum returns the SignalQuorum param -func (k Keeper) SignalQuorum(ctx sdk.Context) (res sdk.Dec) { - k.paramStore.Get(ctx, types.KeySignalQuorum, &res) - return res -} diff --git a/x/upgrade/tally_test.go b/x/upgrade/tally_test.go index 76139f73a7..994e74043f 100644 --- a/x/upgrade/tally_test.go +++ b/x/upgrade/tally_test.go @@ -6,8 +6,6 @@ import ( "cosmossdk.io/math" "github.com/celestiaorg/celestia-app/x/upgrade" "github.com/celestiaorg/celestia-app/x/upgrade/types" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -15,24 +13,12 @@ import ( testutil "github.com/celestiaorg/celestia-app/test/util" storetypes "github.com/cosmos/cosmos-sdk/store/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmversion "github.com/tendermint/tendermint/proto/tendermint/version" tmdb "github.com/tendermint/tm-db" ) -func TestSignalQuorum(t *testing.T) { - upgradeKeeper, ctx, _ := setup(t) - require.Equal(t, types.DefaultSignalQuorum, upgradeKeeper.SignalQuorum(ctx)) - require.EqualValues(t, 100, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) - newParams := types.DefaultParams() - newParams.SignalQuorum = types.MinSignalQuorum - upgradeKeeper.SetParams(ctx, newParams) - require.Equal(t, types.MinSignalQuorum, upgradeKeeper.SignalQuorum(ctx)) - require.EqualValues(t, 80, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) -} - func TestSignalVersion(t *testing.T) { upgradeKeeper, ctx, _ := setup(t) goCtx := sdk.WrapSDKContext(ctx) @@ -63,8 +49,8 @@ func TestSignalVersion(t *testing.T) { Version: 2, }) require.NoError(t, err) - require.EqualValues(t, 30, res.VotingPower) - require.EqualValues(t, 100, res.Threshold) + require.EqualValues(t, 40, res.VotingPower) + require.EqualValues(t, 100, res.ThresholdPower) require.EqualValues(t, 120, res.TotalVotingPower) } @@ -92,8 +78,8 @@ func TestTallyingLogic(t *testing.T) { Version: 2, }) require.NoError(t, err) - require.EqualValues(t, 30, res.VotingPower) - require.EqualValues(t, 100, res.Threshold) + require.EqualValues(t, 40, res.VotingPower) + require.EqualValues(t, 100, res.ThresholdPower) require.EqualValues(t, 120, res.TotalVotingPower) _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ @@ -106,8 +92,8 @@ func TestTallyingLogic(t *testing.T) { Version: 2, }) require.NoError(t, err) - require.EqualValues(t, 80, res.VotingPower) - require.EqualValues(t, 100, res.Threshold) + require.EqualValues(t, 100, res.VotingPower) + require.EqualValues(t, 100, res.ThresholdPower) require.EqualValues(t, 120, res.TotalVotingPower) upgradeKeeper.EndBlock(ctx) @@ -115,18 +101,7 @@ func TestTallyingLogic(t *testing.T) { require.False(t, shouldUpgrade) require.Equal(t, uint64(0), version) - // modify the quorum so we are right on the boundary 80/120 = 2/3 - newParams := types.DefaultParams() - newParams.SignalQuorum = types.MinSignalQuorum - upgradeKeeper.SetParams(ctx, newParams) - - upgradeKeeper.EndBlock(ctx) - shouldUpgrade, version = upgradeKeeper.ShouldUpgrade() - require.False(t, shouldUpgrade) - require.Equal(t, uint64(0), version) - require.EqualValues(t, 80, upgradeKeeper.GetVotingPowerThreshold(ctx).Int64()) - - // we now have 81/120 = 0.675 > 2/3 + // we now have 101/120 _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ ValidatorAddress: testutil.ValAddrs[1].String(), Version: 2, @@ -156,25 +131,25 @@ func TestTallyingLogic(t *testing.T) { Version: 2, }) require.NoError(t, err) - require.EqualValues(t, 51, res.VotingPower) - require.EqualValues(t, 80, res.Threshold) + require.EqualValues(t, 61, res.VotingPower) + require.EqualValues(t, 100, res.ThresholdPower) require.EqualValues(t, 120, res.TotalVotingPower) // remove one of the validators from the set - delete(mockStakingKeeper.validators, testutil.ValAddrs[2].String()) - mockStakingKeeper.totalVotingPower -= 50 + delete(mockStakingKeeper.validators, testutil.ValAddrs[1].String()) + mockStakingKeeper.totalVotingPower-- res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ Version: 2, }) require.NoError(t, err) - require.EqualValues(t, 1, res.VotingPower) - require.EqualValues(t, 47, res.Threshold) - require.EqualValues(t, 70, res.TotalVotingPower) + require.EqualValues(t, 60, res.VotingPower) + require.EqualValues(t, 99, res.ThresholdPower) + require.EqualValues(t, 119, res.TotalVotingPower) // That validator should not be able to signal a version _, err = upgradeKeeper.SignalVersion(goCtx, &types.MsgSignalVersion{ - ValidatorAddress: testutil.ValAddrs[2].String(), + ValidatorAddress: testutil.ValAddrs[1].String(), Version: 2, }) require.Error(t, err) @@ -182,12 +157,8 @@ func TestTallyingLogic(t *testing.T) { func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { upgradeStore := sdk.NewKVStoreKey(types.StoreKey) - paramStoreKey := sdk.NewKVStoreKey(paramtypes.StoreKey) - tStoreKey := storetypes.NewTransientStoreKey(paramtypes.TStoreKey) db := tmdb.NewMemDB() stateStore := store.NewCommitMultiStore(db) - stateStore.MountStoreWithDB(paramStoreKey, storetypes.StoreTypeIAVL, nil) - stateStore.MountStoreWithDB(tStoreKey, storetypes.StoreTypeTransient, nil) stateStore.MountStoreWithDB(upgradeStore, storetypes.StoreTypeIAVL, nil) require.NoError(t, stateStore.LoadLatestVersion()) mockCtx := sdk.NewContext(stateStore, tmproto.Header{ @@ -199,25 +170,14 @@ func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { mockStakingKeeper := &mockStakingKeeper{ totalVotingPower: 120, validators: map[string]int64{ - testutil.ValAddrs[0].String(): 30, + testutil.ValAddrs[0].String(): 40, testutil.ValAddrs[1].String(): 1, - testutil.ValAddrs[2].String(): 50, - testutil.ValAddrs[3].String(): 39, + testutil.ValAddrs[2].String(): 60, + testutil.ValAddrs[3].String(): 19, }, } - registry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(registry) - - paramsSubspace := paramtypes.NewSubspace(cdc, - testutil.MakeTestCodec(), - paramStoreKey, - tStoreKey, - types.ModuleName, - ) - paramsSubspace.WithKeyTable(types.ParamKeyTable()) - upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, mockStakingKeeper, paramsSubspace) - upgradeKeeper.SetParams(mockCtx, types.DefaultParams()) + upgradeKeeper := upgrade.NewKeeper(upgradeStore, 0, mockStakingKeeper) return upgradeKeeper, mockCtx, mockStakingKeeper } diff --git a/x/upgrade/types/params.go b/x/upgrade/types/params.go deleted file mode 100644 index ef95cc0e84..0000000000 --- a/x/upgrade/types/params.go +++ /dev/null @@ -1,60 +0,0 @@ -package types - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -var KeySignalQuorum = []byte("SignalQuorum") - -// ParamKeyTable returns the param key table for the upgrade module -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -func NewParams(signalQuorum sdk.Dec) Params { - return Params{ - SignalQuorum: signalQuorum, - } -} - -func DefaultParams() Params { - return Params{ - SignalQuorum: DefaultSignalQuorum, - } -} - -var ( - // 2/3 - MinSignalQuorum = sdk.NewDec(2).Quo(sdk.NewDec(3)) - // 5/6 - DefaultSignalQuorum = sdk.NewDec(5).Quo(sdk.NewDec(6)) -) - -func (p Params) Validate() error { - return validateSignalQuorum(p.SignalQuorum) -} - -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeySignalQuorum, &p.SignalQuorum, validateSignalQuorum), - } -} - -func validateSignalQuorum(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - if v.LT(MinSignalQuorum) { - return fmt.Errorf("quorum must be at least %s (2/3), got %s", MinSignalQuorum, v) - } - - if v.GT(sdk.OneDec()) { - return fmt.Errorf("quorum must be less than or equal to 1, got %s", v) - } - - return nil -} diff --git a/x/upgrade/types/params.pb.go b/x/upgrade/types/params.pb.go deleted file mode 100644 index 2a8326c3a5..0000000000 --- a/x/upgrade/types/params.pb.go +++ /dev/null @@ -1,320 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: celestia/upgrade/v1/params.proto - -package types - -import ( - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/gogo/protobuf/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 - -// Params defines the parameters for the upgrade module. -type Params struct { - // SignalQuorum represents the minimum voting power for an upgrade to go through. - // It must be at least 2/3. - SignalQuorum github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=signal_quorum,json=signalQuorum,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"signal_quorum"` -} - -func (m *Params) Reset() { *m = Params{} } -func (m *Params) String() string { return proto.CompactTextString(m) } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_b4f657414f35d610, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Params)(nil), "celestia.upgrade.v1.Params") -} - -func init() { proto.RegisterFile("celestia/upgrade/v1/params.proto", fileDescriptor_b4f657414f35d610) } - -var fileDescriptor_b4f657414f35d610 = []byte{ - // 225 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0x4e, 0xcd, 0x49, - 0x2d, 0x2e, 0xc9, 0x4c, 0xd4, 0x2f, 0x2d, 0x48, 0x2f, 0x4a, 0x4c, 0x49, 0xd5, 0x2f, 0x33, 0xd4, - 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0xa9, - 0xd0, 0x83, 0xaa, 0xd0, 0x2b, 0x33, 0x94, 0x92, 0x4c, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0x8e, 0x07, - 0x2b, 0xd1, 0x87, 0x70, 0x20, 0xea, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0x21, 0xe2, 0x20, 0x16, - 0x44, 0x54, 0x29, 0x96, 0x8b, 0x2d, 0x00, 0x6c, 0xaa, 0x50, 0x30, 0x17, 0x6f, 0x71, 0x66, 0x7a, - 0x5e, 0x62, 0x4e, 0x7c, 0x61, 0x69, 0x7e, 0x51, 0x69, 0xae, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, - 0x93, 0xde, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9, 0xab, 0xa5, 0x67, 0x96, 0x64, 0x94, 0x26, - 0xe9, 0x25, 0xe7, 0xe7, 0x42, 0xcd, 0x85, 0x52, 0xba, 0xc5, 0x29, 0xd9, 0xfa, 0x25, 0x95, 0x05, - 0xa9, 0xc5, 0x7a, 0x2e, 0xa9, 0xc9, 0x41, 0x3c, 0x10, 0x43, 0x02, 0xc1, 0x66, 0x38, 0xf9, 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, 0x31, 0xb2, 0x79, 0x50, 0x9f, 0xe4, - 0x17, 0xa5, 0xc3, 0xd9, 0xba, 0x89, 0x05, 0x05, 0xfa, 0x15, 0x70, 0xdf, 0x83, 0x2d, 0x48, 0x62, - 0x03, 0x3b, 0xda, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xca, 0xe4, 0x67, 0x15, 0x1e, 0x01, 0x00, - 0x00, -} - -func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.SignalQuorum.Size() - i -= size - if _, err := m.SignalQuorum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintParams(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func encodeVarintParams(dAtA []byte, offset int, v uint64) int { - offset -= sovParams(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.SignalQuorum.Size() - n += 1 + l + sovParams(uint64(l)) - return n -} - -func sovParams(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozParams(x uint64) (n int) { - return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) 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: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SignalQuorum", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParams - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthParams - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthParams - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.SignalQuorum.Unmarshal(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 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowParams - } - 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, ErrIntOverflowParams - } - 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, ErrIntOverflowParams - } - 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, ErrInvalidLengthParams - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupParams - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthParams - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/upgrade/types/query.pb.go b/x/upgrade/types/query.pb.go index fe0ad604be..ed6653ac17 100644 --- a/x/upgrade/types/query.pb.go +++ b/x/upgrade/types/query.pb.go @@ -28,88 +28,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// QueryParamsRequest is the request type for the Params RPC method. -type QueryParamsRequest struct { -} - -func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } -func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } -func (*QueryParamsRequest) ProtoMessage() {} -func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{0} -} -func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsRequest.Merge(m, src) -} -func (m *QueryParamsRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo - -// QueryParamsResponse is the response type for the Params RPC method. -type QueryParamsResponse struct { - Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` -} - -func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } -func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } -func (*QueryParamsResponse) ProtoMessage() {} -func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{1} -} -func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryParamsResponse.Merge(m, src) -} -func (m *QueryParamsResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryParamsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo - -func (m *QueryParamsResponse) GetParams() *Params { - if m != nil { - return m.Params - } - return nil -} - // QueryVersionTallyRequest is the request type for the UpgradeStatus RPC // method. type QueryVersionTallyRequest struct { @@ -120,7 +38,7 @@ func (m *QueryVersionTallyRequest) Reset() { *m = QueryVersionTallyReque func (m *QueryVersionTallyRequest) String() string { return proto.CompactTextString(m) } func (*QueryVersionTallyRequest) ProtoMessage() {} func (*QueryVersionTallyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{2} + return fileDescriptor_7dd2290b21d03efa, []int{0} } func (m *QueryVersionTallyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -160,7 +78,7 @@ func (m *QueryVersionTallyRequest) GetVersion() uint64 { // method. type QueryVersionTallyResponse struct { VotingPower uint64 `protobuf:"varint,1,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` - Threshold uint64 `protobuf:"varint,2,opt,name=threshold,proto3" json:"threshold,omitempty"` + ThresholdPower uint64 `protobuf:"varint,2,opt,name=threshold_power,json=thresholdPower,proto3" json:"threshold_power,omitempty"` TotalVotingPower uint64 `protobuf:"varint,3,opt,name=total_voting_power,json=totalVotingPower,proto3" json:"total_voting_power,omitempty"` } @@ -168,7 +86,7 @@ func (m *QueryVersionTallyResponse) Reset() { *m = QueryVersionTallyResp func (m *QueryVersionTallyResponse) String() string { return proto.CompactTextString(m) } func (*QueryVersionTallyResponse) ProtoMessage() {} func (*QueryVersionTallyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{3} + return fileDescriptor_7dd2290b21d03efa, []int{1} } func (m *QueryVersionTallyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -204,9 +122,9 @@ func (m *QueryVersionTallyResponse) GetVotingPower() uint64 { return 0 } -func (m *QueryVersionTallyResponse) GetThreshold() uint64 { +func (m *QueryVersionTallyResponse) GetThresholdPower() uint64 { if m != nil { - return m.Threshold + return m.ThresholdPower } return 0 } @@ -219,8 +137,6 @@ func (m *QueryVersionTallyResponse) GetTotalVotingPower() uint64 { } func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "celestia.upgrade.v1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "celestia.upgrade.v1.QueryParamsResponse") proto.RegisterType((*QueryVersionTallyRequest)(nil), "celestia.upgrade.v1.QueryVersionTallyRequest") proto.RegisterType((*QueryVersionTallyResponse)(nil), "celestia.upgrade.v1.QueryVersionTallyResponse") } @@ -228,32 +144,28 @@ func init() { func init() { proto.RegisterFile("celestia/upgrade/v1/query.proto", fileDescriptor_7dd2290b21d03efa) } var fileDescriptor_7dd2290b21d03efa = []byte{ - // 399 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xbf, 0x6f, 0xda, 0x40, - 0x14, 0xc6, 0xb4, 0xa5, 0xea, 0xc1, 0x50, 0x1d, 0x0c, 0xae, 0xa1, 0x2e, 0x75, 0x87, 0x32, 0x14, - 0x9f, 0x80, 0xfe, 0x05, 0x1d, 0x2b, 0x45, 0x22, 0x28, 0x62, 0xc8, 0x82, 0x0e, 0x38, 0x19, 0x4b, - 0xc6, 0x77, 0xdc, 0x9d, 0x4d, 0x50, 0x94, 0x25, 0x63, 0xa6, 0x28, 0x51, 0xfe, 0xa7, 0x8c, 0x48, - 0x59, 0x32, 0x46, 0x90, 0x3f, 0x24, 0xe2, 0x7c, 0xfc, 0x12, 0x8e, 0x92, 0xcd, 0xfe, 0xde, 0xf7, - 0x7d, 0xef, 0x7b, 0xef, 0x1d, 0xf8, 0x31, 0x20, 0x01, 0x11, 0xd2, 0xc7, 0x28, 0x62, 0x1e, 0xc7, - 0x43, 0x82, 0xe2, 0x06, 0x9a, 0x44, 0x84, 0xcf, 0x5c, 0xc6, 0xa9, 0xa4, 0xb0, 0xb8, 0x26, 0xb8, - 0x9a, 0xe0, 0xc6, 0x0d, 0xab, 0xe2, 0x51, 0xea, 0x05, 0x04, 0x61, 0xe6, 0x23, 0x1c, 0x86, 0x54, - 0x62, 0xe9, 0xd3, 0x50, 0x24, 0x12, 0xab, 0x9a, 0xe6, 0xc9, 0x30, 0xc7, 0x63, 0xcd, 0x70, 0x4a, - 0x00, 0x1e, 0xaf, 0x7a, 0xb4, 0x15, 0xd8, 0x21, 0x93, 0x88, 0x08, 0xe9, 0xfc, 0x07, 0xc5, 0x3d, - 0x54, 0x30, 0x1a, 0x0a, 0x02, 0x5b, 0x20, 0x97, 0x88, 0x4d, 0xa3, 0x6a, 0xd4, 0xf2, 0xcd, 0xb2, - 0x9b, 0x12, 0xc9, 0xd5, 0x22, 0x4d, 0x75, 0xfe, 0x02, 0x53, 0x79, 0x75, 0x09, 0x17, 0x3e, 0x0d, - 0x4f, 0x70, 0x10, 0xcc, 0x74, 0x1f, 0x68, 0x82, 0xcf, 0x71, 0x02, 0x2b, 0xc7, 0x8f, 0x9d, 0xf5, - 0xaf, 0x73, 0x65, 0x80, 0x6f, 0x29, 0x32, 0x1d, 0xe4, 0x27, 0x28, 0xc4, 0x54, 0xfa, 0xa1, 0xd7, - 0x63, 0x74, 0x4a, 0xb8, 0x16, 0xe7, 0x13, 0xac, 0xbd, 0x82, 0x60, 0x05, 0x7c, 0x91, 0x23, 0x4e, - 0xc4, 0x88, 0x06, 0x43, 0x33, 0xab, 0xea, 0x5b, 0x00, 0xfe, 0x01, 0x50, 0x52, 0x89, 0x83, 0xde, - 0x9e, 0xcd, 0x07, 0x45, 0xfb, 0xaa, 0x2a, 0xdd, 0xad, 0x57, 0xf3, 0x2e, 0x0b, 0x3e, 0xa9, 0x30, - 0x70, 0x0a, 0x72, 0xc9, 0x78, 0xf0, 0x77, 0xea, 0xec, 0x87, 0xbb, 0xb4, 0x6a, 0x6f, 0x13, 0x93, - 0xa9, 0x1c, 0xeb, 0xf2, 0xe1, 0xf9, 0x36, 0x5b, 0x82, 0xf0, 0xf0, 0x5a, 0xf0, 0xc6, 0x00, 0x85, - 0xdd, 0x55, 0xc0, 0xfa, 0xeb, 0xb6, 0x29, 0x9b, 0xb6, 0xdc, 0xf7, 0xd2, 0x75, 0x96, 0x5f, 0x2a, - 0xcb, 0x77, 0x58, 0xde, 0xcd, 0x22, 0x57, 0x14, 0x74, 0xae, 0x6f, 0x74, 0xf1, 0xef, 0xe8, 0x7e, - 0x61, 0x1b, 0xf3, 0x85, 0x6d, 0x3c, 0x2d, 0x6c, 0xe3, 0x7a, 0x69, 0x67, 0xe6, 0x4b, 0x3b, 0xf3, - 0xb8, 0xb4, 0x33, 0xa7, 0x2d, 0xcf, 0x97, 0xa3, 0xa8, 0xef, 0x0e, 0xe8, 0x18, 0xad, 0x1b, 0x53, - 0xee, 0x6d, 0xbe, 0xeb, 0x98, 0x31, 0x74, 0xb6, 0xf1, 0x96, 0x33, 0x46, 0x44, 0x3f, 0xa7, 0x9e, - 0x64, 0xeb, 0x25, 0x00, 0x00, 0xff, 0xff, 0x37, 0x43, 0xf1, 0x62, 0x0a, 0x03, 0x00, 0x00, + // 331 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x4e, 0x02, 0x31, + 0x14, 0x85, 0x29, 0xfe, 0x25, 0x95, 0xa8, 0xa9, 0x1b, 0x44, 0x1d, 0x15, 0x17, 0xba, 0x90, 0x36, + 0x88, 0x4f, 0xe0, 0xde, 0x44, 0x89, 0x61, 0xe1, 0x86, 0x14, 0x68, 0x86, 0x49, 0xc6, 0xb9, 0xa5, + 0xbd, 0x33, 0x4a, 0x8c, 0x1b, 0x9f, 0xc0, 0x68, 0xdc, 0xf9, 0x40, 0x2e, 0x49, 0xdc, 0xb8, 0x34, + 0xe0, 0x83, 0x18, 0x66, 0x86, 0x11, 0x13, 0x4c, 0xdc, 0xb5, 0xa7, 0xdf, 0x39, 0xbd, 0x3f, 0x74, + 0xa7, 0xad, 0x7c, 0x65, 0xd1, 0x93, 0x22, 0xd4, 0xae, 0x91, 0x1d, 0x25, 0xa2, 0xaa, 0xe8, 0x85, + 0xca, 0xf4, 0xb9, 0x36, 0x80, 0xc0, 0xd6, 0x27, 0x00, 0x4f, 0x01, 0x1e, 0x55, 0x4b, 0x5b, 0x2e, + 0x80, 0xeb, 0x2b, 0x21, 0xb5, 0x27, 0x64, 0x10, 0x00, 0x4a, 0xf4, 0x20, 0xb0, 0x89, 0xa5, 0x7c, + 0x42, 0x8b, 0x17, 0xe3, 0x84, 0x86, 0x32, 0xd6, 0x83, 0xe0, 0x52, 0xfa, 0x7e, 0xbf, 0xae, 0x7a, + 0xa1, 0xb2, 0xc8, 0x8a, 0x74, 0x29, 0x4a, 0xe4, 0x22, 0xd9, 0x25, 0x87, 0xf3, 0xf5, 0xc9, 0xb5, + 0xfc, 0x42, 0xe8, 0xc6, 0x0c, 0x9b, 0xd5, 0x10, 0x58, 0xc5, 0xf6, 0x68, 0x21, 0x02, 0xf4, 0x02, + 0xb7, 0xa9, 0xe1, 0x46, 0x99, 0xd4, 0xbc, 0x9c, 0x68, 0xe7, 0x63, 0x89, 0x1d, 0xd0, 0x55, 0xec, + 0x1a, 0x65, 0xbb, 0xe0, 0x77, 0x52, 0x2a, 0x1f, 0x53, 0x2b, 0x99, 0x9c, 0x80, 0x47, 0x94, 0x21, + 0xa0, 0xf4, 0x9b, 0xbf, 0x12, 0xe7, 0x62, 0x76, 0x2d, 0x7e, 0x69, 0xfc, 0xc4, 0x1e, 0xbf, 0x12, + 0xba, 0x10, 0xd7, 0xc5, 0x9e, 0x08, 0x2d, 0x4c, 0x17, 0xc7, 0x2a, 0x7c, 0xc6, 0x70, 0xf8, 0x5f, + 0xbd, 0x97, 0xf8, 0x7f, 0xf1, 0xa4, 0xe7, 0xf2, 0xfe, 0xc3, 0xfb, 0xd7, 0x73, 0x7e, 0x9b, 0x6d, + 0x4e, 0xef, 0x06, 0xc7, 0x88, 0xb8, 0x4b, 0xa7, 0x76, 0x7f, 0x7a, 0xf6, 0x36, 0x74, 0xc8, 0x60, + 0xe8, 0x90, 0xcf, 0xa1, 0x43, 0x1e, 0x47, 0x4e, 0x6e, 0x30, 0x72, 0x72, 0x1f, 0x23, 0x27, 0x77, + 0x55, 0x73, 0x3d, 0xec, 0x86, 0x2d, 0xde, 0x86, 0x6b, 0x31, 0xf9, 0x18, 0x8c, 0x9b, 0x9d, 0x2b, + 0x52, 0x6b, 0x71, 0x9b, 0x65, 0x63, 0x5f, 0x2b, 0xdb, 0x5a, 0x8c, 0x57, 0x58, 0xfb, 0x0e, 0x00, + 0x00, 0xff, 0xff, 0xa9, 0x02, 0x48, 0x0f, 0x18, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -268,8 +180,6 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Params allows the querying of the params - Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) // VersionTally allows the querying of the tally of voting power by all // validators that have signalled for each version VersionTally(ctx context.Context, in *QueryVersionTallyRequest, opts ...grpc.CallOption) (*QueryVersionTallyResponse, error) @@ -283,15 +193,6 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { - out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Query/Params", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *queryClient) VersionTally(ctx context.Context, in *QueryVersionTallyRequest, opts ...grpc.CallOption) (*QueryVersionTallyResponse, error) { out := new(QueryVersionTallyResponse) err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Query/VersionTally", in, out, opts...) @@ -303,8 +204,6 @@ func (c *queryClient) VersionTally(ctx context.Context, in *QueryVersionTallyReq // QueryServer is the server API for Query service. type QueryServer interface { - // Params allows the querying of the params - Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) // VersionTally allows the querying of the tally of voting power by all // validators that have signalled for each version VersionTally(context.Context, *QueryVersionTallyRequest) (*QueryVersionTallyResponse, error) @@ -314,9 +213,6 @@ type QueryServer interface { type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") -} func (*UnimplementedQueryServer) VersionTally(ctx context.Context, req *QueryVersionTallyRequest) (*QueryVersionTallyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VersionTally not implemented") } @@ -325,24 +221,6 @@ func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryParamsRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Params(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/celestia.upgrade.v1.Query/Params", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Query_VersionTally_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryVersionTallyRequest) if err := dec(in); err != nil { @@ -365,10 +243,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "celestia.upgrade.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "Params", - Handler: _Query_Params_Handler, - }, { MethodName: "VersionTally", Handler: _Query_VersionTally_Handler, @@ -378,64 +252,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Metadata: "celestia/upgrade/v1/query.proto", } -func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Params != nil { - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *QueryVersionTallyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -489,8 +305,8 @@ func (m *QueryVersionTallyResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro i-- dAtA[i] = 0x18 } - if m.Threshold != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Threshold)) + if m.ThresholdPower != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ThresholdPower)) i-- dAtA[i] = 0x10 } @@ -513,28 +329,6 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryParamsRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryParamsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Params != nil { - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - } - return n -} - func (m *QueryVersionTallyRequest) Size() (n int) { if m == nil { return 0 @@ -556,8 +350,8 @@ func (m *QueryVersionTallyResponse) Size() (n int) { if m.VotingPower != 0 { n += 1 + sovQuery(uint64(m.VotingPower)) } - if m.Threshold != 0 { - n += 1 + sovQuery(uint64(m.Threshold)) + if m.ThresholdPower != 0 { + n += 1 + sovQuery(uint64(m.ThresholdPower)) } if m.TotalVotingPower != 0 { n += 1 + sovQuery(uint64(m.TotalVotingPower)) @@ -571,142 +365,6 @@ func sovQuery(x uint64) (n int) { func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *QueryParamsRequest) 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 ErrIntOverflowQuery - } - 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: QueryParamsRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryParamsResponse) 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 ErrIntOverflowQuery - } - 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: QueryParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - 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 ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Params == nil { - m.Params = &Params{} - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *QueryVersionTallyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -826,9 +484,9 @@ func (m *QueryVersionTallyResponse) Unmarshal(dAtA []byte) error { } case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Threshold", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ThresholdPower", wireType) } - m.Threshold = 0 + m.ThresholdPower = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -838,7 +496,7 @@ func (m *QueryVersionTallyResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Threshold |= uint64(b&0x7F) << shift + m.ThresholdPower |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/upgrade/types/query.pb.gw.go b/x/upgrade/types/query.pb.gw.go index fb87b44f83..03b777ca29 100644 --- a/x/upgrade/types/query.pb.gw.go +++ b/x/upgrade/types/query.pb.gw.go @@ -33,24 +33,6 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join -func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryParamsRequest - var metadata runtime.ServerMetadata - - msg, err := server.Params(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_VersionTally_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryVersionTallyRequest var metadata runtime.ServerMetadata @@ -111,29 +93,6 @@ func local_request_Query_VersionTally_0(ctx context.Context, marshaler runtime.M // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_VersionTally_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -198,26 +157,6 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_VersionTally_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -242,13 +181,9 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"upgrade", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_VersionTally_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"upgrade", "v1", "tally", "version"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage - forward_Query_VersionTally_0 = runtime.ForwardResponseMessage ) From 41f80b16b98aeac7052ef71425b6700ada7ba28d Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 29 Nov 2023 17:04:39 +0100 Subject: [PATCH 25/26] update the codec with the query server --- x/upgrade/types/codec.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 7cf5a81e89..e28b2d28f3 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -15,4 +15,5 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // RegisterInterfaces registers the upgrade module types. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) + msgservice.RegisterMsgServiceDesc(registry, &_Query_serviceDesc) } From 6274c98fe169e5a925169a5c6d49f563b017eb07 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 29 Nov 2023 17:09:40 +0100 Subject: [PATCH 26/26] revert the last commit --- x/upgrade/types/codec.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index e28b2d28f3..7cf5a81e89 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -15,5 +15,4 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // RegisterInterfaces registers the upgrade module types. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) - msgservice.RegisterMsgServiceDesc(registry, &_Query_serviceDesc) }