Skip to content

Commit

Permalink
fix: Large transactions simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Jan 13, 2025
1 parent 7e05996 commit 8cbd066
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 26 additions & 2 deletions pkg/client/tx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

0 comments on commit 8cbd066

Please sign in to comment.