Skip to content

Commit

Permalink
Set chain's gas_price based off of fetched chain data (#3426)
Browse files Browse the repository at this point in the history
* Set gas_price based off of fetched chain data

* Update crates/relayer-cli/src/commands/config/auto.rs

Signed-off-by: Romain Ruetschi <[email protected]>

---------

Signed-off-by: Romain Ruetschi <[email protected]>
Co-authored-by: Romain Ruetschi <[email protected]>
  • Loading branch information
seanchen1991 and romac authored Jun 19, 2023
1 parent 6959325 commit c06d1b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
15 changes: 13 additions & 2 deletions crates/relayer-cli/src/chain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ where
MAX_HEALTHY_QUERY_RETRIES,
)
.await?;

let grpc_address = query_healthy_retry::<GrpcQuerier>(
chain_name.to_string(),
grpc_endpoints,
Expand All @@ -113,6 +114,12 @@ where
RegistryError::websocket_url_parse_error(rpc_data.websocket.to_string(), e)
})?;

let avg_gas_price = if let Some(fee_token) = chain_data.fees.fee_tokens.first() {
fee_token.average_gas_price
} else {
0.1
};

Ok(ChainConfig {
id: chain_data.chain_id,
r#type: default::chain_type(),
Expand Down Expand Up @@ -146,7 +153,7 @@ where
proof_specs: Default::default(),
trust_threshold: TrustThreshold::default(),
gas_price: GasPrice {
price: 0.1,
price: avg_gas_price,
denom: asset.base.to_owned(),
},
packet_filter: packet_filter.unwrap_or_default(),
Expand Down Expand Up @@ -213,6 +220,7 @@ async fn get_data_from_handles<T>(
.map_err(|e| RegistryError::join_error(error_task.to_string(), e))?
.into_iter()
.collect();

data_array
}

Expand All @@ -236,6 +244,7 @@ pub async fn get_configs(
commit: Option<String>,
) -> Result<Vec<ChainConfig>, RegistryError> {
let n = chains.len();

if n == 0 {
return Ok(Vec::new());
}
Expand All @@ -245,6 +254,7 @@ pub async fn get_configs(
let asset_lists_handle = get_handles::<AssetList>(chains, &commit).await;

let mut path_handles = Vec::with_capacity(n * (n - 1) / 2);

for i in 0..n {
for chain_j in &chains[i + 1..] {
let chain_i = &chains[i];
Expand All @@ -255,8 +265,8 @@ pub async fn get_configs(
}));
}
}
// Collect data from the spawned tasks

// Collect data from the spawned tasks
let chain_data_array =
get_data_from_handles::<ChainData>(chain_data_handle, "chain_data_join").await?;
let asset_lists =
Expand Down Expand Up @@ -288,6 +298,7 @@ pub async fn get_configs(
})
})
.collect();

get_data_from_handles::<ChainConfig>(config_handles, "config_handle_join").await
}

Expand Down
13 changes: 5 additions & 8 deletions crates/relayer-cli/src/commands/config/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ impl Runnable for AutoCmd {
};

match store(&config, &self.path) {
Ok(_) => {
warn!("Gas parameters are set to default values.");
Output::success(format!(
"Config file written successfully : {}.",
self.path.to_str().unwrap()
))
.exit()
}
Ok(_) => Output::success(format!(
"Config file written successfully at {}.",
self.path.to_str().unwrap()
))
.exit(),
Err(e) => Output::error(e.to_string()).exit(),
}
}
Expand Down

0 comments on commit c06d1b3

Please sign in to comment.