diff --git a/src/config.rs b/src/config.rs index 7708654a..bd928060 100644 --- a/src/config.rs +++ b/src/config.rs @@ -199,6 +199,7 @@ pub struct CosmosSection { pub key_derivation_path: String, pub prefix: String, pub msg_batch_size: u32, + pub gas_limit_per_msg: u64, pub gas_price: GasPrice, } @@ -210,6 +211,7 @@ impl Default for CosmosSection { key_derivation_path: "m/44'/118'/0'/0/0".to_owned(), prefix: "somm".to_owned(), msg_batch_size: 5, + gas_limit_per_msg: 20_000_000u64, gas_price: GasPrice::default(), } } diff --git a/src/cork.rs b/src/cork.rs index 9e339960..81dc6236 100644 --- a/src/cork.rs +++ b/src/cork.rs @@ -141,6 +141,7 @@ pub async fn schedule_cork( config::DELEGATE_ADDRESS.to_string(), &config::DELEGATE_KEY, fee, + config.cosmos.gas_limit_per_msg, height, ) .await diff --git a/src/gen/proto/descriptor.bin b/src/gen/proto/descriptor.bin index 7186a999..81ab5942 100644 Binary files a/src/gen/proto/descriptor.bin and b/src/gen/proto/descriptor.bin differ diff --git a/src/somm_send.rs b/src/somm_send.rs index 4285d7dd..1b3a077d 100644 --- a/src/somm_send.rs +++ b/src/somm_send.rs @@ -20,6 +20,7 @@ pub async fn schedule_cork( delegate_address: String, delegate_key: &CosmosPrivateKey, fee: Coin, + gas_limit_per_msg: u64, block_height: u64, ) -> Result { let msg = MsgScheduleCorkRequest { @@ -28,20 +29,29 @@ pub async fn schedule_cork( block_height, }; let msg = Msg::new("/cork.v2.MsgScheduleCorkRequest", msg); - __send_messages(contact, delegate_key, fee, vec![msg]).await + __send_messages(contact, delegate_key, fee, gas_limit_per_msg, vec![msg]).await } async fn __send_messages( contact: &Contact, cosmos_key: &CosmosPrivateKey, fee: Coin, + gas_limit_per_msg: u64, messages: Vec, ) -> Result { let cosmos_address = cosmos_key.to_address(&contact.get_prefix())?; + let gas_limit = gas_limit_per_msg * (messages.len() as u64); + + // block gas limit check + if gas_limit > 20_000_000u64 { + return Err(CosmosGrpcError::BadInput( + "total gas limit too high. (gas limit) * (number of messages) exceeded 20M".to_string(), + )); + } let fee = Fee { amount: vec![fee], - gas_limit: 500_000u64 * (messages.len() as u64), + gas_limit, granter: None, payer: None, };