From 575eab97f47074b638b82a8e885b3b7ae8ca3ca5 Mon Sep 17 00:00:00 2001 From: Til Jordan Date: Tue, 16 Sep 2025 15:56:16 +0000 Subject: [PATCH 1/3] app,store(forking): add THOR_FORK_DEBUG-gated logs for RPC ABCI bank/auth/acc query tracing --- app/query_service_router.go | 8 ++++++++ x/thorchain/forking/store.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/query_service_router.go b/app/query_service_router.go index 4a584d72e..5ab4668e7 100644 --- a/app/query_service_router.go +++ b/app/query_service_router.go @@ -2,6 +2,8 @@ package app import ( "context" + "fmt" + "os" "github.com/cosmos/cosmos-sdk/baseapp" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -60,11 +62,17 @@ func (w *BankQueryWrapper) extractUserAPICall(goCtx context.Context) context.Con } func (w *BankQueryWrapper) Balance(goCtx context.Context, req *banktypes.QueryBalanceRequest) (*banktypes.QueryBalanceResponse, error) { + if os.Getenv("THOR_FORK_DEBUG") == "1" { + fmt.Printf("[rpc-debug] BankQueryWrapper.Balance entry\n") + } ctx := w.extractUserAPICall(goCtx) return w.originalHandler.Balance(ctx, req) } func (w *BankQueryWrapper) AllBalances(goCtx context.Context, req *banktypes.QueryAllBalancesRequest) (*banktypes.QueryAllBalancesResponse, error) { + if os.Getenv("THOR_FORK_DEBUG") == "1" { + fmt.Printf("[rpc-debug] BankQueryWrapper.AllBalances entry\n") + } ctx := w.extractUserAPICall(goCtx) return w.originalHandler.AllBalances(ctx, req) } diff --git a/x/thorchain/forking/store.go b/x/thorchain/forking/store.go index 244bbeae7..73afc3de4 100644 --- a/x/thorchain/forking/store.go +++ b/x/thorchain/forking/store.go @@ -1,5 +1,6 @@ package forking + "os" import ( "context" "encoding/hex" @@ -89,6 +90,9 @@ func (f *forkingKVStore) shouldAllowRemoteFetch() bool { return true } + if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { + fmt.Printf("[rpc-debug][GET] store=%s key=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(key), f.shouldAllowRemoteFetch()) + } func (f *forkingKVStore) Get(key []byte) ([]byte, error) { if f.storeKey == "wasm" && len(key) > 0 && key[0] == 0x02 { fmt.Printf("[forking][GET][wasm] ContractInfo key len=%d key=%s\n", len(key), hex.EncodeToString(key)) @@ -189,6 +193,10 @@ func (f *forkingKVStore) Delete(key []byte) error { return nil } + if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { + s, e := start, end + fmt.Printf("[rpc-debug][ITER] store=%s start=%s end=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(s), hex.EncodeToString(e), f.shouldAllowRemoteFetch()) + } func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error) { localIter, err := f.parent.Iterator(start, end) if err != nil { @@ -207,6 +215,10 @@ func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error return NewMergedIterator(localIter, remoteIter), nil } + if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { + s, e := start, end + fmt.Printf("[rpc-debug][RITER] store=%s start=%s end=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(s), hex.EncodeToString(e), f.shouldAllowRemoteFetch()) + } func (f *forkingKVStore) ReverseIterator(start, end []byte) (storetypes.Iterator, error) { localIter, err := f.parent.ReverseIterator(start, end) if err != nil { From 9d13e950132f11a2206271ed9808c99e7984aaa6 Mon Sep 17 00:00:00 2001 From: Til Jordan Date: Tue, 16 Sep 2025 16:45:23 +0000 Subject: [PATCH 2/3] app(query): route Tx/Tendermint services through custom GRPCQueryRouter; add debug logs for bank/auth/acc RPC path --- app/app.go | 9 +++++++-- x/thorchain/forking/store.go | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/app.go b/app/app.go index 69d23a151..9c780562b 100644 --- a/app/app.go +++ b/app/app.go @@ -93,6 +93,7 @@ import ( denomtypes "gitlab.com/thorchain/thornode/v3/x/denom/types" evm "github.com/cosmos/evm/encoding/codec" + "github.com/cosmos/evm/ethereum/eip712" ) @@ -1013,7 +1014,7 @@ func RegisterSwaggerAPI(rtr *mux.Router, swaggerEnabled bool) error { // RegisterTxService implements the Application.RegisterTxService method. func (app *THORChainApp) RegisterTxService(clientCtx client.Context) { - authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) + authtx.RegisterTxService(app.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } // RegisterTendermintService implements the Application.RegisterTendermintService method. @@ -1021,7 +1022,7 @@ func (app *THORChainApp) RegisterTendermintService(clientCtx client.Context) { cmtApp := server.NewCometABCIWrapper(app) cmtservice.RegisterTendermintService( clientCtx, - app.BaseApp.GRPCQueryRouter(), + app.GRPCQueryRouter(), app.interfaceRegistry, cmtApp.Query, ) @@ -1067,6 +1068,10 @@ func BlockedAddresses() map[string]bool { return modAccAddrs } +func (app *THORChainApp) GRPCQueryRouter() *QueryServiceRouter { + return app.queryServiceRouter +} + // MsgServiceRouter returns the MsgServiceRouter. func (app *THORChainApp) MsgServiceRouter() *MsgServiceRouter { return app.msgServiceRouter diff --git a/x/thorchain/forking/store.go b/x/thorchain/forking/store.go index 73afc3de4..82e568eee 100644 --- a/x/thorchain/forking/store.go +++ b/x/thorchain/forking/store.go @@ -1,13 +1,14 @@ package forking - "os" import ( "context" "encoding/hex" "fmt" - "gitlab.com/thorchain/thornode/v3/constants" + "os" "time" + "gitlab.com/thorchain/thornode/v3/constants" + storetypes "cosmossdk.io/core/store" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -90,10 +91,10 @@ func (f *forkingKVStore) shouldAllowRemoteFetch() bool { return true } +func (f *forkingKVStore) Get(key []byte) ([]byte, error) { if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { fmt.Printf("[rpc-debug][GET] store=%s key=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(key), f.shouldAllowRemoteFetch()) } -func (f *forkingKVStore) Get(key []byte) ([]byte, error) { if f.storeKey == "wasm" && len(key) > 0 && key[0] == 0x02 { fmt.Printf("[forking][GET][wasm] ContractInfo key len=%d key=%s\n", len(key), hex.EncodeToString(key)) } @@ -193,11 +194,11 @@ func (f *forkingKVStore) Delete(key []byte) error { return nil } +func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error) { if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { s, e := start, end fmt.Printf("[rpc-debug][ITER] store=%s start=%s end=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(s), hex.EncodeToString(e), f.shouldAllowRemoteFetch()) } -func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error) { localIter, err := f.parent.Iterator(start, end) if err != nil { fmt.Printf("[forking][ITER] local-err store=%s err=%v\n", f.storeKey, err) @@ -215,11 +216,11 @@ func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error return NewMergedIterator(localIter, remoteIter), nil } +func (f *forkingKVStore) ReverseIterator(start, end []byte) (storetypes.Iterator, error) { if os.Getenv("THOR_FORK_DEBUG") == "1" && (f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc") { s, e := start, end fmt.Printf("[rpc-debug][RITER] store=%s start=%s end=%s allowRemote=%v\n", f.storeKey, hex.EncodeToString(s), hex.EncodeToString(e), f.shouldAllowRemoteFetch()) } -func (f *forkingKVStore) ReverseIterator(start, end []byte) (storetypes.Iterator, error) { localIter, err := f.parent.ReverseIterator(start, end) if err != nil { fmt.Printf("[forking][RITER] local-err store=%s err=%v\n", f.storeKey, err) From 550b4703047f72a9ab79a99d06153aaa17a5d523 Mon Sep 17 00:00:00 2001 From: Til Jordan Date: Tue, 16 Sep 2025 19:11:36 +0000 Subject: [PATCH 3/3] app(query): ensure BaseApp uses custom GRPCQueryRouter for ABCI; forking(store): force local-only iterators for bank/auth/acc on RPC/ABCI paths --- app/app.go | 2 ++ x/thorchain/forking/store.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 9c780562b..b4cea114d 100644 --- a/app/app.go +++ b/app/app.go @@ -690,6 +690,8 @@ func NewChainApp( if err != nil { panic(err) } + app.BaseApp.SetGRPCQueryRouter(app.GRPCQueryRouter()) + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. diff --git a/x/thorchain/forking/store.go b/x/thorchain/forking/store.go index 82e568eee..e0dd1931e 100644 --- a/x/thorchain/forking/store.go +++ b/x/thorchain/forking/store.go @@ -205,7 +205,7 @@ func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error return nil, err } - if !f.shouldAllowRemoteFetch() { + if f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc" || !f.shouldAllowRemoteFetch() { return localIter, nil } @@ -227,7 +227,7 @@ func (f *forkingKVStore) ReverseIterator(start, end []byte) (storetypes.Iterator return nil, err } - if !f.shouldAllowRemoteFetch() { + if f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc" || !f.shouldAllowRemoteFetch() { return localIter, nil }