Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -689,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.
Expand Down Expand Up @@ -1013,15 +1016,15 @@ 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.
func (app *THORChainApp) RegisterTendermintService(clientCtx client.Context) {
cmtApp := server.NewCometABCIWrapper(app)
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.GRPCQueryRouter(),
app.interfaceRegistry,
cmtApp.Query,
)
Expand Down Expand Up @@ -1067,6 +1070,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
Expand Down
8 changes: 8 additions & 0 deletions app/query_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
19 changes: 16 additions & 3 deletions x/thorchain/forking/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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"
)
Expand Down Expand Up @@ -90,6 +92,9 @@ func (f *forkingKVStore) shouldAllowRemoteFetch() bool {
}

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())
}
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))
}
Expand Down Expand Up @@ -190,13 +195,17 @@ func (f *forkingKVStore) Delete(key []byte) error {
}

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())
}
localIter, err := f.parent.Iterator(start, end)
if err != nil {
fmt.Printf("[forking][ITER] local-err store=%s err=%v\n", f.storeKey, err)
return nil, err
}

if !f.shouldAllowRemoteFetch() {
if f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc" || !f.shouldAllowRemoteFetch() {
return localIter, nil
}

Expand All @@ -208,13 +217,17 @@ func (f *forkingKVStore) Iterator(start, end []byte) (storetypes.Iterator, error
}

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())
}
localIter, err := f.parent.ReverseIterator(start, end)
if err != nil {
fmt.Printf("[forking][RITER] local-err store=%s err=%v\n", f.storeKey, err)
return nil, err
}

if !f.shouldAllowRemoteFetch() {
if f.storeKey == "bank" || f.storeKey == "auth" || f.storeKey == "acc" || !f.shouldAllowRemoteFetch() {
return localIter, nil
}

Expand Down