From 8cbd066ec22bcc0cd8bef487702331136d95958e Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Mon, 13 Jan 2025 20:44:37 +0100 Subject: [PATCH] fix: Large transactions simulation --- config.yml | 5 +++++ pkg/client/tx/context.go | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index 0554fcf5d..63efee887 100644 --- a/config.yml +++ b/config.yml @@ -104,6 +104,11 @@ validators: instrumentation: prometheus: true log_level: "info" + # Increase the rpc and mempool max bytes to support larger proof transactions. + rpc: + max_body_bytes: "100000000" + mempool: + max_tx_bytes: "100000000" client: chain-id: poktroll diff --git a/pkg/client/tx/context.go b/pkg/client/tx/context.go index 1275ba858..061553439 100644 --- a/pkg/client/tx/context.go +++ b/pkg/client/tx/context.go @@ -9,12 +9,22 @@ import ( cosmostx "github.com/cosmos/cosmos-sdk/client/tx" cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" cosmostypes "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" + grpc "google.golang.org/grpc" "github.com/pokt-network/poktroll/pkg/client" txtypes "github.com/pokt-network/poktroll/pkg/client/tx/types" ) +// maxGRPCMsgSize is the maximum message size the gRPC client can send and receive. +// The current value has been arbitrarily set to a large value after observing +// proof messages bundled within transactions exceeding the default 4MB limit. +// TODO_TECHDEBT: Adjust the max message size to a more sensible value. +// DEV_NOTE: This value should adjusted in concert with the CometBFT's rpc max_body_bytes, +// mempool max_tx_bytes and max_txs_bytes. +const maxGRPCMsgSize = 100 * 1024 * 1024 // 100MB + var _ client.TxContext = (*cosmosTxContext)(nil) // cosmosTxContext is an internal implementation of the client.TxContext interface. @@ -134,10 +144,24 @@ func (txCtx cosmosTxContext) GetSimulatedTxGas( WithFromName(signingKeyName). WithSequence(seq) - _, gas, err := cosmostx.CalculateGas(txCtx.GetClientCtx(), txf, msgs...) + txBytes, err := txf.BuildSimTx(msgs...) + if err != nil { + return 0, err + } + + txSvcClient := tx.NewServiceClient(clientCtx) + + simRequest := &tx.SimulateRequest{TxBytes: txBytes} + // Set the maximum message size for the gRPC client to allow large transactions + // (e.g. transactions with multiple proof messages) to be simulated. + gRPCOpts := []grpc.CallOption{ + grpc.MaxCallSendMsgSize(maxGRPCMsgSize), + grpc.MaxCallRecvMsgSize(maxGRPCMsgSize), + } + simRes, err := txSvcClient.Simulate(context.Background(), simRequest, gRPCOpts...) if err != nil { return 0, err } - return gas, nil + return uint64(txf.GasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil }