From 928b6c1c66b4067ca5ecf9d80b704ab497a6b2fc Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 15:51:13 +0100 Subject: [PATCH 01/20] start of environment variable --- core/appmodule/environment.go | 19 +++++++++++++++++++ core/appmodule/event.go | 32 -------------------------------- core/appmodule/event_test.go | 17 ----------------- core/event/service.go | 6 +++--- core/gas/meter.go | 13 ++++--------- runtime/events.go | 6 +++--- simapp/app.go | 1 - x/accounts/msg_server.go | 1 - x/accounts/utils_test.go | 6 +++--- x/consensus/keeper/keeper.go | 1 - x/counter/keeper/keeper.go | 1 - 11 files changed, 32 insertions(+), 71 deletions(-) create mode 100644 core/appmodule/environment.go delete mode 100644 core/appmodule/event.go delete mode 100644 core/appmodule/event_test.go diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go new file mode 100644 index 000000000000..da666728691f --- /dev/null +++ b/core/appmodule/environment.go @@ -0,0 +1,19 @@ +package appmodule + +import ( + "cosmossdk.io/core/branch" + "cosmossdk.io/core/event" + "cosmossdk.io/core/gas" + "cosmossdk.io/core/header" + "cosmossdk.io/core/store" +) + +// Environment is used to get all services to their respective module +type Environment struct { + BranchService branch.Service + EventService event.Service + GasService gas.Service + HeaderService header.Service + KvStoreService store.KVStoreService + MemStoreService store.MemoryStoreService +} diff --git a/core/appmodule/event.go b/core/appmodule/event.go deleted file mode 100644 index 0622d6b5a975..000000000000 --- a/core/appmodule/event.go +++ /dev/null @@ -1,32 +0,0 @@ -package appmodule - -import ( - "context" - - "google.golang.org/protobuf/runtime/protoiface" -) - -// HasEventListeners is the extension interface that modules should implement to register -// event listeners. -type HasEventListeners interface { - AppModule - - // RegisterEventListeners registers the module's events listeners. - RegisterEventListeners(registrar *EventListenerRegistrar) -} - -// EventListenerRegistrar allows registering event listeners. -type EventListenerRegistrar struct { - listeners []any -} - -// GetListeners gets the event listeners that have been registered -func (e *EventListenerRegistrar) GetListeners() []any { - return e.listeners -} - -// RegisterEventListener registers an event listener for event type E. If a non-nil error is returned by the listener, -// it will cause the process which emitted the event to fail. -func RegisterEventListener[E protoiface.MessageV1](registrar *EventListenerRegistrar, listener func(context.Context, E) error) { - registrar.listeners = append(registrar.listeners, listener) -} diff --git a/core/appmodule/event_test.go b/core/appmodule/event_test.go deleted file mode 100644 index 739bfa6fb3c9..000000000000 --- a/core/appmodule/event_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package appmodule - -import ( - "context" - "reflect" - "testing" - - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/types/known/timestamppb" -) - -func TestEventListenerRegistrar(t *testing.T) { - registrar := &EventListenerRegistrar{} - RegisterEventListener(registrar, func(ctx context.Context, dummy *timestamppb.Timestamp) error { return nil }) - require.Len(t, registrar.listeners, 1) - require.Equal(t, reflect.Func, reflect.TypeOf(registrar.listeners[0]).Kind()) -} diff --git a/core/event/service.go b/core/event/service.go index b8e09673a58a..3f6b273be06b 100644 --- a/core/event/service.go +++ b/core/event/service.go @@ -21,20 +21,20 @@ type Manager interface { // Callers SHOULD assume that these events may be included in consensus. These events // MUST be emitted deterministically and adding, removing or changing these events SHOULD // be considered state-machine breaking. - Emit(ctx context.Context, event protoiface.MessageV1) error + Emit(event protoiface.MessageV1) error // EmitKV emits an event based on an event and kv-pair attributes. // // These events will not be part of consensus and adding, removing or changing these events is // not a state-machine breaking change. - EmitKV(ctx context.Context, eventType string, attrs ...Attribute) error + EmitKV(eventType string, attrs ...Attribute) error // EmitNonConsensus emits events represented as a protobuf message (as described in ADR 032), without // including it in blockchain consensus. // // These events will not be part of consensus and adding, removing or changing events is // not a state-machine breaking change. - EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error + EmitNonConsensus(event protoiface.MessageV1) error } // KVEventAttribute is a kv-pair event attribute. diff --git a/core/gas/meter.go b/core/gas/meter.go index 2bb735faccab..0774fd2a7733 100644 --- a/core/gas/meter.go +++ b/core/gas/meter.go @@ -26,15 +26,10 @@ type Service interface { WithBlockGasMeter(ctx context.Context, meter Meter) context.Context } -// Meter represents a gas meter. +// Meter represents a gas meter for modules consumption type Meter interface { - GasConsumed() Gas - GasConsumedToLimit() Gas - GasRemaining() Gas + Consume(amount Gas, descriptor string) + Refund(amount Gas, descriptor string) + Remaining() Gas Limit() Gas - ConsumeGas(amount Gas, descriptor string) - RefundGas(amount Gas, descriptor string) - IsPastLimit() bool - IsOutOfGas() bool - String() string } diff --git a/runtime/events.go b/runtime/events.go index 752dcae2bb30..150de335d5df 100644 --- a/runtime/events.go +++ b/runtime/events.go @@ -34,12 +34,12 @@ func NewEventManager(ctx context.Context) event.Manager { // Emit emits an typed event that is defined in the protobuf file. // In the future these events will be added to consensus. -func (e Events) Emit(ctx context.Context, event protoiface.MessageV1) error { +func (e Events) Emit(event protoiface.MessageV1) error { return e.EventManagerI.EmitTypedEvent(event) } // EmitKV emits a key value pair event. -func (e Events) EmitKV(ctx context.Context, eventType string, attrs ...event.Attribute) error { +func (e Events) EmitKV(eventType string, attrs ...event.Attribute) error { attributes := make([]sdk.Attribute, 0, len(attrs)) for _, attr := range attrs { @@ -52,6 +52,6 @@ func (e Events) EmitKV(ctx context.Context, eventType string, attrs ...event.Att // Emit emits an typed event that is defined in the protobuf file. // In the future these events will be added to consensus. -func (e Events) EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error { +func (e Events) EmitNonConsensus(event protoiface.MessageV1) error { return e.EventManagerI.EmitTypedEvent(event) } diff --git a/simapp/app.go b/simapp/app.go index 12daf0637215..170b61fcb1dc 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -282,7 +282,6 @@ func NewSimApp( bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) // add keepers - app.AuthKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) accountsKeeper, err := accounts.NewKeeper( diff --git a/x/accounts/msg_server.go b/x/accounts/msg_server.go index 52fafeec0c38..0216b39d3793 100644 --- a/x/accounts/msg_server.go +++ b/x/accounts/msg_server.go @@ -44,7 +44,6 @@ func (m msgServer) Init(ctx context.Context, request *v1.MsgInit) (*v1.MsgInitRe eventManager := m.k.eventService.EventManager(ctx) err = eventManager.EmitKV( - ctx, "account_creation", event.Attribute{ Key: "address", diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index bcef6b963f26..7f0450c57e15 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -24,13 +24,13 @@ func (a addressCodec) BytesToString(bz []byte) (string, error) { return string type eventService struct{} -func (e eventService) Emit(ctx context.Context, event protoiface.MessageV1) error { return nil } +func (e eventService) Emit(event protoiface.MessageV1) error { return nil } -func (e eventService) EmitKV(ctx context.Context, eventType string, attrs ...event.Attribute) error { +func (e eventService) EmitKV(eventType string, attrs ...event.Attribute) error { return nil } -func (e eventService) EmitNonConsensus(ctx context.Context, event protoiface.MessageV1) error { +func (e eventService) EmitNonConsensus(event protoiface.MessageV1) error { return nil } diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 31315de40532..9e6a068bc15a 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -80,7 +80,6 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (* } if err := k.event.EventManager(ctx).EmitKV( - ctx, "update_consensus_params", event.Attribute{Key: "authority", Value: msg.Authority}, event.Attribute{Key: "parameters", Value: consensusParams.String()}); err != nil { diff --git a/x/counter/keeper/keeper.go b/x/counter/keeper/keeper.go index 8fc152fa3e52..127311d23363 100644 --- a/x/counter/keeper/keeper.go +++ b/x/counter/keeper/keeper.go @@ -68,7 +68,6 @@ func (k Keeper) IncreaseCount(ctx context.Context, msg *types.MsgIncreaseCounter } if err := k.event.EventManager(ctx).EmitKV( - ctx, "increase_counter", event.Attribute{Key: "signer", Value: msg.Signer}, event.Attribute{Key: "new count", Value: fmt.Sprint(num + msg.Count)}); err != nil { From 03394683385f7ff44a95dd2a0796258b5c86b3ef Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 16:59:17 +0100 Subject: [PATCH 02/20] add gas to runtime --- core/appmodule/environment.go | 4 ++-- core/gas/meter.go | 6 ++--- runtime/environment.go | 23 ++++++++++++++++++ runtime/gas.go | 44 +++++++++++++++++++++++++++++++++++ runtime/store.go | 4 ++++ 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 runtime/environment.go create mode 100644 runtime/gas.go diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index da666728691f..0737519777de 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -14,6 +14,6 @@ type Environment struct { EventService event.Service GasService gas.Service HeaderService header.Service - KvStoreService store.KVStoreService - MemStoreService store.MemoryStoreService + KvStoreService map[string]store.KVStoreService + MemStoreService map[string]store.MemoryStoreService } diff --git a/core/gas/meter.go b/core/gas/meter.go index 0774fd2a7733..d79991232aa5 100644 --- a/core/gas/meter.go +++ b/core/gas/meter.go @@ -28,8 +28,8 @@ type Service interface { // Meter represents a gas meter for modules consumption type Meter interface { - Consume(amount Gas, descriptor string) - Refund(amount Gas, descriptor string) - Remaining() Gas + ConsumeGas(amount Gas, descriptor string) + RefundGas(amount Gas, descriptor string) + GasRemaining() Gas Limit() Gas } diff --git a/runtime/environment.go b/runtime/environment.go new file mode 100644 index 000000000000..5af25b73ad87 --- /dev/null +++ b/runtime/environment.go @@ -0,0 +1,23 @@ +package runtime + +import ( + "cosmossdk.io/core/appmodule" + storetypes "cosmossdk.io/store/types" +) + +func NewEnvironment(kvKeys []storetypes.KVStoreKey, memKeys []storetypes.MemoryStoreKey) *appmodule.Environment { + env := &appmodule.Environment{} + for _, storeKey := range kvKeys { + env.KvStoreService[storeKey.Name()] = NewKVStoreService(&storeKey) + } + for _, memKey := range memKeys { + env.MemStoreService[memKey.Name()] = NewMemStoreService(&memKey) + } + env.EventService = EventService{} + env.HeaderService = HeaderService{} + env.BranchService = BranchService{} + + // GasService gas.Service + + return env +} diff --git a/runtime/gas.go b/runtime/gas.go new file mode 100644 index 000000000000..82c8bd8f05d0 --- /dev/null +++ b/runtime/gas.go @@ -0,0 +1,44 @@ +package runtime + +import ( + "context" + + "cosmossdk.io/core/gas" + storetypes "cosmossdk.io/store/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ gas.Service = GasService{} + +type GasService struct { + storetypes.GasMeter +} + +func (g GasService) GetGasMeter(ctx context.Context) gas.Meter { + return sdk.UnwrapSDKContext(ctx).GasMeter() +} + +func (g GasService) GetBlockGasMeter(ctx context.Context) gas.Meter { + return sdk.UnwrapSDKContext(ctx).BlockGasMeter() +} + +func (g GasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context { + return sdk.UnwrapSDKContext(ctx).WithGasMeter(meter) +} + +func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context { + return sdk.UnwrapSDKContext(ctx).WithGasMeter() +} + +// ______________________________________________________________________________________________ +// Gas Meter Wrappers +// ______________________________________________________________________________________________ + +type SDKGasMeter struct { + gas.Meter +} + +type CoreGasmeter struct { + storetypes.GasMeter +} diff --git a/runtime/store.go b/runtime/store.go index 230f53c38c5d..5de89d180a65 100644 --- a/runtime/store.go +++ b/runtime/store.go @@ -28,6 +28,10 @@ type memStoreService struct { key *storetypes.MemoryStoreKey } +func NewMemStoreService(storeKey *storetypes.MemoryStoreKey) store.MemoryStoreService { + return &memStoreService{key: storeKey} +} + func (m memStoreService) OpenMemoryStore(ctx context.Context) store.KVStore { return newKVStore(sdk.UnwrapSDKContext(ctx).KVStore(m.key)) } From 2cdab4707bb682605c394fe4ff9f0479b0c397b5 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 17:46:46 +0100 Subject: [PATCH 03/20] gas wrappers --- core/gas/meter.go | 6 ++-- runtime/environment.go | 5 ++-- runtime/gas.go | 66 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/core/gas/meter.go b/core/gas/meter.go index d79991232aa5..0774fd2a7733 100644 --- a/core/gas/meter.go +++ b/core/gas/meter.go @@ -28,8 +28,8 @@ type Service interface { // Meter represents a gas meter for modules consumption type Meter interface { - ConsumeGas(amount Gas, descriptor string) - RefundGas(amount Gas, descriptor string) - GasRemaining() Gas + Consume(amount Gas, descriptor string) + Refund(amount Gas, descriptor string) + Remaining() Gas Limit() Gas } diff --git a/runtime/environment.go b/runtime/environment.go index 5af25b73ad87..d5ba0bb29e7c 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -8,16 +8,17 @@ import ( func NewEnvironment(kvKeys []storetypes.KVStoreKey, memKeys []storetypes.MemoryStoreKey) *appmodule.Environment { env := &appmodule.Environment{} for _, storeKey := range kvKeys { + storeKey := storeKey // TODO remove in go 1.22 env.KvStoreService[storeKey.Name()] = NewKVStoreService(&storeKey) } for _, memKey := range memKeys { + memKey := memKey // TODO remove in go 1.22 env.MemStoreService[memKey.Name()] = NewMemStoreService(&memKey) } env.EventService = EventService{} env.HeaderService = HeaderService{} env.BranchService = BranchService{} - - // GasService gas.Service + env.GasService = GasService{} return env } diff --git a/runtime/gas.go b/runtime/gas.go index 82c8bd8f05d0..e5dbebc932b2 100644 --- a/runtime/gas.go +++ b/runtime/gas.go @@ -12,23 +12,22 @@ import ( var _ gas.Service = GasService{} type GasService struct { - storetypes.GasMeter } func (g GasService) GetGasMeter(ctx context.Context) gas.Meter { - return sdk.UnwrapSDKContext(ctx).GasMeter() + return CoreGasmeter{gm: sdk.UnwrapSDKContext(ctx).GasMeter()} } func (g GasService) GetBlockGasMeter(ctx context.Context) gas.Meter { - return sdk.UnwrapSDKContext(ctx).BlockGasMeter() + return CoreGasmeter{gm: sdk.UnwrapSDKContext(ctx).BlockGasMeter()} } func (g GasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context { - return sdk.UnwrapSDKContext(ctx).WithGasMeter(meter) + return sdk.UnwrapSDKContext(ctx).WithGasMeter(SDKGasMeter{gm: meter}) } func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context { - return sdk.UnwrapSDKContext(ctx).WithGasMeter() + return sdk.UnwrapSDKContext(ctx).WithGasMeter(SDKGasMeter{gm: meter}) } // ______________________________________________________________________________________________ @@ -36,9 +35,62 @@ func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) cont // ______________________________________________________________________________________________ type SDKGasMeter struct { - gas.Meter + gm gas.Meter +} + +func (gm SDKGasMeter) GasConsumed() storetypes.Gas { + return gm.gm.Remaining() +} + +func (gm SDKGasMeter) GasConsumedToLimit() storetypes.Gas { + return gm.gm.Limit() // TODO is this correct? +} + +func (gm SDKGasMeter) GasRemaining() storetypes.Gas { + return gm.gm.Remaining() +} + +func (gm SDKGasMeter) Limit() storetypes.Gas { + return gm.gm.Limit() +} + +func (gm SDKGasMeter) ConsumeGas(amount storetypes.Gas, descriptor string) { + gm.gm.Consume(amount, descriptor) +} + +func (gm SDKGasMeter) RefundGas(amount storetypes.Gas, descriptor string) { + gm.gm.Refund(amount, descriptor) +} + +func (gm SDKGasMeter) IsPastLimit() bool { + return gm.gm.Remaining() <= gm.gm.Limit() + +} + +func (gm SDKGasMeter) IsOutOfGas() bool { + return gm.gm.Remaining() >= gm.gm.Limit() +} + +func (gm SDKGasMeter) String() string { + return "gas go fast" // TODO } type CoreGasmeter struct { - storetypes.GasMeter + gm storetypes.GasMeter +} + +func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) { + cgm.gm.ConsumeGas(amount, descriptor) +} + +func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) { + cgm.gm.RefundGas(amount, descriptor) +} + +func (cgm CoreGasmeter) Remaining() gas.Gas { + return cgm.gm.GasRemaining() +} + +func (cgm CoreGasmeter) Limit() gas.Gas { + return cgm.gm.Limit() } From c363d1ecfcd33dee8159a2949af4c99a966647f0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 18:02:05 +0100 Subject: [PATCH 04/20] fix linting --- runtime/gas.go | 4 +--- store/database.go | 3 ++- store/kv/mem/iterator.go | 2 -- store/proof.go | 4 ++-- store/storage/sqlite/iterator.go | 1 - 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/runtime/gas.go b/runtime/gas.go index e5dbebc932b2..2223cef4a696 100644 --- a/runtime/gas.go +++ b/runtime/gas.go @@ -11,8 +11,7 @@ import ( var _ gas.Service = GasService{} -type GasService struct { -} +type GasService struct{} func (g GasService) GetGasMeter(ctx context.Context) gas.Meter { return CoreGasmeter{gm: sdk.UnwrapSDKContext(ctx).GasMeter()} @@ -64,7 +63,6 @@ func (gm SDKGasMeter) RefundGas(amount storetypes.Gas, descriptor string) { func (gm SDKGasMeter) IsPastLimit() bool { return gm.gm.Remaining() <= gm.gm.Limit() - } func (gm SDKGasMeter) IsOutOfGas() bool { diff --git a/store/database.go b/store/database.go index 2df28059a490..1975b2af38e4 100644 --- a/store/database.go +++ b/store/database.go @@ -3,8 +3,9 @@ package store import ( "io" - corestore "cosmossdk.io/core/store" ics23 "github.com/cosmos/ics23/go" + + corestore "cosmossdk.io/core/store" ) // Reader wraps the Has and Get method of a backing data store. diff --git a/store/kv/mem/iterator.go b/store/kv/mem/iterator.go index da7cdc61af94..711eb4bb53f3 100644 --- a/store/kv/mem/iterator.go +++ b/store/kv/mem/iterator.go @@ -98,8 +98,6 @@ func (itr *iterator) Next() { if itr.valid { itr.valid = itr.keyInRange(itr.Key()) } - - return } func (itr *iterator) Close() error { diff --git a/store/proof.go b/store/proof.go index cabeb5c680ac..e20145711f5c 100644 --- a/store/proof.go +++ b/store/proof.go @@ -163,7 +163,7 @@ func ProofFromByteSlices(leaves [][]byte, index int) (rootHash []byte, inners [] // saved until the next iteration). if index < n-1 || index&1 == 1 { inner := &ics23.InnerOp{Hash: ics23.HashOp_SHA256} - //If proof index is even then child is from left, suffix is populated + // otherwise, child is from right and the prefix is populated. if index&1 == 0 { // inner op(prefix=0x01 | child | suffix=leaves[index+1]) @@ -190,7 +190,7 @@ func ProofFromByteSlices(leaves [][]byte, index int) (rootHash []byte, inners [] } rootHash = leaves[0] - return + return rootHash, inners } // ConvertCommitmentOp converts the given merkle proof into an CommitmentOp. diff --git a/store/storage/sqlite/iterator.go b/store/storage/sqlite/iterator.go index 4549c478fad1..e048e1f3cd27 100644 --- a/store/storage/sqlite/iterator.go +++ b/store/storage/sqlite/iterator.go @@ -152,7 +152,6 @@ func (itr *iterator) Next() { } itr.valid = false - return } func (itr *iterator) Error() error { From f1379de0d8004812d4e305a50ae8f2ea85295b5c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 18:10:14 +0100 Subject: [PATCH 05/20] add it to circuit --- runtime/environment.go | 6 +++--- simapp/app.go | 4 +++- store/storage/pebbledb/iterator.go | 1 - x/circuit/keeper/keeper.go | 5 ++++- x/circuit/keeper/keeper_test.go | 6 ++++-- x/circuit/module.go | 9 ++++----- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/runtime/environment.go b/runtime/environment.go index d5ba0bb29e7c..927c79e4c6d5 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -5,11 +5,11 @@ import ( storetypes "cosmossdk.io/store/types" ) -func NewEnvironment(kvKeys []storetypes.KVStoreKey, memKeys []storetypes.MemoryStoreKey) *appmodule.Environment { - env := &appmodule.Environment{} +func NewEnvironment(kvKeys map[string]*storetypes.KVStoreKey, memKeys []storetypes.MemoryStoreKey) appmodule.Environment { + env := appmodule.Environment{} for _, storeKey := range kvKeys { storeKey := storeKey // TODO remove in go 1.22 - env.KvStoreService[storeKey.Name()] = NewKVStoreService(&storeKey) + env.KvStoreService[storeKey.Name()] = NewKVStoreService(storeKey) } for _, memKey := range memKeys { memKey := memKey // TODO remove in go 1.22 diff --git a/simapp/app.go b/simapp/app.go index 170b61fcb1dc..e0cf88a15b1b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -268,6 +268,8 @@ func NewSimApp( panic(err) } + env := runtime.NewEnvironment(keys, nil) + app := &SimApp{ BaseApp: bApp, legacyAmino: legacyAmino, @@ -349,7 +351,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.CircuitKeeper = circuitkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[circuittypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) + app.CircuitKeeper = circuitkeeper.NewKeeper(env, appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper) diff --git a/store/storage/pebbledb/iterator.go b/store/storage/pebbledb/iterator.go index abb746863d88..6bd60a2cfea6 100644 --- a/store/storage/pebbledb/iterator.go +++ b/store/storage/pebbledb/iterator.go @@ -180,7 +180,6 @@ func (itr *iterator) Next() { } itr.valid = false - return } func (itr *iterator) Valid() bool { diff --git a/x/circuit/keeper/keeper.go b/x/circuit/keeper/keeper.go index 25513991f8c1..51f7f5c39d5b 100644 --- a/x/circuit/keeper/keeper.go +++ b/x/circuit/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" "cosmossdk.io/core/store" "cosmossdk.io/x/circuit/types" @@ -28,12 +29,14 @@ type Keeper struct { } // NewKeeper constructs a new Circuit Keeper instance -func NewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, authority string, addressCodec address.Codec) Keeper { +func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, authority string, addressCodec address.Codec) Keeper { auth, err := addressCodec.StringToBytes(authority) if err != nil { panic(err) } + storeService := env.KvStoreService[types.ModuleName] + sb := collections.NewSchemaBuilder(storeService) k := Keeper{ diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index d556388212ec..3a54cfea0a00 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -42,8 +42,10 @@ func initFixture(t *testing.T) *fixture { encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{}) ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") - storeService := runtime.NewKVStoreService(mockStoreKey) - k := keeper.NewKeeper(encCfg.Codec, storeService, authtypes.NewModuleAddress("gov").String(), ac) + sk := map[string]*storetypes.KVStoreKey{} + sk[types.ModuleName] = mockStoreKey + env := runtime.NewEnvironment(sk, nil) + k := keeper.NewKeeper(env, encCfg.Codec, authtypes.NewModuleAddress("gov").String(), ac) bz, err := ac.StringToBytes(authtypes.NewModuleAddress("gov").String()) require.NoError(t, err) diff --git a/x/circuit/module.go b/x/circuit/module.go index 667a1fd9700a..03cca2242490 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -11,7 +11,6 @@ import ( modulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/store" "cosmossdk.io/depinject" am "cosmossdk.io/depinject/appmodule" authtypes "cosmossdk.io/x/auth/types" @@ -136,9 +135,9 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - StoreService store.KVStoreService + Config *modulev1.Module + Cdc codec.Codec + Env appmodule.Environment AddressCodec address.Codec } @@ -159,8 +158,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { } circuitkeeper := keeper.NewKeeper( + in.Env, in.Cdc, - in.StoreService, authority.String(), in.AddressCodec, ) From 1ef053eb8cd9530bddfc25ea7be397d1f449db4e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 19:15:58 +0100 Subject: [PATCH 06/20] event passing --- x/circuit/keeper/genesis_test.go | 5 ++- x/circuit/keeper/keeper.go | 3 ++ x/circuit/keeper/msg_server.go | 52 ++++++++++++++++---------------- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index 3569c5fc69db..48d5cca4dda8 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -48,7 +48,10 @@ func (s *GenesisTestSuite) SetupTest() { s.Require().NoError(err) s.addrBytes = bz - s.keeper = keeper.NewKeeper(s.cdc, runtime.NewKVStoreService(key), authority.String(), ac) + kvKeys := map[string]*storetypes.KVStoreKey{} + kvKeys[types.ModuleName] = key + + s.keeper = keeper.NewKeeper(runtime.NewEnvironment(kvKeys, nil), s.cdc, authority.String(), ac) } func (s *GenesisTestSuite) TestInitExportGenesis() { diff --git a/x/circuit/keeper/keeper.go b/x/circuit/keeper/keeper.go index 51f7f5c39d5b..e8790b165c5f 100644 --- a/x/circuit/keeper/keeper.go +++ b/x/circuit/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/event" "cosmossdk.io/core/store" "cosmossdk.io/x/circuit/types" @@ -16,6 +17,7 @@ import ( type Keeper struct { cdc codec.BinaryCodec storeService store.KVStoreService + eventService event.Service authority []byte @@ -42,6 +44,7 @@ func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, authority strin k := Keeper{ cdc: cdc, storeService: storeService, + eventService: env.EventService, authority: auth, addressCodec: addressCodec, Permissions: collections.NewMap( diff --git a/x/circuit/keeper/msg_server.go b/x/circuit/keeper/msg_server.go index 0c6bb07cbc40..3c0136be42a1 100644 --- a/x/circuit/keeper/msg_server.go +++ b/x/circuit/keeper/msg_server.go @@ -7,10 +7,10 @@ import ( "strings" "cosmossdk.io/collections" + "cosmossdk.io/core/event" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/circuit/types" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -63,15 +63,15 @@ func (srv msgServer) AuthorizeCircuitBreaker(ctx context.Context, msg *types.Msg return nil, err } - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - "authorize_circuit_breaker", - sdk.NewAttribute("granter", msg.Granter), - sdk.NewAttribute("grantee", msg.Grantee), - sdk.NewAttribute("permission", msg.Permissions.String()), - ), - }) + err = srv.Keeper.eventService.EventManager(ctx).EmitKV( + "authorize_circuit_breaker", + event.Attribute{Key: "granter", Value: msg.Granter}, + event.Attribute{Key: "grantee", Value: msg.Grantee}, + event.Attribute{Key: "permission", Value: msg.Permissions.String()}, + ) + if err != nil { + return nil, err + } return &types.MsgAuthorizeCircuitBreakerResponse{ Success: true, @@ -121,14 +121,14 @@ func (srv msgServer) TripCircuitBreaker(ctx context.Context, msg *types.MsgTripC urls := strings.Join(msg.GetMsgTypeUrls(), ",") - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - "trip_circuit_breaker", - sdk.NewAttribute("authority", msg.Authority), - sdk.NewAttribute("msg_url", urls), - ), - }) + err = srv.Keeper.eventService.EventManager(ctx).EmitKV( + "trip_circuit_breaker", + event.Attribute{Key: "authority", Value: msg.Authority}, + event.Attribute{Key: "msg_url", Value: urls}, + ) + if err != nil { + return nil, err + } return &types.MsgTripCircuitBreakerResponse{ Success: true, @@ -180,14 +180,14 @@ func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgRese urls := strings.Join(msg.GetMsgTypeUrls(), ",") - sdkCtx := sdk.UnwrapSDKContext(ctx) - sdkCtx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - "reset_circuit_breaker", - sdk.NewAttribute("authority", msg.Authority), - sdk.NewAttribute("msg_url", urls), - ), - }) + err = srv.Keeper.eventService.EventManager(ctx).EmitKV( + "reset_circuit_breaker", + event.Attribute{Key: "authority", Value: msg.Authority}, + event.Attribute{Key: "msg_url", Value: urls}, + ) + if err != nil { + return nil, err + } return &types.MsgResetCircuitBreakerResponse{Success: true}, nil } From 31a9356f10eac770ca11e92ad57032e6ddc0bea2 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 19:39:02 +0100 Subject: [PATCH 07/20] provide environment --- runtime/module.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/runtime/module.go b/runtime/module.go index 0c4cbda7da7a..583678969aff 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -251,6 +251,26 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { return app.app } +func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) appmodule.Environment { + override := storeKeyOverride(config, key.Name()) + + var storeKeyName string + if override != nil { + storeKeyName = override.KvStoreKey + } else { + storeKeyName = key.Name() + } + + storeKey := storetypes.NewKVStoreKey(storeKeyName) + registerStoreKey(app, storeKey) + + kvKeys := map[string]*storetypes.KVStoreKey{ + storeKeyName: storeKey, + } + + return NewEnvironment(kvKeys, nil) +} + type ( // ValidatorAddressCodec is an alias for address.Codec for validator addresses. ValidatorAddressCodec address.Codec From c7d551fc011045c9cb7cbdd97c53b2fdcc9be7ae Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 12 Jan 2024 19:51:17 +0100 Subject: [PATCH 08/20] minor cleanup --- core/event/service.go | 4 ++++ x/accounts/msg_server.go | 5 +---- x/circuit/keeper/msg_server.go | 14 +++++++------- x/consensus/keeper/keeper.go | 4 ++-- x/counter/keeper/keeper.go | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/event/service.go b/core/event/service.go index 3f6b273be06b..941f142db5f9 100644 --- a/core/event/service.go +++ b/core/event/service.go @@ -41,3 +41,7 @@ type Manager interface { type Attribute struct { Key, Value string } + +func NewAttribute(key, value string) Attribute { + return Attribute{Key: key, Value: value} +} diff --git a/x/accounts/msg_server.go b/x/accounts/msg_server.go index 0216b39d3793..a4dce5600190 100644 --- a/x/accounts/msg_server.go +++ b/x/accounts/msg_server.go @@ -45,10 +45,7 @@ func (m msgServer) Init(ctx context.Context, request *v1.MsgInit) (*v1.MsgInitRe eventManager := m.k.eventService.EventManager(ctx) err = eventManager.EmitKV( "account_creation", - event.Attribute{ - Key: "address", - Value: accAddrString, - }, + event.NewAttribute("address", accAddrString), ) if err != nil { return nil, err diff --git a/x/circuit/keeper/msg_server.go b/x/circuit/keeper/msg_server.go index 3c0136be42a1..3c60cb07848b 100644 --- a/x/circuit/keeper/msg_server.go +++ b/x/circuit/keeper/msg_server.go @@ -65,9 +65,9 @@ func (srv msgServer) AuthorizeCircuitBreaker(ctx context.Context, msg *types.Msg err = srv.Keeper.eventService.EventManager(ctx).EmitKV( "authorize_circuit_breaker", - event.Attribute{Key: "granter", Value: msg.Granter}, - event.Attribute{Key: "grantee", Value: msg.Grantee}, - event.Attribute{Key: "permission", Value: msg.Permissions.String()}, + event.NewAttribute("granter", msg.Granter), + event.NewAttribute("grantee", msg.Grantee), + event.NewAttribute("permission", msg.Permissions.String()), ) if err != nil { return nil, err @@ -123,8 +123,8 @@ func (srv msgServer) TripCircuitBreaker(ctx context.Context, msg *types.MsgTripC err = srv.Keeper.eventService.EventManager(ctx).EmitKV( "trip_circuit_breaker", - event.Attribute{Key: "authority", Value: msg.Authority}, - event.Attribute{Key: "msg_url", Value: urls}, + event.NewAttribute("authority", msg.Authority), + event.NewAttribute("msg_url", urls), ) if err != nil { return nil, err @@ -182,8 +182,8 @@ func (srv msgServer) ResetCircuitBreaker(ctx context.Context, msg *types.MsgRese err = srv.Keeper.eventService.EventManager(ctx).EmitKV( "reset_circuit_breaker", - event.Attribute{Key: "authority", Value: msg.Authority}, - event.Attribute{Key: "msg_url", Value: urls}, + event.NewAttribute("authority", msg.Authority), + event.NewAttribute("msg_url", urls), ) if err != nil { return nil, err diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 9e6a068bc15a..a0ccf562dea2 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -81,8 +81,8 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (* if err := k.event.EventManager(ctx).EmitKV( "update_consensus_params", - event.Attribute{Key: "authority", Value: msg.Authority}, - event.Attribute{Key: "parameters", Value: consensusParams.String()}); err != nil { + event.NewAttribute("authority", msg.Authority), + event.NewAttribute("parameters", consensusParams.String())); err != nil { return nil, err } diff --git a/x/counter/keeper/keeper.go b/x/counter/keeper/keeper.go index 127311d23363..6d7fd422e8c3 100644 --- a/x/counter/keeper/keeper.go +++ b/x/counter/keeper/keeper.go @@ -69,8 +69,8 @@ func (k Keeper) IncreaseCount(ctx context.Context, msg *types.MsgIncreaseCounter if err := k.event.EventManager(ctx).EmitKV( "increase_counter", - event.Attribute{Key: "signer", Value: msg.Signer}, - event.Attribute{Key: "new count", Value: fmt.Sprint(num + msg.Count)}); err != nil { + event.NewAttribute("signer", msg.Signer), + event.NewAttribute("new count", fmt.Sprint(num+msg.Count))); err != nil { return nil, err } From ae054795d106211ae78ce20447687698c3174a94 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sat, 13 Jan 2024 18:33:08 +0100 Subject: [PATCH 09/20] make it only take one key --- core/appmodule/environment.go | 4 ++-- runtime/environment.go | 14 +++++++------- runtime/module.go | 20 +++++++------------- simapp/app.go | 4 +--- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index 0737519777de..da666728691f 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -14,6 +14,6 @@ type Environment struct { EventService event.Service GasService gas.Service HeaderService header.Service - KvStoreService map[string]store.KVStoreService - MemStoreService map[string]store.MemoryStoreService + KvStoreService store.KVStoreService + MemStoreService store.MemoryStoreService } diff --git a/runtime/environment.go b/runtime/environment.go index 927c79e4c6d5..cfc723268bc3 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -5,16 +5,16 @@ import ( storetypes "cosmossdk.io/store/types" ) -func NewEnvironment(kvKeys map[string]*storetypes.KVStoreKey, memKeys []storetypes.MemoryStoreKey) appmodule.Environment { +func NewEnvironment(storeKey *storetypes.KVStoreKey, memKey *storetypes.MemoryStoreKey) appmodule.Environment { env := appmodule.Environment{} - for _, storeKey := range kvKeys { - storeKey := storeKey // TODO remove in go 1.22 - env.KvStoreService[storeKey.Name()] = NewKVStoreService(storeKey) + if storeKey != nil { + env.KvStoreService = NewKVStoreService(storeKey) } - for _, memKey := range memKeys { - memKey := memKey // TODO remove in go 1.22 - env.MemStoreService[memKey.Name()] = NewMemStoreService(&memKey) + + if memKey != nil { + env.MemStoreService = NewMemStoreService(memKey) } + env.EventService = EventService{} env.HeaderService = HeaderService{} env.BranchService = BranchService{} diff --git a/runtime/module.go b/runtime/module.go index 583678969aff..10730188d392 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -252,23 +252,17 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { } func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) appmodule.Environment { - override := storeKeyOverride(config, key.Name()) + env := appmodule.Environment{} - var storeKeyName string - if override != nil { - storeKeyName = override.KvStoreKey - } else { - storeKeyName = key.Name() - } + env.KvStoreService = ProvideKVStoreService(config, key, app) - storeKey := storetypes.NewKVStoreKey(storeKeyName) - registerStoreKey(app, storeKey) + env.EventService = EventService{} + env.HeaderService = HeaderService{} + env.BranchService = BranchService{} + env.GasService = GasService{} - kvKeys := map[string]*storetypes.KVStoreKey{ - storeKeyName: storeKey, - } + return env - return NewEnvironment(kvKeys, nil) } type ( diff --git a/simapp/app.go b/simapp/app.go index e0cf88a15b1b..18eaa1a6c22b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -268,8 +268,6 @@ func NewSimApp( panic(err) } - env := runtime.NewEnvironment(keys, nil) - app := &SimApp{ BaseApp: bApp, legacyAmino: legacyAmino, @@ -351,7 +349,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.CircuitKeeper = circuitkeeper.NewKeeper(env, appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) + app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey]), nil), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper) From bbc3f3aca1ef2ae6aec02e94e5a50c6b16b9f321 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 17 Jan 2024 12:25:23 +0100 Subject: [PATCH 10/20] provide kvstoreservice as a function parameter --- runtime/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index d121e93df7a3..ff6ec740681b 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -251,10 +251,10 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { return app.app } -func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) appmodule.Environment { +func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder, kvservice func(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) store.KVStoreService) appmodule.Environment { env := appmodule.Environment{} - env.KvStoreService = ProvideKVStoreService(config, key, app) + env.KvStoreService = kvservice(config, key, app) env.EventService = EventService{} env.HeaderService = HeaderService{} From d069987357374854f0cf5f86ef4f457fd2d69fa0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 18 Jan 2024 15:45:01 +0100 Subject: [PATCH 11/20] address comments --- core/appmodule/environment.go | 2 +- runtime/environment.go | 2 +- runtime/module.go | 4 ++-- x/circuit/keeper/keeper.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/appmodule/environment.go b/core/appmodule/environment.go index da666728691f..f7305db9fc3d 100644 --- a/core/appmodule/environment.go +++ b/core/appmodule/environment.go @@ -14,6 +14,6 @@ type Environment struct { EventService event.Service GasService gas.Service HeaderService header.Service - KvStoreService store.KVStoreService + KVStoreService store.KVStoreService MemStoreService store.MemoryStoreService } diff --git a/runtime/environment.go b/runtime/environment.go index cfc723268bc3..54423c005006 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -8,7 +8,7 @@ import ( func NewEnvironment(storeKey *storetypes.KVStoreKey, memKey *storetypes.MemoryStoreKey) appmodule.Environment { env := appmodule.Environment{} if storeKey != nil { - env.KvStoreService = NewKVStoreService(storeKey) + env.KVStoreService = NewKVStoreService(storeKey) } if memKey != nil { diff --git a/runtime/module.go b/runtime/module.go index ff6ec740681b..a9b16945df4f 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -251,10 +251,10 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { return app.app } -func ProvideEnvironment(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder, kvservice func(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) store.KVStoreService) appmodule.Environment { +func ProvideEnvironment(kvservice store.KVStoreService) appmodule.Environment { env := appmodule.Environment{} - env.KvStoreService = kvservice(config, key, app) + env.KVStoreService = kvservice env.EventService = EventService{} env.HeaderService = HeaderService{} diff --git a/x/circuit/keeper/keeper.go b/x/circuit/keeper/keeper.go index e8790b165c5f..6532d501584b 100644 --- a/x/circuit/keeper/keeper.go +++ b/x/circuit/keeper/keeper.go @@ -37,7 +37,7 @@ func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, authority strin panic(err) } - storeService := env.KvStoreService[types.ModuleName] + storeService := env.KVStoreService[types.ModuleName] sb := collections.NewSchemaBuilder(storeService) From 8d8739df4d1f3ebc051beae20d57c3048ca42997 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 18 Jan 2024 15:53:19 +0100 Subject: [PATCH 12/20] add some docs --- UPGRADING.md | 10 ++++++++++ core/CHANGELOG.md | 1 + x/accounts/testing/counter/counter.go | 8 +++++--- x/circuit/CHANGELOG.md | 4 ++++ x/circuit/depinject.go | 9 ++++----- x/circuit/keeper/genesis_test.go | 5 +---- x/circuit/keeper/keeper.go | 2 +- x/circuit/keeper/keeper_test.go | 5 ++--- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 6207265bc3e0..f80cdf34a842 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -116,6 +116,16 @@ Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a l +### Core + +`appmodule.Environment` interface was introduced to fetch different services from the application. This can be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services. It needs to be passed into a module at instantiation. + +Circuit Breaker is used as an example. + +```go +app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey]), nil), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) +``` + ### Modules #### `**all**` diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 1af2b0fc308b..6fe568084e6d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. * [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit. +* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services ### API Breaking diff --git a/x/accounts/testing/counter/counter.go b/x/accounts/testing/counter/counter.go index 920699fa3226..55aecb82fb8d 100644 --- a/x/accounts/testing/counter/counter.go +++ b/x/accounts/testing/counter/counter.go @@ -114,9 +114,11 @@ func (a Account) TestDependencies(ctx context.Context, _ *counterv1.MsgTestDepen chainID := a.hs.GetHeaderInfo(ctx).ChainID // test gas meter - gasBefore := a.gs.GetGasMeter(ctx).GasConsumedToLimit() - a.gs.GetGasMeter(ctx).ConsumeGas(10, "test") - gasAfter := a.gs.GetGasMeter(ctx).GasConsumedToLimit() + gasBefore := a.gs.GetGasMeter(ctx).Limit() + a.gs.GetGasMeter(ctx).Consume(gasBefore, "before") + a.gs.GetGasMeter(ctx).Consume(10, "test") + gasAfter := a.gs.GetGasMeter(ctx).Limit() + a.gs.GetGasMeter(ctx).Consume(gasBefore, "After") return &counterv1.MsgTestDependenciesResponse{ ChainId: chainID, diff --git a/x/circuit/CHANGELOG.md b/x/circuit/CHANGELOG.md index 8f9cd263ca6d..005ba39481a1 100644 --- a/x/circuit/CHANGELOG.md +++ b/x/circuit/CHANGELOG.md @@ -31,4 +31,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### API Breaking + +* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) `appmodule.Environment` is received on the Keeper to get access to different application services + ## [v0.1.0](https://github.com/cosmos/cosmos-sdk/releases/tag/x/circuit/v0.1.0) - 2023-11-07 diff --git a/x/circuit/depinject.go b/x/circuit/depinject.go index fdca2207413c..1ec1d4d9662d 100644 --- a/x/circuit/depinject.go +++ b/x/circuit/depinject.go @@ -4,7 +4,6 @@ import ( modulev1 "cosmossdk.io/api/cosmos/circuit/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" authtypes "cosmossdk.io/x/auth/types" @@ -30,9 +29,9 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - StoreService store.KVStoreService + Config *modulev1.Module + Cdc codec.Codec + Environment appmodule.Environment AddressCodec address.Codec } @@ -53,8 +52,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { } circuitkeeper := keeper.NewKeeper( + in.Environment, in.Cdc, - in.StoreService, authority.String(), in.AddressCodec, ) diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index 48d5cca4dda8..65fcabfd5c9e 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -48,10 +48,7 @@ func (s *GenesisTestSuite) SetupTest() { s.Require().NoError(err) s.addrBytes = bz - kvKeys := map[string]*storetypes.KVStoreKey{} - kvKeys[types.ModuleName] = key - - s.keeper = keeper.NewKeeper(runtime.NewEnvironment(kvKeys, nil), s.cdc, authority.String(), ac) + s.keeper = keeper.NewKeeper(runtime.NewEnvironment(key, nil), s.cdc, authority.String(), ac) } func (s *GenesisTestSuite) TestInitExportGenesis() { diff --git a/x/circuit/keeper/keeper.go b/x/circuit/keeper/keeper.go index 6532d501584b..aa6a71a03ad6 100644 --- a/x/circuit/keeper/keeper.go +++ b/x/circuit/keeper/keeper.go @@ -37,7 +37,7 @@ func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, authority strin panic(err) } - storeService := env.KVStoreService[types.ModuleName] + storeService := env.KVStoreService sb := collections.NewSchemaBuilder(storeService) diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index 3a54cfea0a00..3f1081b955ac 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -42,9 +42,8 @@ func initFixture(t *testing.T) *fixture { encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{}) ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") - sk := map[string]*storetypes.KVStoreKey{} - sk[types.ModuleName] = mockStoreKey - env := runtime.NewEnvironment(sk, nil) + + env := runtime.NewEnvironment(mockStoreKey, nil) k := keeper.NewKeeper(env, encCfg.Codec, authtypes.NewModuleAddress("gov").String(), ac) bz, err := ac.StringToBytes(authtypes.NewModuleAddress("gov").String()) From a9ea987336c471c931979295920968754bc986b2 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 18 Jan 2024 18:20:35 +0100 Subject: [PATCH 13/20] pass build --- go.mod | 2 ++ go.sum | 4 ---- simapp/go.mod | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index c43ce6b2a674..00c36df1b8d9 100644 --- a/go.mod +++ b/go.mod @@ -178,6 +178,7 @@ require ( // TODO remove after all modules have their own go.mods replace ( cosmossdk.io/api => ./api + cosmossdk.io/core => ./core cosmossdk.io/depinject => ./depinject cosmossdk.io/x/auth => ./x/auth cosmossdk.io/x/bank => ./x/bank @@ -186,6 +187,7 @@ replace ( cosmossdk.io/x/protocolpool => ./x/protocolpool cosmossdk.io/x/slashing => ./x/slashing cosmossdk.io/x/staking => ./x/staking + cosmossdk.io/x/tx => ./x/tx ) // Below are the long-lived replace of the Cosmos SDK diff --git a/go.sum b/go.sum index e74bc4eda48c..5b0c39d3e42c 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 h1:hOzi4yo2Fc7h3mod+xX4m4QA4+Uq+PkFRjY/yalZ0B8= -cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7/go.mod h1:3v0JJNNd8ye0cOvJ+wUUvE7Ke0d2qxnNIDcXd5mziHk= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.3.0 h1:L0Z0XstClo2kOU4h3V1iDoE5Ji64sg5HLOogzGg67Oo= @@ -12,8 +10,6 @@ cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0= cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs= -cosmossdk.io/x/tx v0.13.0 h1:8lzyOh3zONPpZv2uTcUmsv0WTXy6T1/aCVDCqShmpzU= -cosmossdk.io/x/tx v0.13.0/go.mod h1:CpNQtmoqbXa33/DVxWQNx5Dcnbkv2xGUhL7tYQ5wUsY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index 674513ca92a4..faeba40da2e8 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -232,6 +232,7 @@ require ( // SimApp on main always tests the latest extracted SDK modules importing the sdk replace ( cosmossdk.io/api => ../api + cosmossdk.io/core => ../core cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/depinject => ../depinject cosmossdk.io/tools/confix => ../tools/confix @@ -252,6 +253,7 @@ replace ( cosmossdk.io/x/slashing => ../x/slashing cosmossdk.io/x/staking => ../x/staking cosmossdk.io/x/upgrade => ../x/upgrade + cosmossdk.io/x/tx => ../x/tx ) // Below are the long-lived replace of the SimApp From ce39c718907f6cc51bb21a74ec74c6aa1ef8410e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 23 Jan 2024 14:31:21 +0100 Subject: [PATCH 14/20] address comments and add changelog entry --- core/CHANGELOG.md | 1 + runtime/environment.go | 26 ++++++++++---------------- simapp/app.go | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 6fe568084e6d..6133359d7e4d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18857](https://github.com/cosmos/cosmos-sdk/pull/18857) Moved `FormatCoins` to `x/tx`. * [#18861](httpes://github.com/cosmos/cosmos-sdk/pull/18861) Moved `coin.ParseCoin` to `client/v2/internal`. * [#18866](https://github.com/cosmos/cosmos-sdk/pull/18866) All items related to depinject have been moved to `cosmossdk.io/depinject` (`Provide`, `Invoke`, `Register`) +* [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) `HasEventListeners` was removed from appmodule due to the fact that it was not used anywhere in the SDK nor implemented ## [v0.12.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0) diff --git a/runtime/environment.go b/runtime/environment.go index 54423c005006..6f34e9f67dd7 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -2,23 +2,17 @@ package runtime import ( "cosmossdk.io/core/appmodule" - storetypes "cosmossdk.io/store/types" + "cosmossdk.io/core/store" ) -func NewEnvironment(storeKey *storetypes.KVStoreKey, memKey *storetypes.MemoryStoreKey) appmodule.Environment { - env := appmodule.Environment{} - if storeKey != nil { - env.KVStoreService = NewKVStoreService(storeKey) +// NewEnvironment creates a new environment for the application +// if memstoreservice is needed, it can be added to the environment: environment.MemStoreService = memstoreservice +func NewEnvironment(kvService store.KVStoreService) appmodule.Environment { + return appmodule.Environment{ + EventService: EventService{}, + HeaderService: HeaderService{}, + BranchService: BranchService{}, + GasService: GasService{}, + KVStoreService: kvService, } - - if memKey != nil { - env.MemStoreService = NewMemStoreService(memKey) - } - - env.EventService = EventService{} - env.HeaderService = HeaderService{} - env.BranchService = BranchService{} - env.GasService = GasService{} - - return env } diff --git a/simapp/app.go b/simapp/app.go index 7ebc68fafb53..57ea91a88997 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -352,7 +352,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey]), nil), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) + app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AuthKeeper) From da75006a9a798eab5988a149ab44705ff51c63ed Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 23 Jan 2024 14:36:16 +0100 Subject: [PATCH 15/20] address todos --- runtime/gas.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/gas.go b/runtime/gas.go index 2223cef4a696..5a18ec511b54 100644 --- a/runtime/gas.go +++ b/runtime/gas.go @@ -2,6 +2,7 @@ package runtime import ( "context" + "fmt" "cosmossdk.io/core/gas" storetypes "cosmossdk.io/store/types" @@ -33,6 +34,7 @@ func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) cont // Gas Meter Wrappers // ______________________________________________________________________________________________ +// SDKGasMeter is a wrapper around the SDK's GasMeter that implements the GasMeter interface. type SDKGasMeter struct { gm gas.Meter } @@ -42,7 +44,10 @@ func (gm SDKGasMeter) GasConsumed() storetypes.Gas { } func (gm SDKGasMeter) GasConsumedToLimit() storetypes.Gas { - return gm.gm.Limit() // TODO is this correct? + if gm.IsPastLimit() { + return gm.gm.Limit() + } + return gm.gm.Remaining() } func (gm SDKGasMeter) GasRemaining() storetypes.Gas { @@ -70,9 +75,10 @@ func (gm SDKGasMeter) IsOutOfGas() bool { } func (gm SDKGasMeter) String() string { - return "gas go fast" // TODO + return fmt.Sprintf("BasicGasMeter:\n limit: %d\n consumed: %d", gm.gm.Limit(), gm.gm.Remaining()) } +// CoreGasmeter is a wrapper around the SDK's GasMeter that implements the GasMeter interface. type CoreGasmeter struct { gm storetypes.GasMeter } From 02149fb709d1fac615bc52ba64dcc4bc45ff98c9 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 29 Jan 2024 15:47:35 +0100 Subject: [PATCH 16/20] fix linting --- runtime/module.go | 14 ++------------ tests/integration/distribution/cli_tx_test.go | 1 - tests/integration/evidence/genesis_test.go | 1 - .../staking/simulation/operations_test.go | 3 +-- tests/sims/authz/operations_test.go | 18 ++++++++---------- x/circuit/keeper/genesis_test.go | 2 +- x/circuit/keeper/keeper_test.go | 2 +- 7 files changed, 13 insertions(+), 28 deletions(-) diff --git a/runtime/module.go b/runtime/module.go index a9b16945df4f..58f8a712d15f 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -251,18 +251,8 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier { return app.app } -func ProvideEnvironment(kvservice store.KVStoreService) appmodule.Environment { - env := appmodule.Environment{} - - env.KVStoreService = kvservice - - env.EventService = EventService{} - env.HeaderService = HeaderService{} - env.BranchService = BranchService{} - env.GasService = GasService{} - - return env - +func ProvideEnvironment(kvService store.KVStoreService) appmodule.Environment { + return NewEnvironment(kvService) } type ( diff --git a/tests/integration/distribution/cli_tx_test.go b/tests/integration/distribution/cli_tx_test.go index 5723c89b6598..e45c228a032b 100644 --- a/tests/integration/distribution/cli_tx_test.go +++ b/tests/integration/distribution/cli_tx_test.go @@ -11,7 +11,6 @@ import ( sdkmath "cosmossdk.io/math" "cosmossdk.io/x/distribution/client/cli" - minttypes "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/client" diff --git a/tests/integration/evidence/genesis_test.go b/tests/integration/evidence/genesis_test.go index 088f41eef0ce..902bc3f23d15 100644 --- a/tests/integration/evidence/genesis_test.go +++ b/tests/integration/evidence/genesis_test.go @@ -13,7 +13,6 @@ import ( "cosmossdk.io/x/evidence" "cosmossdk.io/x/evidence/exported" "cosmossdk.io/x/evidence/keeper" - "cosmossdk.io/x/evidence/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" diff --git a/tests/integration/staking/simulation/operations_test.go b/tests/integration/staking/simulation/operations_test.go index 2c752c6ea8eb..38bfa26232ea 100644 --- a/tests/integration/staking/simulation/operations_test.go +++ b/tests/integration/staking/simulation/operations_test.go @@ -35,12 +35,11 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/tests/integration/staking" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - - "github.com/cosmos/cosmos-sdk/tests/integration/staking" ) type SimTestSuite struct { diff --git a/tests/sims/authz/operations_test.go b/tests/sims/authz/operations_test.go index 7831aa4e4b69..c241d0afcdbd 100644 --- a/tests/sims/authz/operations_test.go +++ b/tests/sims/authz/operations_test.go @@ -11,31 +11,29 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/auth" // import as blank for app wiring authkeeper "cosmossdk.io/x/auth/keeper" + _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring "cosmossdk.io/x/authz" authzkeeper "cosmossdk.io/x/authz/keeper" + _ "cosmossdk.io/x/authz/module" // import as blank for app wiring "cosmossdk.io/x/authz/simulation" - + _ "cosmossdk.io/x/bank" // import as blank for app wiring bankkeeper "cosmossdk.io/x/bank/keeper" banktestutil "cosmossdk.io/x/bank/testutil" banktypes "cosmossdk.io/x/bank/types" + _ "cosmossdk.io/x/gov" // import as blank for app wiring + _ "cosmossdk.io/x/mint" // import as blank for app wiring + _ "cosmossdk.io/x/staking" // import as blank for app wiring - _ "cosmossdk.io/x/auth" // import as blank for app wiring - _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring - _ "cosmossdk.io/x/authz/module" // import as blank for app wiring - _ "cosmossdk.io/x/bank" // import as blank for app wiring - _ "cosmossdk.io/x/gov" // import as blank for app wiring - _ "cosmossdk.io/x/mint" // import as blank for app wiring - _ "cosmossdk.io/x/staking" // import as blank for app wiring "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - - "github.com/cosmos/cosmos-sdk/testutil/configurator" _ "github.com/cosmos/cosmos-sdk/x/consensus" // import as blank for app wiring _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring ) diff --git a/x/circuit/keeper/genesis_test.go b/x/circuit/keeper/genesis_test.go index 65fcabfd5c9e..e11e0da5b30c 100644 --- a/x/circuit/keeper/genesis_test.go +++ b/x/circuit/keeper/genesis_test.go @@ -48,7 +48,7 @@ func (s *GenesisTestSuite) SetupTest() { s.Require().NoError(err) s.addrBytes = bz - s.keeper = keeper.NewKeeper(runtime.NewEnvironment(key, nil), s.cdc, authority.String(), ac) + s.keeper = keeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(key)), s.cdc, authority.String(), ac) } func (s *GenesisTestSuite) TestInitExportGenesis() { diff --git a/x/circuit/keeper/keeper_test.go b/x/circuit/keeper/keeper_test.go index 3f1081b955ac..f3091989dd44 100644 --- a/x/circuit/keeper/keeper_test.go +++ b/x/circuit/keeper/keeper_test.go @@ -43,7 +43,7 @@ func initFixture(t *testing.T) *fixture { ac := addresscodec.NewBech32Codec("cosmos") mockStoreKey := storetypes.NewKVStoreKey("test") - env := runtime.NewEnvironment(mockStoreKey, nil) + env := runtime.NewEnvironment(runtime.NewKVStoreService(mockStoreKey)) k := keeper.NewKeeper(env, encCfg.Codec, authtypes.NewModuleAddress("gov").String(), ac) bz, err := ac.StringToBytes(authtypes.NewModuleAddress("gov").String()) From 3ebf4187a013593dd341400976151b8811ad2cbf Mon Sep 17 00:00:00 2001 From: Facundo Date: Tue, 30 Jan 2024 10:42:57 +0100 Subject: [PATCH 17/20] add ProvideEnvironment --- runtime/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/module.go b/runtime/module.go index 58f8a712d15f..1cd814f15844 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -74,6 +74,7 @@ func init() { ProvideBasicManager, ProvideAppVersionModifier, ProvideAddressCodec, + ProvideEnvironment, ), appconfig.Invoke(SetupAppBuilder), ) From 42368640d0b5d58490d955d2b8e69c475aec413b Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 30 Jan 2024 12:59:28 +0100 Subject: [PATCH 18/20] fix imports --- simapp/go.mod | 2 -- x/circuit/go.mod | 6 ++---- x/circuit/go.sum | 4 ---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/simapp/go.mod b/simapp/go.mod index fce978530594..4d39d573bfbe 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -232,7 +232,6 @@ require ( // SimApp on main always tests the latest extracted SDK modules importing the sdk replace ( cosmossdk.io/api => ../api - cosmossdk.io/core => ../core cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/core => ../core cosmossdk.io/depinject => ../depinject @@ -255,7 +254,6 @@ replace ( cosmossdk.io/x/staking => ../x/staking cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade - cosmossdk.io/x/tx => ../x/tx ) // Below are the long-lived replace of the SimApp diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 455529b282bc..38159d512bbb 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -164,12 +164,10 @@ require ( replace github.com/cosmos/cosmos-sdk => ../../. replace ( + cosmossdk.io/core => ../../core cosmossdk.io/depinject => ../../depinject cosmossdk.io/x/auth => ../auth cosmossdk.io/x/bank => ../bank - cosmossdk.io/x/distribution => ../distribution - cosmossdk.io/x/mint => ../mint - cosmossdk.io/x/protocolpool => ../protocolpool - cosmossdk.io/x/slashing => ../slashing cosmossdk.io/x/staking => ../staking + cosmossdk.io/x/tx => ../tx ) diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 4d2159b607f1..1405279c56f3 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -4,8 +4,6 @@ cosmossdk.io/api v0.7.3-0.20231113122742-912390d5fc4a h1:Zr++x1RCJWi+K8bTZsQKdjt cosmossdk.io/api v0.7.3-0.20231113122742-912390d5fc4a/go.mod h1:7B/5XWh1HYwJk3DzWeNoxOSI+nGx1m5UyYfHLFuKzkw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7 h1:hOzi4yo2Fc7h3mod+xX4m4QA4+Uq+PkFRjY/yalZ0B8= -cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7/go.mod h1:3v0JJNNd8ye0cOvJ+wUUvE7Ke0d2qxnNIDcXd5mziHk= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/log v1.3.0 h1:L0Z0XstClo2kOU4h3V1iDoE5Ji64sg5HLOogzGg67Oo= @@ -14,8 +12,6 @@ cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig= cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.2 h1:lSg5BTvJBHUDwswNNyeh4K/CbqiHER73VU4nDNb8uk0= cosmossdk.io/store v1.0.2/go.mod h1:EFtENTqVTuWwitGW1VwaBct+yDagk7oG/axBMPH+FXs= -cosmossdk.io/x/tx v0.13.0 h1:8lzyOh3zONPpZv2uTcUmsv0WTXy6T1/aCVDCqShmpzU= -cosmossdk.io/x/tx v0.13.0/go.mod h1:CpNQtmoqbXa33/DVxWQNx5Dcnbkv2xGUhL7tYQ5wUsY= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= From 72e5410396cb2cd6c57836464f047afa61cd318e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 30 Jan 2024 13:04:02 +0100 Subject: [PATCH 19/20] fix tests imports --- tests/go.mod | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index 92f6c5f08121..dc56fec7ce69 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -226,7 +226,9 @@ replace ( cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/depinject => ../depinject + cosmossdk.io/core => ../core cosmossdk.io/x/accounts => ../x/accounts + cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/auth => ../x/auth cosmossdk.io/x/authz => ../x/authz cosmossdk.io/x/bank => ../x/bank @@ -252,7 +254,4 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // We always want to test against the latest version of the SDK. github.com/cosmos/cosmos-sdk => ../. - // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. - // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 - github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 ) From 9b4b398cf06d2f819fe5ed26e801fef252de3233 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 30 Jan 2024 13:13:51 +0100 Subject: [PATCH 20/20] fix linting --- x/accounts/go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/x/accounts/go.mod b/x/accounts/go.mod index 61e88f068ff9..64918a6848ae 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -160,6 +160,7 @@ replace github.com/cosmos/cosmos-sdk => ../../. replace ( cosmossdk.io/api => ../../api cosmossdk.io/depinject => ../../depinject + cosmossdk.io/core => ../../core cosmossdk.io/x/auth => ../auth cosmossdk.io/x/bank => ../bank cosmossdk.io/x/distribution => ../distribution