From 8c4c6706080469a1f0e56536120caabf78be81b6 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Thu, 7 Nov 2024 15:01:00 -0500 Subject: [PATCH] fixup! test: Take even more debug additions from #10165 --- golang/cosmos/x/swingset/keeper/msg_server.go | 11 ++-- golang/cosmos/x/swingset/types/msgs.go | 58 ++++++++++++++++++- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/golang/cosmos/x/swingset/keeper/msg_server.go b/golang/cosmos/x/swingset/keeper/msg_server.go index 55f43bfc355..f0f59943292 100644 --- a/golang/cosmos/x/swingset/keeper/msg_server.go +++ b/golang/cosmos/x/swingset/keeper/msg_server.go @@ -105,6 +105,7 @@ type walletSpendAction struct { type MultiStoreSpy struct { storetypes.MultiStore } + func (spy MultiStoreSpy) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore { return KVStoreSpy{spy.MultiStore.GetKVStore(storeKey), storeKey.Name()} } @@ -113,16 +114,17 @@ type KVStoreSpy struct { storetypes.KVStore name string } + func (spy KVStoreSpy) Get(key []byte) []byte { got := spy.KVStore.Get(key) stdlog.Printf("xxx gibson KVStore(%#q).Get(%#q) = %#q [k+v = %d]\n", - spy.name, key, got, len(key) + len(got)) + spy.name, key, got, len(key)+len(got)) return got } func (spy KVStoreSpy) Set(key, value []byte) { spy.KVStore.Set(key, value) stdlog.Printf("xxx gibson KVStore(%#q).Set(%#q, %#q) [k+v = %d]\n", - spy.name, key, value, len(key) + len(value)) + spy.name, key, value, len(key)+len(value)) } func (spy KVStoreSpy) Has(key []byte) bool { found := spy.KVStore.Has(key) @@ -139,6 +141,7 @@ func (spy KVStoreSpy) Delete(key []byte) { type GasMeterSpy struct { storetypes.GasMeter } + func (spy GasMeterSpy) ConsumeGas(amount storetypes.Gas, descriptor string) { stdlog.Printf("xxx gibson ConsumeGas %v %v\n", descriptor, amount) spy.GasMeter.ConsumeGas(amount, descriptor) @@ -159,8 +162,8 @@ func (keeper msgServer) WalletSpendAction(goCtx context.Context, msg *types.MsgW "remaining": gasMeter.GasRemaining(), "limit": gasMeter.Limit(), } - stdlog.Printf("xxx gibson WalletSpendAction GasConfig %+v %v\n", - ctx.KVGasConfig(), meterState) + stdlog.Printf("xxx gibson WalletSpendAction GasConfig %s %+v %v\n", + msg.Owner, ctx.KVGasConfig(), meterState) ctx = ctx.WithMultiStore(&MultiStoreSpy{ctx.MultiStore()}) ctx = ctx.WithGasMeter(&GasMeterSpy{gasMeter}) } diff --git a/golang/cosmos/x/swingset/types/msgs.go b/golang/cosmos/x/swingset/types/msgs.go index 8bedaf58a7d..fa4f80c4d71 100644 --- a/golang/cosmos/x/swingset/types/msgs.go +++ b/golang/cosmos/x/swingset/types/msgs.go @@ -11,6 +11,7 @@ import ( sdkioerrors "cosmossdk.io/errors" "github.com/Agoric/agoric-sdk/golang/cosmos/vm" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -281,6 +282,51 @@ func NewMsgWalletSpendAction(owner sdk.AccAddress, spendAction string) *MsgWalle } } +type MultiStoreSpy struct { + storetypes.MultiStore +} + +func (spy MultiStoreSpy) GetKVStore(storeKey storetypes.StoreKey) storetypes.KVStore { + return KVStoreSpy{spy.MultiStore.GetKVStore(storeKey), storeKey.Name()} +} + +type KVStoreSpy struct { + storetypes.KVStore + name string +} + +func (spy KVStoreSpy) Get(key []byte) []byte { + got := spy.KVStore.Get(key) + stdlog.Printf("xxx gibson KVStore(%#q).Get(%#q) = %#q [k+v = %d]\n", + spy.name, key, got, len(key)+len(got)) + return got +} +func (spy KVStoreSpy) Set(key, value []byte) { + spy.KVStore.Set(key, value) + stdlog.Printf("xxx gibson KVStore(%#q).Set(%#q, %#q) [k+v = %d]\n", + spy.name, key, value, len(key)+len(value)) +} +func (spy KVStoreSpy) Has(key []byte) bool { + found := spy.KVStore.Has(key) + stdlog.Printf("xxx gibson KVStore(%#q).Has(%#q) = %v\n", + spy.name, key, found) + return found +} +func (spy KVStoreSpy) Delete(key []byte) { + spy.KVStore.Delete(key) + stdlog.Printf("xxx gibson KVStore(%#q).Delete(%#q)\n", + spy.name, key) +} + +type GasMeterSpy struct { + storetypes.GasMeter +} + +func (spy GasMeterSpy) ConsumeGas(amount storetypes.Gas, descriptor string) { + stdlog.Printf("xxx gibson ConsumeGas %v %v\n", descriptor, amount) + spy.GasMeter.ConsumeGas(amount, descriptor) +} + // CheckAdmissibility implements the vm.ControllerAdmissionMsg interface. func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interface{}) error { xxx_gibson := false @@ -289,7 +335,17 @@ func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interfa xxx_gibson = xxx_gibson || ok && key == "XXX_GIBSON" && value != "" && value != "0" } if xxx_gibson { - stdlog.Println("xxx gibson WalletSpendAction.CheckAdmissibility", msg.Owner) + gasMeter := ctx.GasMeter() + meterState := map[string]storetypes.Gas{ + "consumed": gasMeter.GasConsumed(), + "consumedToLimit": gasMeter.GasConsumedToLimit(), + "remaining": gasMeter.GasRemaining(), + "limit": gasMeter.Limit(), + } + stdlog.Printf("xxx gibson WalletSpendAction.CheckAdmissibility GasConfig %s %+v %v\n", + msg.Owner, ctx.KVGasConfig(), meterState) + ctx = ctx.WithMultiStore(&MultiStoreSpy{ctx.MultiStore()}) + ctx = ctx.WithGasMeter(&GasMeterSpy{gasMeter}) } keeper, ok := data.(SwingSetKeeper) if !ok {