From 3e413243db3c20941de2306debe7d8c28404f324 Mon Sep 17 00:00:00 2001 From: Marko Date: Mon, 12 Aug 2024 16:19:13 +0200 Subject: [PATCH] refactor: remove consensus messages (#21248) --- core/app/app.go | 26 ++++---- core/context/context.go | 7 ++- server/v2/appmanager/appmanager.go | 8 +-- server/v2/cometbft/abci.go | 42 ++++++++----- server/v2/cometbft/config.go | 4 +- server/v2/go.mod | 14 +++-- server/v2/go.sum | 29 +++++---- server/v2/stf/stf.go | 36 +++-------- simapp/app.go | 26 ++++++-- simapp/app_config.go | 1 + simapp/v2/app_config.go | 1 + x/consensus/keeper/keeper.go | 60 +++++++++++++++---- x/consensus/module.go | 27 +++++++-- .../proto/cosmos/consensus/v1/query.proto | 1 - .../proto/cosmos/consensus/v1/tx.proto | 1 - 15 files changed, 180 insertions(+), 103 deletions(-) diff --git a/core/app/app.go b/core/app/app.go index 2295b0300835..b377d42cef38 100644 --- a/core/app/app.go +++ b/core/app/app.go @@ -21,26 +21,24 @@ type QueryResponse struct { } type BlockRequest[T transaction.Tx] struct { - Height uint64 - Time time.Time - Hash []byte - ChainId string - AppHash []byte - Txs []T - ConsensusMessages []transaction.Msg + Height uint64 + Time time.Time + Hash []byte + ChainId string + AppHash []byte + Txs []T // IsGenesis indicates if this block is the first block of the chain. IsGenesis bool } type BlockResponse struct { - Apphash []byte - ConsensusMessagesResponse []transaction.Msg - ValidatorUpdates []appmodulev2.ValidatorUpdate - PreBlockEvents []event.Event - BeginBlockEvents []event.Event - TxResults []TxResult - EndBlockEvents []event.Event + Apphash []byte + ValidatorUpdates []appmodulev2.ValidatorUpdate + PreBlockEvents []event.Event + BeginBlockEvents []event.Event + TxResults []TxResult + EndBlockEvents []event.Event } type RequestInitChain struct { diff --git a/core/context/context.go b/core/context/context.go index 6803bd7eb44b..54ed6b46236f 100644 --- a/core/context/context.go +++ b/core/context/context.go @@ -3,12 +3,17 @@ package context type ( execModeKey struct{} cometInfoKey struct{} + initInfoKey struct{} environmentKey struct{} ) var ( - ExecModeKey = execModeKey{} + // ExecModeKey is the context key for setting the execution mode. + ExecModeKey = execModeKey{} + // CometInfoKey is the context key for allowing modules to get CometInfo. CometInfoKey = cometInfoKey{} + // InitInfoKey is the context key for setting consensus params from genesis in the consensus module. + InitInfoKey = initInfoKey{} // EnvironmentContextKey is the context key for the environment. // A caller should not assume the environment is available in each context. diff --git a/server/v2/appmanager/appmanager.go b/server/v2/appmanager/appmanager.go index cef0fc57cce7..66e38a762a18 100644 --- a/server/v2/appmanager/appmanager.go +++ b/server/v2/appmanager/appmanager.go @@ -36,6 +36,7 @@ type AppManager[T transaction.Tx] struct { stf StateTransitionFunction[T] } +// InitGenesis initializes the genesis state of the application. func (a AppManager[T]) InitGenesis( ctx context.Context, blockRequest *appmanager.BlockRequest[T], @@ -65,8 +66,6 @@ func (a AppManager[T]) InitGenesis( return nil, nil, fmt.Errorf("failed to import genesis state: %w", err) } // run block - // TODO: in an ideal world, genesis state is simply an initial state being applied - // unaware of what that state means in relation to every other blockRequest.Txs = genTxs blockResponse, blockZeroState, err := a.stf.DeliverBlock(ctx, blockRequest, genesisState) @@ -75,18 +74,17 @@ func (a AppManager[T]) InitGenesis( } // after executing block 0, we extract the changes and apply them to the genesis state. - blockZeroStateChanges, err := blockZeroState.GetStateChanges() + stateChanges, err := blockZeroState.GetStateChanges() if err != nil { return nil, nil, fmt.Errorf("failed to get block zero state changes: %w", err) } - err = genesisState.ApplyStateChanges(blockZeroStateChanges) + err = genesisState.ApplyStateChanges(stateChanges) if err != nil { return nil, nil, fmt.Errorf("failed to apply block zero state changes to genesis state: %w", err) } return blockResponse, genesisState, err - // consensus server will need to set the version of the store } // ExportGenesis exports the genesis state of the application. diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 2fa91216ed85..b7a300b05f5e 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -13,6 +13,7 @@ import ( coreappmgr "cosmossdk.io/core/app" "cosmossdk.io/core/comet" + corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/event" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" @@ -152,10 +153,23 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc return nil, err } - // cp, err := c.GetConsensusParams(ctx) - // if err != nil { - // return nil, err - // } + // if height is 0, we dont know the consensus params + var appVersion uint64 = 0 + if version > 0 { + cp, err := c.GetConsensusParams(ctx) + // if the consensus params are not found, we set the app version to 0 + // in the case that the start version is > 0 + if cp == nil || errors.Is(err, errors.New("collections: not found")) { + appVersion = 0 + } else if err != nil { + return nil, err + } else { + appVersion = cp.Version.GetApp() + } + if err != nil { + return nil, err + } + } cid, err := c.store.LastCommitID() if err != nil { @@ -165,7 +179,7 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc return &abciproto.InfoResponse{ Data: c.appName, Version: c.version, - AppVersion: 0, // TODO fetch consensus params? + AppVersion: appVersion, LastBlockHeight: int64(version), LastBlockAppHash: cid.Hash, }, nil @@ -234,14 +248,15 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe c.initialHeight = 1 } - var consMessages []transaction.Msg if req.ConsensusParams != nil { - consMessages = append(consMessages, &consensustypes.MsgUpdateParams{ + ctx = context.WithValue(ctx, corecontext.InitInfoKey, &consensustypes.MsgUpdateParams{ Authority: c.consensusAuthority, Block: req.ConsensusParams.Block, Evidence: req.ConsensusParams.Evidence, Validator: req.ConsensusParams.Validator, Abci: req.ConsensusParams.Abci, + Synchrony: req.ConsensusParams.Synchrony, + Feature: req.ConsensusParams.Feature, }) } @@ -254,13 +269,12 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe bz := sha256.Sum256([]byte{}) br := &coreappmgr.BlockRequest[T]{ - Height: uint64(req.InitialHeight - 1), - Time: req.Time, - Hash: bz[:], - AppHash: ci.Hash, - ChainId: req.ChainId, - ConsensusMessages: consMessages, - IsGenesis: true, + Height: uint64(req.InitialHeight - 1), + Time: req.Time, + Hash: bz[:], + AppHash: ci.Hash, + ChainId: req.ChainId, + IsGenesis: true, } blockresponse, genesisState, err := c.app.InitGenesis( diff --git a/server/v2/cometbft/config.go b/server/v2/cometbft/config.go index 3f03e383c601..56860a78ddaf 100644 --- a/server/v2/cometbft/config.go +++ b/server/v2/cometbft/config.go @@ -43,14 +43,14 @@ type CfgOption func(*Config) // OverwriteDefaultConfigTomlConfig overwrites the default comet config with the new config. func OverwriteDefaultConfigTomlConfig(newCfg *cmtcfg.Config) CfgOption { return func(cfg *Config) { - cfg.ConfigTomlConfig = newCfg // nolint:ineffassign,staticcheck // We want to overwrite everything + cfg.ConfigTomlConfig = newCfg } } // OverwriteDefaultAppTomlConfig overwrites the default comet config with the new config. func OverwriteDefaultAppTomlConfig(newCfg *AppTomlConfig) CfgOption { return func(cfg *Config) { - cfg.AppTomlConfig = newCfg // nolint:ineffassign,staticcheck // We want to overwrite everything + cfg.AppTomlConfig = newCfg } } diff --git a/server/v2/go.mod b/server/v2/go.mod index d9f90121405a..602ffa6cdfa7 100644 --- a/server/v2/go.mod +++ b/server/v2/go.mod @@ -26,9 +26,9 @@ require ( github.com/golang/protobuf v1.5.4 github.com/gorilla/mux v1.8.1 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/hashicorp/go-hclog v1.6.2 + github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-metrics v0.5.3 - github.com/hashicorp/go-plugin v1.6.0 + github.com/hashicorp/go-plugin v1.6.1 github.com/mitchellh/mapstructure v1.5.0 github.com/pelletier/go-toml/v2 v2.2.2 github.com/prometheus/client_golang v1.19.1 @@ -46,8 +46,9 @@ require ( require ( cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect - github.com/DataDog/datadog-go v3.2.0+incompatible // indirect + github.com/DataDog/datadog-go v4.8.3+incompatible // indirect github.com/DataDog/zstd v1.5.5 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cockroachdb/errors v1.11.1 // indirect @@ -60,7 +61,7 @@ require ( github.com/cosmos/ics23/go v0.10.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/dot v1.6.2 // indirect - github.com/fatih/color v1.15.0 // indirect + github.com/fatih/color v1.17.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/gogo/googleapis v1.4.1 // indirect @@ -74,7 +75,7 @@ require ( github.com/hashicorp/yamux v0.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jhump/protoreflect v1.15.3 // indirect - github.com/klauspost/compress v1.17.7 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect @@ -85,6 +86,7 @@ require ( github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oklog/run v1.1.0 // indirect + github.com/onsi/gomega v1.28.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect @@ -100,9 +102,11 @@ require ( github.com/tidwall/btree v1.7.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.28.0 // indirect golang.org/x/sys v0.24.0 // indirect golang.org/x/text v0.17.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a // indirect diff --git a/server/v2/go.sum b/server/v2/go.sum index 8b891e449ae8..c87730bfa317 100644 --- a/server/v2/go.sum +++ b/server/v2/go.sum @@ -5,10 +5,13 @@ cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5/go.mod h1:0CuYKkFHxc1v cosmossdk.io/log v1.4.0 h1:Ttt9d6fQ0GlktwhcysOeNiIjixW7l0rYBocmoXOb11k= cosmossdk.io/log v1.4.0/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q= +github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -79,8 +82,8 @@ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go. 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/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -148,15 +151,15 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v1.6.2 h1:NOtoftovWkDheyUM/8JW3QMiXyxJK3uHRK7wV04nD2I= -github.com/hashicorp/go-hclog v1.6.2/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-metrics v0.5.3 h1:M5uADWMOGCTUNU1YuC4hfknOeHNaX54LDm4oYSucoNE= github.com/hashicorp/go-metrics v0.5.3/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= -github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A= -github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= +github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= +github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= @@ -180,8 +183,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -234,8 +237,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q= -github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= +github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= +github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= @@ -341,6 +344,8 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -425,6 +430,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/server/v2/stf/stf.go b/server/v2/stf/stf.go index 2231f893b55b..d3cd2405b23b 100644 --- a/server/v2/stf/stf.go +++ b/server/v2/stf/stf.go @@ -106,10 +106,6 @@ func (s STF[T]) DeliverBlock( exCtx := s.makeContext(ctx, appmanager.ConsensusIdentity, newState, internal.ExecModeFinalize) exCtx.setHeaderInfo(hi) - consMessagesResponses, err := s.runConsensusMessages(exCtx, block.ConsensusMessages) - if err != nil { - return nil, nil, fmt.Errorf("failed to execute consensus messages: %w", err) - } // reset events exCtx.events = make([]event.Event, 0) @@ -160,13 +156,12 @@ func (s STF[T]) DeliverBlock( } return &appmanager.BlockResponse{ - Apphash: nil, - ConsensusMessagesResponse: consMessagesResponses, - ValidatorUpdates: valset, - PreBlockEvents: preBlockEvents, - BeginBlockEvents: beginBlockEvents, - TxResults: txResults, - EndBlockEvents: endBlockEvents, + Apphash: nil, + ValidatorUpdates: valset, + PreBlockEvents: preBlockEvents, + BeginBlockEvents: beginBlockEvents, + TxResults: txResults, + EndBlockEvents: endBlockEvents, }, newState, nil } @@ -333,6 +328,7 @@ func (s STF[T]) runTxMsgs( return msgResps, consumed, execCtx.events, nil } +// preBlock executes the pre block logic. func (s STF[T]) preBlock( ctx *executionContext, txs []T, @@ -352,22 +348,7 @@ func (s STF[T]) preBlock( return ctx.events, nil } -func (s STF[T]) runConsensusMessages( - ctx *executionContext, - messages []transaction.Msg, -) ([]transaction.Msg, error) { - responses := make([]transaction.Msg, len(messages)) - for i := range messages { - resp, err := s.msgRouter.InvokeUntyped(ctx, messages[i]) - if err != nil { - return nil, err - } - responses[i] = resp - } - - return responses, nil -} - +// beginBlock executes the begin block logic. func (s STF[T]) beginBlock( ctx *executionContext, ) (beginBlockEvents []event.Event, err error) { @@ -386,6 +367,7 @@ func (s STF[T]) beginBlock( return ctx.events, nil } +// endBlock executes the end block logic. func (s STF[T]) endBlock( ctx *executionContext, ) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { diff --git a/simapp/app.go b/simapp/app.go index 6c2424e29c60..a03a9e69f518 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -51,6 +51,7 @@ import ( "cosmossdk.io/x/consensus" consensusparamkeeper "cosmossdk.io/x/consensus/keeper" consensusparamtypes "cosmossdk.io/x/consensus/types" + consensustypes "cosmossdk.io/x/consensus/types" distr "cosmossdk.io/x/distribution" distrkeeper "cosmossdk.io/x/distribution/keeper" distrtypes "cosmossdk.io/x/distribution/types" @@ -501,11 +502,26 @@ func NewSimApp( // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. genesisModuleOrder := []string{ - accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName, - distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, - minttypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, upgradetypes.ModuleName, - vestingtypes.ModuleName, consensusparamtypes.ModuleName, circuittypes.ModuleName, pooltypes.ModuleName, + consensustypes.ModuleName, + accounts.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + nft.ModuleName, + group.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + consensusparamtypes.ModuleName, + circuittypes.ModuleName, + pooltypes.ModuleName, epochstypes.ModuleName, } app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) diff --git a/simapp/app_config.go b/simapp/app_config.go index e92ac2ce03fe..8918475184e1 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -149,6 +149,7 @@ var ( // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. InitGenesis: []string{ + consensustypes.ModuleName, accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName, diff --git a/simapp/v2/app_config.go b/simapp/v2/app_config.go index c3e5e0492935..ab54100a3f09 100644 --- a/simapp/v2/app_config.go +++ b/simapp/v2/app_config.go @@ -139,6 +139,7 @@ var ( // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. InitGenesis: []string{ + consensustypes.ModuleName, accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName, diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 9236f76f8ddb..548bf61d9337 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/event" "cosmossdk.io/x/consensus/exported" "cosmossdk.io/x/consensus/types" @@ -41,6 +42,31 @@ func (k *Keeper) GetAuthority() string { return k.authority } +// InitGenesis initializes the initial state of the module +func (k *Keeper) InitGenesis(ctx context.Context) error { + value, ok := ctx.Value(corecontext.InitInfoKey).(*types.MsgUpdateParams) + if !ok { + // no error for appv1 and appv2 + return nil + } + if value == nil { + // no error for appv1 + return nil + } + + consensusParams, err := value.ToProtoConsensusParams() + if err != nil { + return err + } + + nextParams, err := k.paramCheck(ctx, consensusParams) + if err != nil { + return err + } + + return k.ParamsStore.Set(ctx, nextParams.ToProto()) +} + // Querier var _ types.QueryServer = Keeper{} @@ -69,6 +95,27 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (* return nil, err } + nextParams, err := k.paramCheck(ctx, consensusParams) + if err != nil { + return nil, err + } + + if err := k.ParamsStore.Set(ctx, nextParams.ToProto()); err != nil { + return nil, err + } + + if err := k.EventService.EventManager(ctx).EmitKV( + "update_consensus_params", + event.NewAttribute("authority", msg.Authority), + event.NewAttribute("parameters", consensusParams.String())); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} + +// paramCheck validates the consensus params +func (k Keeper) paramCheck(ctx context.Context, consensusParams cmtproto.ConsensusParams) (*cmttypes.ConsensusParams, error) { paramsProto, err := k.ParamsStore.Get(ctx) var params cmttypes.ConsensusParams @@ -92,16 +139,5 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (* return nil, err } - if err := k.ParamsStore.Set(ctx, nextParams.ToProto()); err != nil { - return nil, err - } - - if err := k.EventService.EventManager(ctx).EmitKV( - "update_consensus_params", - event.NewAttribute("authority", msg.Authority), - event.NewAttribute("parameters", consensusParams.String())); err != nil { - return nil, err - } - - return &types.MsgUpdateParamsResponse{}, nil + return &nextParams, nil } diff --git a/x/consensus/module.go b/x/consensus/module.go index 02504cfcff19..72c04496addc 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -2,6 +2,7 @@ package consensus import ( "context" + "encoding/json" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" @@ -25,6 +26,7 @@ var ( _ module.HasGRPCGateway = AppModule{} _ appmodule.AppModule = AppModule{} + _ appmodule.HasGenesis = AppModule{} _ appmodule.HasRegisterInterfaces = AppModule{} ) @@ -42,6 +44,26 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { } } +// InitGenesis performs genesis initialization for the bank module. +func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error { + return am.keeper.InitGenesis(ctx) +} + +// DefaultGenesis returns the default genesis state. (Noop) +func (am AppModule) DefaultGenesis() json.RawMessage { + return nil +} + +// ValidateGenesis validates the genesis state. (Noop) +func (am AppModule) ValidateGenesis(data json.RawMessage) error { + return nil +} + +// ExportGenesis returns the exported genesis state. (Noop) +func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) { + return nil, nil +} + // IsAppModule implements the appmodule.AppModule interface. func (AppModule) IsAppModule() {} @@ -75,8 +97,3 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // ConsensusVersion implements HasConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } - -// RegisterConsensusMessages registers the consensus module's messages. -func (am AppModule) RegisterConsensusMessages(builder any) { - // std.RegisterConsensusHandler(builder ,am.keeper.SetParams) // TODO uncomment when api is available -} diff --git a/x/consensus/proto/cosmos/consensus/v1/query.proto b/x/consensus/proto/cosmos/consensus/v1/query.proto index 4841c5aed367..9a84c1909766 100644 --- a/x/consensus/proto/cosmos/consensus/v1/query.proto +++ b/x/consensus/proto/cosmos/consensus/v1/query.proto @@ -4,7 +4,6 @@ package cosmos.consensus.v1; import "google/api/annotations.proto"; import "cometbft/types/v1/params.proto"; -import "cosmos/consensus/v1/consensus.proto"; option go_package = "cosmossdk.io/x/consensus/types"; diff --git a/x/consensus/proto/cosmos/consensus/v1/tx.proto b/x/consensus/proto/cosmos/consensus/v1/tx.proto index afecf31d97b8..d0cdde493a9c 100644 --- a/x/consensus/proto/cosmos/consensus/v1/tx.proto +++ b/x/consensus/proto/cosmos/consensus/v1/tx.proto @@ -6,7 +6,6 @@ import "amino/amino.proto"; import "cosmos_proto/cosmos.proto"; import "cosmos/msg/v1/msg.proto"; import "cometbft/types/v1/params.proto"; -import "cometbft/abci/v1/types.proto"; option go_package = "cosmossdk.io/x/consensus/types";