Skip to content

Commit

Permalink
Merge pull request #1180 from public-awesome/jhernandezb/fix-cron
Browse files Browse the repository at this point in the history
fix abci begin/end blockers
  • Loading branch information
jhernandezb authored Jan 8, 2025
2 parents 76ee4d2 + ce67a8d commit df6ad98
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ steps:
event:
- push
branch:
- jhernandezb/upgrade-params
- jhernandezb/fix-cron
- main
- name: docker_release
image: plugins/docker
Expand Down Expand Up @@ -411,7 +411,7 @@ steps:
trigger:
branch:
- main
- jhernandezb/upgrade-params
- jhernandezb/fix-cron
event:
- pull_request
- push
Expand All @@ -424,6 +424,6 @@ volumes:

---
kind: signature
hmac: 6fa113240c7eeed870eef11e63633911cae346e1b0286c8a4afc0c3677050b2b
hmac: 7f6a696633927ee7fcac8511be795df0f17c229369d245c4c7cb4ca83c09ac96

...
1 change: 0 additions & 1 deletion .github/workflows/interchaintest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ jobs:
run_chain_upgrade_interchaintest,
run_ica_interchaintest,
run_chain_conformance,
run_slinky_interchaintest,
]
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COPY . /code/
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.4/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.4/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
RUN echo "a4a3d09b36fabb65b119d5ba23442c23694401fcbee4451fe6b7e22e325a4bac /lib/libwasmvm_muslc.x86_64.a" | sha256sum -c
RUN echo "faea4e15390e046d2ca8441c21a88dba56f9a0363f92c5d94015df0ac6da1f2d /lib/libwasmvm_muslc.aarch64.a" | sha256sum -c
RUN echo "090b97641157fae1ae45e7ed368a1a8c091f3fef67958d3bc7c2fa7e7c54b6b4 /lib/libwasmvm_muslc.aarch64.a" | sha256sum -c

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgrades "github.com/public-awesome/stargaze/v15/app/upgrades"
mainnetupgradesv15 "github.com/public-awesome/stargaze/v15/app/upgrades/mainnet/v15"
testnetupgradesv15b2 "github.com/public-awesome/stargaze/v15/app/upgrades/testnet/v15b2"
)

var Upgrades = []upgrades.Upgrade{
mainnetupgradesv15.Upgrade,
testnetupgradesv15b2.Upgrade,
}

func (app App) RegisterUpgradeHandlers(configurator module.Configurator) {
Expand Down
36 changes: 36 additions & 0 deletions app/upgrades/testnet/v15b2/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package v15

import (
"context"
"time"

storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/public-awesome/stargaze/v15/app/keepers"
"github.com/public-awesome/stargaze/v15/app/upgrades"
)

// next upgrade name
const UpgradeName = "v15b2"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator, _ keepers.StargazeKeepers) upgradetypes.UpgradeHandler {
return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
startTime := time.Now()
wctx := sdk.UnwrapSDKContext(ctx)
wctx.Logger().Info("upgrade started", "upgrade_name", UpgradeName)
migrations, err := mm.RunMigrations(ctx, cfg, fromVM)
if err != nil {
return nil, err
}
wctx.Logger().Info("upgrade completed", "duration_ms", time.Since(startTime).Milliseconds())
return migrations, nil
}
},
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{},
},
}
4 changes: 3 additions & 1 deletion x/alloc/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alloc

import (
"context"
"fmt"
"time"

Expand All @@ -11,7 +12,8 @@ import (
)

// BeginBlocker to distribute specific rewards on every begin block
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
ctx := sdk.UnwrapSDKContext(goCtx)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
if err := k.DistributeInflation(ctx); err != nil {
panic(fmt.Sprintf("Error distribute inflation: %s", err.Error()))
Expand Down
9 changes: 6 additions & 3 deletions x/alloc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// this line is used by starport scaffolding # 1

"cosmossdk.io/core/appmodule"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

Expand All @@ -23,8 +24,9 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ appmodule.HasBeginBlocker = AppModule{}
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -156,8 +158,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 4 }

// BeginBlock executes all ABCI BeginBlock logic respective to the alloc module.
func (am AppModule) BeginBlock(ctx sdk.Context) {
func (am AppModule) BeginBlock(ctx context.Context) error {
BeginBlocker(ctx, am.keeper)
return nil
}

// EndBlock executes all ABCI EndBlock logic respective to the alloc module. It
Expand Down
9 changes: 5 additions & 4 deletions x/cron/abci.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cron

import (
"context"
"encoding/json"
"fmt"
"runtime/debug"
"time"

"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/public-awesome/stargaze/v15/x/cron/contract"
Expand All @@ -17,18 +17,19 @@ import (
)

// BeginBlocker sends a BeginBlock SudoMsg to all privileged contracts
func BeginBlocker(ctx sdk.Context, k keeper.Keeper, w types.WasmKeeper) {
func BeginBlocker(goCtx context.Context, k keeper.Keeper, w types.WasmKeeper) {
ctx := sdk.UnwrapSDKContext(goCtx)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
sudoMsg := contract.SudoMsg{BeginBlock: &struct{}{}}
k.IteratePrivileged(ctx, abciContractCallback(ctx, w, sudoMsg))
}

// EndBlocker sends a EndBlock SudoMsg to all privileged contracts
func EndBlocker(ctx sdk.Context, k keeper.Keeper, w types.WasmKeeper) []abci.ValidatorUpdate {
func EndBlocker(goCtx context.Context, k keeper.Keeper, w types.WasmKeeper) {
ctx := sdk.UnwrapSDKContext(goCtx)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
sudoMsg := contract.SudoMsg{EndBlock: &struct{}{}}
k.IteratePrivileged(ctx, abciContractCallback(ctx, w, sudoMsg))
return nil
}

// returns safe method to send the message via sudo to the privileged contract
Expand Down
15 changes: 10 additions & 5 deletions x/cron/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

abci "github.com/cometbft/cometbft/abci/types"

"cosmossdk.io/core/appmodule"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -23,8 +24,10 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ appmodule.HasBeginBlocker = AppModule{}
_ appmodule.HasEndBlocker = AppModule{}
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -144,13 +147,15 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(ctx sdk.Context) {
func (am AppModule) BeginBlock(ctx context.Context) error {
BeginBlocker(ctx, am.keeper, am.wasmKeeper)
return nil
}

// EndBlock contains the logic that is automatically triggered at the end of each block
func (am AppModule) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate {
return EndBlocker(ctx, am.keeper, am.wasmKeeper)
func (am AppModule) EndBlock(ctx context.Context) error {
EndBlocker(ctx, am.keeper, am.wasmKeeper)
return nil
}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
Expand Down
4 changes: 3 additions & 1 deletion x/mint/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mint

import (
"context"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
Expand All @@ -10,7 +11,8 @@ import (
)

// BeginBlocker mints new tokens for the previous block.
func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
func BeginBlocker(goCtx context.Context, k keeper.Keeper) {
ctx := sdk.UnwrapSDKContext(goCtx)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

// fetch stored minter & params
Expand Down
9 changes: 6 additions & 3 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"

"cosmossdk.io/core/appmodule"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand All @@ -21,8 +22,9 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ appmodule.HasBeginBlocker = AppModule{}
)

// AppModuleBasic defines the basic application module used by the mint module.
Expand Down Expand Up @@ -145,8 +147,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 2 }

// BeginBlock returns the begin blocker for the mint module.
func (am AppModule) BeginBlock(ctx sdk.Context) {
func (am AppModule) BeginBlock(ctx context.Context) error {
BeginBlocker(ctx, am.keeper)
return nil
}

// EndBlock returns the end blocker for the mint module. It returns no validator
Expand Down

0 comments on commit df6ad98

Please sign in to comment.