From 3eab82c5739f8d1771be39ec52b72874095f8891 Mon Sep 17 00:00:00 2001 From: Artur Abliazimov Date: Mon, 23 Sep 2024 16:36:50 +0300 Subject: [PATCH] PR fixes --- cmd/wardenkms/wardenkms.go | 2 +- .../docs/build-a-keychain/build-a-keychain-app.md | 2 +- .../build-a-keychain/implementations/wardenkms.md | 2 +- go-client/tx_raw_client.go | 12 +++++------- keychain-sdk/example_keychain_test.go | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/wardenkms/wardenkms.go b/cmd/wardenkms/wardenkms.go index 187cd0c7e..ea08351bb 100644 --- a/cmd/wardenkms/wardenkms.go +++ b/cmd/wardenkms/wardenkms.go @@ -32,7 +32,7 @@ type Config struct { BatchInterval time.Duration `env:"BATCH_INTERVAL, default=8s"` BatchSize int `env:"BATCH_SIZE, default=7"` GasLimit uint64 `env:"GAS_LIMIT, default=400000"` - AutoEstimateGas bool `env:"AUTO_ESTIMATE_GAS, default=false"` + AutoEstimateGas bool `env:"AUTO_ESTIMATE_GAS, default=true"` GasAdjustmentFactor float64 `env:"GAS_ADJUSTMENT_FACTOR, default=1.1"` TxTimeout time.Duration `env:"TX_TIMEOUT, default=120s"` TxFee int64 `env:"TX_FEE, default=400000"` diff --git a/docs/developer-docs/docs/build-a-keychain/build-a-keychain-app.md b/docs/developer-docs/docs/build-a-keychain/build-a-keychain-app.md index f5266b2a6..fef7774b7 100644 --- a/docs/developer-docs/docs/build-a-keychain/build-a-keychain-app.md +++ b/docs/developer-docs/docs/build-a-keychain/build-a-keychain-app.md @@ -107,7 +107,7 @@ func main() { // setup throughput for batching responses GasLimit: 400000, - AutoEstimateGas: false, + AutoEstimateGas: true, GasAdjustmentFactor: 1.2, BatchTimeout: 8 * time.Second, BatchSize: 10, diff --git a/docs/developer-docs/docs/build-a-keychain/implementations/wardenkms.md b/docs/developer-docs/docs/build-a-keychain/implementations/wardenkms.md index 4721d8017..c017e0f53 100644 --- a/docs/developer-docs/docs/build-a-keychain/implementations/wardenkms.md +++ b/docs/developer-docs/docs/build-a-keychain/implementations/wardenkms.md @@ -49,7 +49,7 @@ type Config struct { BatchInterval time.Duration `env:"BATCH_INTERVAL, default=8s"` BatchSize int `env:"BATCH_SIZE, default=7"` GasLimit uint64 `env:"GAS_LIMIT, default=400000"` - AutoEstimateGas bool `env:"AUTO_ESTIMATE_GAS, default=false"` + AutoEstimateGas bool `env:"AUTO_ESTIMATE_GAS, default=true"` GasAdjustmentFactor float64 `env:"GAS_ADJUSTMENT_FACTOR, default=1.1"` TxTimeout time.Duration `env:"TX_TIMEOUT, default=120s"` TxFee int64 `env:"TX_FEE, default=400000"` diff --git a/go-client/tx_raw_client.go b/go-client/tx_raw_client.go index 9ab24da14..8ad55a49e 100644 --- a/go-client/tx_raw_client.go +++ b/go-client/tx_raw_client.go @@ -114,9 +114,6 @@ func (c *RawTxClient) BuildTx( signMode := app.TxConfig().SignModeHandler().DefaultMode() // build unsigned tx - if !autoEstimateGas { - txBuilder.SetGasLimit(gasLimit) - } txBuilder.SetFeeAmount(fees) msgs := make([]sdk.Msg, len(msgers)) @@ -151,11 +148,12 @@ func (c *RawTxClient) BuildTx( gasLimit, err = c.EstimateGas(ctx, txBytes, gasAdjustmentFactor, gasLimit) if err != nil { - return nil, fmt.Errorf("estimage gas: %w", err) + return nil, fmt.Errorf("estimate gas: %w", err) } - txBuilder.SetGasLimit(gasLimit) } + txBuilder.SetGasLimit(gasLimit) + // Second round: all signer infos are set, so each signer can sign. signerData := xauthsigning.SignerData{ ChainID: c.chainID, @@ -235,8 +233,8 @@ func (c *RawTxClient) WaitForTx(ctx context.Context, hash string) error { } } -// EstimateGas estimates gas by simulating the transaction when autoEstimateGas is set to true. -// Otherwise, GasLimit is used. +// EstimateGas estimates gas by simulating the transaction. +// If the simulation exceeds gasLimit, gasLimit is returned. func (c *RawTxClient) EstimateGas( ctx context.Context, txBytes []byte, diff --git a/keychain-sdk/example_keychain_test.go b/keychain-sdk/example_keychain_test.go index b2e16efe3..e98b091d4 100644 --- a/keychain-sdk/example_keychain_test.go +++ b/keychain-sdk/example_keychain_test.go @@ -31,7 +31,7 @@ func Main() { // setup throughput for batching responses GasLimit: 400000, - AutoEstimateGas: false, + AutoEstimateGas: true, GasAdjustmentFactor: 1.2, BatchInterval: 8 * time.Second, BatchSize: 10,