diff --git a/core/appmodule/module.go b/core/appmodule/module.go index 8936c121c1c4..75ebcf68dd7f 100644 --- a/core/appmodule/module.go +++ b/core/appmodule/module.go @@ -3,8 +3,9 @@ package appmodule import ( "context" - "cosmossdk.io/core/appmodule/v2" "google.golang.org/grpc" + + "cosmossdk.io/core/appmodule/v2" ) // AppModule is a tag interface for app module implementations to use as a basis diff --git a/core/appmodule/v2/handlers.go b/core/appmodule/v2/handlers.go index f7753c4723e3..7bfc46bf24cf 100644 --- a/core/appmodule/v2/handlers.go +++ b/core/appmodule/v2/handlers.go @@ -12,7 +12,7 @@ type ( Handler = func(ctx context.Context, msg Message) (msgResp Message, err error) // PostMsgHandler runs after Handler, only if Handler does not error. If PostMsgHandler errors // then the execution is reverted. - PostMsgHandler = func(ctx context.Context, msg Message, msgResp Message) error + PostMsgHandler = func(ctx context.Context, msg, msgResp Message) error ) // RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the @@ -86,7 +86,7 @@ func RegisterPostHandler[Req, Resp Message]( router PostMsgRouter, handler func(ctx context.Context, msg Req, msgResp Resp) error, ) { - untypedHandler := func(ctx context.Context, m Message, mResp Message) error { + untypedHandler := func(ctx context.Context, m, mResp Message) error { typed, ok := m.(Req) if !ok { return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req)) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 25c3b20e2c07..c7ec14c59f79 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -16,6 +16,7 @@ import ( runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2" cosmosmsg "cosmossdk.io/api/cosmos/msg/v1" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/log" "cosmossdk.io/runtime/v2/protocompat" @@ -84,7 +85,7 @@ func (m *MM) BeginBlock() func(ctx context.Context) error { } // EndBlock runs the end-block logic of all modules and tx validator updates -func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error)) { +func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error)) { validatorUpdates := []abci.ValidatorUpdate{} endBlock := func(ctx context.Context) error { @@ -118,12 +119,12 @@ func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate fun return nil } - valUpdate := func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { - valUpdates := []appmodule.ValidatorUpdate{} + valUpdate := func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { + valUpdates := []appmodulev2.ValidatorUpdate{} // get validator updates of legacy modules using HasABCIEndBlock for i, v := range validatorUpdates { - valUpdates[i] = appmodule.ValidatorUpdate{ + valUpdates[i] = appmodulev2.ValidatorUpdate{ PubKey: v.PubKey.GetEd25519(), Power: v.Power, } @@ -131,7 +132,7 @@ func (m *MM) EndBlock() (endblock func(ctx context.Context) error, valupdate fun // get validator updates of modules implementing directly the new HasUpdateValidators interface for _, v := range m.modules { - if module, ok := v.(appmodule.HasUpdateValidators); ok { + if module, ok := v.(appmodulev2.HasUpdateValidators); ok { up, err := module.UpdateValidators(ctx) if err != nil { return nil, err @@ -170,7 +171,7 @@ func (m *MM) PreBlocker() func(ctx context.Context, txs []transaction.Tx) error func (m *MM) TxValidation() func(ctx context.Context, tx transaction.Tx) error { return func(ctx context.Context, tx transaction.Tx) error { for _, moduleName := range m.config.TxValidation { - if module, ok := m.modules[moduleName].(appmodule.HasTxValidation[transaction.Tx]); ok { + if module, ok := m.modules[moduleName].(appmodulev2.HasTxValidation[transaction.Tx]); ok { if err := module.TxValidator(ctx, tx); err != nil { return fmt.Errorf("failed to run txvalidator for %s: %w", moduleName, err) } diff --git a/server/v2/cometbft/utils.go b/server/v2/cometbft/utils.go index 6e6914eb9d70..81cfc7db1816 100644 --- a/server/v2/cometbft/utils.go +++ b/server/v2/cometbft/utils.go @@ -20,7 +20,7 @@ import ( v1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" consensusv1 "cosmossdk.io/api/cosmos/consensus/v1" sdkabci "cosmossdk.io/api/tendermint/abci" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" errorsmod "cosmossdk.io/errors" "cosmossdk.io/server/v2/core/appmanager" @@ -124,7 +124,7 @@ func finalizeBlockResponse( return resp, nil } -func intoABCIValidatorUpdates(updates []appmodule.ValidatorUpdate) []abci.ValidatorUpdate { +func intoABCIValidatorUpdates(updates []appmodulev2.ValidatorUpdate) []abci.ValidatorUpdate { valsetUpdates := make([]abci.ValidatorUpdate, len(updates)) for i := range updates { diff --git a/server/v2/core/appmanager/app.go b/server/v2/core/appmanager/app.go index 799c5c708437..6a3e2e294c11 100644 --- a/server/v2/core/appmanager/app.go +++ b/server/v2/core/appmanager/app.go @@ -4,7 +4,7 @@ import ( "context" "time" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/core/event" "cosmossdk.io/server/v2/core/store" @@ -39,7 +39,7 @@ type BlockRequest[T any] struct { type BlockResponse struct { Apphash []byte - ValidatorUpdates []appmodule.ValidatorUpdate + ValidatorUpdates []appmodulev2.ValidatorUpdate PreBlockEvents []event.Event BeginBlockEvents []event.Event TxResults []TxResult @@ -49,13 +49,13 @@ type BlockResponse struct { type RequestInitChain struct { Time time.Time ChainId string - Validators []appmodule.ValidatorUpdate + Validators []appmodulev2.ValidatorUpdate AppStateBytes []byte InitialHeight int64 } type ResponseInitChain struct { - Validators []appmodule.ValidatorUpdate + Validators []appmodulev2.ValidatorUpdate AppHash []byte } diff --git a/server/v2/core/go.mod b/server/v2/core/go.mod index 3c0db362b3c4..fde74bb4ac6b 100644 --- a/server/v2/core/go.mod +++ b/server/v2/core/go.mod @@ -12,16 +12,11 @@ require ( require ( cosmossdk.io/log v1.3.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rs/zerolog v1.32.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect - google.golang.org/grpc v1.61.1 // indirect ) diff --git a/server/v2/core/go.sum b/server/v2/core/go.sum index 1c1b30a3271e..6c775b18f2f6 100644 --- a/server/v2/core/go.sum +++ b/server/v2/core/go.sum @@ -4,10 +4,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR2g= github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -23,22 +19,11 @@ github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk= -google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= -google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index 8ff434cb4332..90305ebf03d9 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -19,7 +19,6 @@ require ( cosmossdk.io/log v1.3.1 // indirect github.com/cosmos/gogoproto v1.4.11 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/kr/text v0.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -28,10 +27,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/zerolog v1.32.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect - google.golang.org/grpc v1.61.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index b04032607682..cc21a9a6c976 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -6,10 +6,6 @@ github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSoht github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -38,22 +34,11 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk= -google.golang.org/grpc v1.61.1 h1:kLAiWrZs7YeDM6MumDe7m3y4aM6wacLzM1Y/wiLP9XY= -google.golang.org/grpc v1.61.1/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/server/v2/stf/stf.go b/server/v2/stf/stf.go index cadb538b4657..1584aff9fd80 100644 --- a/server/v2/stf/stf.go +++ b/server/v2/stf/stf.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" corecontext "cosmossdk.io/core/context" coreevent "cosmossdk.io/core/event" "cosmossdk.io/core/gas" @@ -25,7 +25,7 @@ type STF[T transaction.Tx] struct { doPreBlock func(ctx context.Context, txs []T) error doBeginBlock func(ctx context.Context) error doEndBlock func(ctx context.Context) error - doValidatorUpdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) + doValidatorUpdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) doTxValidation func(ctx context.Context, tx T) error // TODO: rewrite antehandlers remove simulate postTxExec func(ctx context.Context, tx T, success bool) error @@ -43,7 +43,7 @@ func NewSTF[T transaction.Tx]( doBeginBlock func(ctx context.Context) error, doEndBlock func(ctx context.Context) error, doTxValidation func(ctx context.Context, tx T) error, - doValidatorUpdate func(ctx context.Context) ([]appmodule.ValidatorUpdate, error), + doValidatorUpdate func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error), branch func(store store.ReaderMap) store.WriterMap, ) *STF[T] { return &STF[T]{ @@ -260,7 +260,7 @@ func (s STF[T]) beginBlock(ctx context.Context, state store.WriterMap) (beginBlo return bbCtx.events, nil } -func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodule.ValidatorUpdate, error) { +func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { ebCtx := s.makeContext(ctx, []transaction.Identity{runtimeIdentity}, state, gas.NoGasLimit, corecontext.ExecModeFinalize) err := s.doEndBlock(ebCtx) if err != nil { @@ -285,7 +285,7 @@ func (s STF[T]) endBlock(ctx context.Context, state store.WriterMap) ([]event.Ev } // validatorUpdates returns the validator updates for the current block. It is called by endBlock after the endblock execution has concluded -func (s STF[T]) validatorUpdates(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodule.ValidatorUpdate, error) { +func (s STF[T]) validatorUpdates(ctx context.Context, state store.WriterMap) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { ebCtx := s.makeContext(ctx, []transaction.Identity{runtimeIdentity}, state, gas.NoGasLimit, corecontext.ExecModeFinalize) valSetUpdates, err := s.doValidatorUpdate(ebCtx) if err != nil { @@ -375,7 +375,7 @@ func applyStateChanges(dst, src store.WriterMap) error { return dst.ApplyStateChanges(changes) } -// isCtxCancelled reports if the context was cancelled. +// isCtxCancelled reports if the context was canceled. func isCtxCancelled(ctx context.Context) error { select { case <-ctx.Done(): diff --git a/server/v2/stf/stf_test.go b/server/v2/stf/stf_test.go index 7718c12a72d4..fbb1cb6ae476 100644 --- a/server/v2/stf/stf_test.go +++ b/server/v2/stf/stf_test.go @@ -5,16 +5,16 @@ import ( "fmt" "testing" - coregas "cosmossdk.io/core/gas" - "cosmossdk.io/server/v2/stf/gas" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/wrapperspb" - "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" + coregas "cosmossdk.io/core/gas" "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/core/appmanager" "cosmossdk.io/server/v2/core/store" "cosmossdk.io/server/v2/stf/branch" + "cosmossdk.io/server/v2/stf/gas" "cosmossdk.io/server/v2/stf/mock" ) @@ -41,7 +41,7 @@ func TestSTF(t *testing.T) { kvSet(t, ctx, "end-block") return nil }, - doValidatorUpdate: func(ctx context.Context) ([]appmodule.ValidatorUpdate, error) { return nil, nil }, + doValidatorUpdate: func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { return nil, nil }, doTxValidation: func(ctx context.Context, tx mock.Tx) error { kvSet(t, ctx, "validate") return nil diff --git a/simapp/app_test.go b/simapp/app_test.go index e693a729998b..9fac84fe370a 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/depinject" "cosmossdk.io/log" "cosmossdk.io/x/accounts" @@ -247,7 +248,7 @@ func TestInitGenesisOnMigration(t *testing.T) { // Run migrations only for "mock" module. We exclude it from // the VersionMap to simulate upgrading with a new module. _, err := app.ModuleManager.RunMigrations(ctx, app.Configurator(), - module.VersionMap{ + appmodulev2.VersionMap{ "bank": bank.AppModule{}.ConsensusVersion(), "auth": auth.AppModule{}.ConsensusVersion(), "authz": authzmodule.AppModule{}.ConsensusVersion(), @@ -279,7 +280,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx) require.NoError(t, err) for v, i := range app.ModuleManager.Modules { - if i, ok := i.(module.HasConsensusVersion); ok { + if i, ok := i.(appmodulev2.HasConsensusVersion); ok { require.Equal(t, vm[v], i.ConsensusVersion()) } } diff --git a/x/auth/module.go b/x/auth/module.go index f1d8e800ac3d..2ac31d3a984a 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/runtime/v2" "cosmossdk.io/x/auth/ante" @@ -36,10 +37,10 @@ var ( _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} - _ appmodule.AppModule = AppModule{} - _ appmodule.HasTxValidation[transaction.Tx] = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasMigrations = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodulev2.HasTxValidation[transaction.Tx] = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasMigrations = AppModule{} ) // AppModuleBasic defines the basic application module used by the auth module. diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 57168293d93c..f1b0376f63d8 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -25,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -48,7 +47,7 @@ func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height: 11: ") t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -66,7 +65,7 @@ func (s *TestSuite) VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, pro require.ErrorContains(t, err, "UPGRADE \""+proposalName+"\" NEEDED at height: ") t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -167,7 +166,7 @@ func TestHaltIfTooNew(t *testing.T) { s := setupTest(t, 10, map[int64]bool{}) t.Log("Verify that we don't panic with registered plan not in database at all") var called int - s.keeper.SetUpgradeHandler("future", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("future", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { called++ return vm, nil }) @@ -413,7 +412,7 @@ func TestBinaryVersion(t *testing.T) { { "test not panic: upgrade handler is present for last applied upgrade", func() sdk.Context { - s.keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -478,7 +477,7 @@ func TestDowngradeVerification(t *testing.T) { ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1}) // set the handler. - k.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + k.SetUpgradeHandler(planName, func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -493,7 +492,7 @@ func TestDowngradeVerification(t *testing.T) { }{ "valid binary": { preRun: func(k *keeper.Keeper, ctx sdk.Context, name string) { - k.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + k.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) }, diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 939746872769..59b6744656a3 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/header" storetypes "cosmossdk.io/store/types" authtypes "cosmossdk.io/x/auth/types" @@ -19,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -45,7 +45,7 @@ func (suite *UpgradeTestSuite) SetupTest() { suite.Require().NoError(err) suite.encodedAuthority = authority suite.upgradeKeeper = keeper.NewKeeper(skipUpgradeHeights, storeService, suite.encCfg.Codec, suite.T().TempDir(), nil, authority) - err = suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, module.VersionMap{ + err = suite.upgradeKeeper.SetModuleVersionMap(suite.ctx, appmodule.VersionMap{ "bank": 0, }) suite.Require().NoError(err) @@ -133,7 +133,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { err := suite.upgradeKeeper.ScheduleUpgrade(suite.ctx, plan) suite.Require().NoError(err) suite.ctx = suite.ctx.WithHeaderInfo(header.Info{Height: expHeight}) - suite.upgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + suite.upgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) err = suite.upgradeKeeper.ApplyUpgrade(suite.ctx, plan) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 3c9689aad2b7..75c52ecdfd44 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/go-metrics" + "cosmossdk.io/core/appmodule" corestore "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" @@ -28,7 +29,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/types/module" ) type Keeper struct { @@ -40,7 +40,7 @@ type Keeper struct { versionModifier xp.AppVersionModifier // implements setting the protocol version field on BaseApp downgradeVerified bool // tells if we've already sanity checked that this binary version isn't being used against an old state. authority string // the address capable of executing and canceling an upgrade. Usually the gov module account - initVersionMap module.VersionMap // the module version map at init genesis + initVersionMap appmodule.VersionMap // the module version map at init genesis } // NewKeeper constructs an upgrade Keeper which requires the following arguments: @@ -69,13 +69,13 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeService corestore.KVStore // SetInitVersionMap sets the initial version map. // This is only used in app wiring and should not be used in any other context. -func (k *Keeper) SetInitVersionMap(vm module.VersionMap) { +func (k *Keeper) SetInitVersionMap(vm appmodule.VersionMap) { k.initVersionMap = vm } // GetInitVersionMap gets the initial version map // This is only used in upgrade InitGenesis and should not be used in any other context. -func (k *Keeper) GetInitVersionMap() module.VersionMap { +func (k *Keeper) GetInitVersionMap() appmodule.VersionMap { return k.initVersionMap } @@ -87,7 +87,7 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl } // SetModuleVersionMap saves a given version map to state -func (k Keeper) SetModuleVersionMap(ctx context.Context, vm module.VersionMap) error { +func (k Keeper) SetModuleVersionMap(ctx context.Context, vm appmodule.VersionMap) error { if len(vm) > 0 { store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) versionStore := prefix.NewStore(store, []byte{types.VersionMapByte}) @@ -115,7 +115,7 @@ func (k Keeper) SetModuleVersionMap(ctx context.Context, vm module.VersionMap) e // GetModuleVersionMap returns a map of key module name and value module consensus version // as defined in ADR-041. -func (k Keeper) GetModuleVersionMap(ctx context.Context) (module.VersionMap, error) { +func (k Keeper) GetModuleVersionMap(ctx context.Context) (appmodule.VersionMap, error) { store := k.storeService.OpenKVStore(ctx) prefix := []byte{types.VersionMapByte} it, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) @@ -124,7 +124,7 @@ func (k Keeper) GetModuleVersionMap(ctx context.Context) (module.VersionMap, err } defer it.Close() - vm := make(module.VersionMap) + vm := make(appmodule.VersionMap) for ; it.Valid(); it.Next() { moduleBytes := it.Key() // first byte is prefix key, so we remove it here diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index ee87c2f23d89..ea1642bddb0f 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -9,6 +9,7 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/header" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -23,7 +24,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) @@ -166,7 +166,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.upgradeKeeper.SetUpgradeHandler("all-good", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetUpgradeHandler("all-good", func(ctx context.Context, plan types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) err := s.upgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ @@ -287,7 +287,9 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { err = s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) s.Require().EqualError(err, "ApplyUpgrade should never be called without first checking HasHandler") - s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { + return vm, nil + }) err = s.upgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) s.Require().NoError(err) upgradedProtocolVersion, err := s.baseApp.AppVersion(s.ctx) @@ -299,13 +301,13 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { // Tests that the underlying state of x/upgrade is set correctly after // an upgrade. func (s *KeeperTestSuite) TestMigrations() { - initialVM := module.VersionMap{"bank": uint64(1)} + initialVM := appmodule.VersionMap{"bank": uint64(1)} err := s.upgradeKeeper.SetModuleVersionMap(s.ctx, initialVM) s.Require().NoError(err) vmBefore, err := s.upgradeKeeper.GetModuleVersionMap(s.ctx) s.Require().NoError(err) - s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { // simulate upgrading the bank module vm["bank"]++ return vm, nil @@ -332,7 +334,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { require.Equal(int64(0), height) require.NoError(err) - keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test0", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -349,7 +351,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() { require.Equal(int64(10), height) require.NoError(err) - keeper.SetUpgradeHandler("test1", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test1", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -374,7 +376,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() { require := s.Require() // apply first upgrade - keeper.SetUpgradeHandler("test-v0.9", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.9", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) @@ -390,7 +392,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() { require.NoError(err) // apply second upgrade - keeper.SetUpgradeHandler("test-v0.10", func(_ context.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { + keeper.SetUpgradeHandler("test-v0.10", func(_ context.Context, _ types.Plan, vm appmodule.VersionMap) (appmodule.VersionMap, error) { return vm, nil }) diff --git a/x/upgrade/types/handler.go b/x/upgrade/types/handler.go index 80d57da469e2..386fd321017d 100644 --- a/x/upgrade/types/handler.go +++ b/x/upgrade/types/handler.go @@ -3,7 +3,7 @@ package types import ( context "context" - "github.com/cosmos/cosmos-sdk/types/module" + "cosmossdk.io/core/appmodule" ) // UpgradeHandler specifies the type of function that is called when an upgrade @@ -24,4 +24,4 @@ import ( // function. // // Please also refer to docs/core/upgrade.md for more information. -type UpgradeHandler func(ctx context.Context, plan Plan, fromVM module.VersionMap) (module.VersionMap, error) +type UpgradeHandler func(ctx context.Context, plan Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error)