Skip to content
Merged
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
40 changes: 20 additions & 20 deletions src/client/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use cosmos_sdk_proto::cosmos::base::tendermint::v1beta1::GetSyncingRequest;
use cosmos_sdk_proto::cosmos::consensus::v1::query_client::QueryClient as ConsensusQueryClient;
use cosmos_sdk_proto::cosmos::consensus::v1::QueryParamsRequest;
use cosmos_sdk_proto::cosmos::params::v1beta1::query_client::QueryClient as ParamsQueryClient;
use cosmos_sdk_proto::cosmos::params::v1beta1::{QueryParamsRequest as LegacyQueryParamsRequest, QueryParamsResponse as LegacyQueryParamsResponse};
use cosmos_sdk_proto::cosmos::params::v1beta1::{
QueryParamsRequest as LegacyQueryParamsRequest,
QueryParamsResponse as LegacyQueryParamsResponse,
};
use cosmos_sdk_proto::cosmos::tx::v1beta1::service_client::ServiceClient as TxServiceClient;
use cosmos_sdk_proto::cosmos::tx::v1beta1::GetTxRequest;
use cosmos_sdk_proto::cosmos::tx::v1beta1::GetTxResponse;
Expand Down Expand Up @@ -188,11 +191,7 @@ impl Contact {
ConsensusQueryClient::connect(self.url.clone()),
)
.await??;
let res = timeout(
self.get_timeout(),
grpc.params(QueryParamsRequest{}),
)
.await?;
let res = timeout(self.get_timeout(), grpc.params(QueryParamsRequest {})).await?;
if let Err(e) = res {
if e.code() == tonic::Code::Unimplemented {
// this means the chain doesn't have the new params query endpoint so we fall back to the old method
Expand All @@ -204,10 +203,13 @@ impl Contact {
}
if let Some(v) = res.unwrap().into_inner().params {
match v.block {
Some(v) => {
Ok(BlockParams { max_bytes: v.max_bytes as u64, max_gas: Some(v.max_gas as u64) })
}
None => Err(CosmosGrpcError::BadResponse("No BlockParams? Deep Space/protos probably need an update".to_string())),
Some(v) => Ok(BlockParams {
max_bytes: v.max_bytes as u64,
max_gas: Some(v.max_gas as u64),
}),
None => Err(CosmosGrpcError::BadResponse(
"No BlockParams? Deep Space/protos probably need an update".to_string(),
)),
}
} else {
// if we hit this error the value has been moved and we're probably
Expand All @@ -229,17 +231,15 @@ impl Contact {
let v: BlockParamsJson = v;
Ok(v.into())
}
Err(e) => {
Err(CosmosGrpcError::BadResponse(format!(
"Failed to parse BlockParams: {}",
e
)))
}
Err(e) => Err(CosmosGrpcError::BadResponse(format!(
"Failed to parse BlockParams: {}",
e
))),
}
} else {
// if we hit this error the value has been moved and we're probably
// woefully out of date.
Err(CosmosGrpcError::BadResponse(
// if we hit this error the value has been moved and we're probably
// woefully out of date.
Err(CosmosGrpcError::BadResponse(
"No BlockParams? Deep Space probably needs to be upgraded".to_string(),
))
}
Expand All @@ -248,7 +248,7 @@ impl Contact {
/// Queries a registered parameter given it's subspace and key, this should work
/// for any module so long as it has registered the parameter
#[deprecated(
note = "Modules manage their own parameters now, use the module's grpc client to get parameters",
note = "Modules manage their own parameters now, use the module's grpc client to get parameters"
)]
pub async fn get_param(
&self,
Expand Down
4 changes: 3 additions & 1 deletion src/client/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ impl Contact {
};
let msg = Msg::new(MSG_VERIFY_INVARIANT_TYPE_URL, verify);
trace!("Submitting simulation");
self.simulate_tx(&[msg], None, private_key).await
let block_params = self.get_block_params().await?;
self.simulate_tx(&[msg], None, private_key, block_params.max_gas)
.await
}

/// A utility function which executes the specified invariant and returns the TxResponse if one is given
Expand Down
12 changes: 9 additions & 3 deletions src/client/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,20 @@ impl Contact {
fee_token: &[Coin],
private_key: impl PrivateKey,
) -> Result<Fee, CosmosGrpcError> {
let block_params = self.get_block_params().await?;
let gas_info = self
.simulate_tx(messages, Some(fee_token), private_key.clone())
.simulate_tx(
messages,
Some(fee_token),
private_key.clone(),
block_params.max_gas,
)
.await?
.gas_info
.unwrap();
let gas_used = gas_info.gas_used;
trace!("Got {} gas used!", gas_used);

let block_params = self.get_block_params().await?;
if let Some(max_gas) = block_params.max_gas {
if gas_used > max_gas {
return Err(CosmosGrpcError::GasRequiredExceedsBlockMaximum {
Expand Down Expand Up @@ -255,6 +260,7 @@ impl Contact {
messages: &[Msg],
fee_amount: Option<&[Coin]>,
private_key: impl PrivateKey,
max_gas: Option<u64>,
) -> Result<SimulateResponse, CosmosGrpcError> {
let our_address = private_key.to_address(&self.chain_prefix).unwrap();
let fee_amount = fee_amount.unwrap_or_default();
Expand All @@ -264,7 +270,7 @@ impl Contact {
let fee_obj = Fee {
amount: fee_amount.to_vec(),
// derived from this constant https://github.com/cosmos/cosmos-sdk/blob/master/types/tx/types.go#L13
gas_limit: 9223372036854775807,
gas_limit: max_gas.unwrap_or(10_000_000),
granter: None,
payer: None,
};
Expand Down
Loading