From d46f344d66d3a3812eb1afd13dfaf825edcd28a4 Mon Sep 17 00:00:00 2001 From: Aleksao998 Date: Tue, 2 Sep 2025 19:16:08 +0200 Subject: [PATCH 1/2] bugfix: cacheContext not passed to sudo --- x/babylon/keeper/wasm.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/x/babylon/keeper/wasm.go b/x/babylon/keeper/wasm.go index 861b338..01f55f2 100644 --- a/x/babylon/keeper/wasm.go +++ b/x/babylon/keeper/wasm.go @@ -129,8 +129,10 @@ func (k Keeper) doSudoCallWithGasLimit(ctx sdk.Context, contractAddr sdk.AccAddr return } - // Create a gas-limited context - gasCtx := ctx.WithGasMeter(storetypes.NewGasMeter(maxGas)) + // Create a cache context to ensure atomicity; commit only on success + cacheCtx, write := ctx.CacheContext() + // Create a gas-limited context on top of the cache context + gasCtx := cacheCtx.WithGasMeter(storetypes.NewGasMeter(maxGas)) // Use defer to recover from panics that might occur during contract execution defer func() { @@ -151,6 +153,8 @@ func (k Keeper) doSudoCallWithGasLimit(ctx sdk.Context, contractAddr sdk.AccAddr return } + // Commit cached writes only after successful execution + write() gasConsumed = gasCtx.GasMeter().GasConsumed() return From 1103ffe481c9781846229f081df1ac23096ea985 Mon Sep 17 00:00:00 2001 From: Aleksao998 Date: Wed, 3 Sep 2025 15:22:29 +0200 Subject: [PATCH 2/2] add: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a36051..36d2fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Improvements +- [#219](https://github.com/babylonlabs-io/babylon-sdk/pull/219) bugfix: + cacheContext not passed to sudo - [#217](https://github.com/babylonlabs-io/babylon-sdk/pull/217) chore: fix go mod - [#215](https://github.com/babylonlabs-io/babylon-sdk/pull/215) chore: bump