Skip to content

Commit

Permalink
gas limit per message config
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Jul 11, 2023
1 parent 3bd8981 commit 16bba16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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(),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified src/gen/proto/descriptor.bin
Binary file not shown.
14 changes: 12 additions & 2 deletions src/somm_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxResponse, CosmosGrpcError> {
let msg = MsgScheduleCorkRequest {
Expand All @@ -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<Msg>,
) -> Result<TxResponse, CosmosGrpcError> {
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,
};
Expand Down

0 comments on commit 16bba16

Please sign in to comment.