Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RelayMiner] Allow big transactions simulation #1027

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
rpc:
max_body_bytes: "100000000"
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
mempool:
max_tx_bytes: "100000000"
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
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.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
const maxGRPCMsgSize = 100 * 1024 * 1024 // 100MB
red-0ne marked this conversation as resolved.
Show resolved Hide resolved

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
}
Loading