Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve gas cost estimation #337

Merged
merged 1 commit into from
Nov 6, 2024
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parachain/runtimes/nexus/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ fn main() {
.export_heap_base()
.import_memory()
.build()
}
}
26 changes: 4 additions & 22 deletions tesseract/evm/src/gas_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pub async fn get_current_gas_cost_in_usd(
chain: StateMachine,
api_keys: &str,
client: Arc<Provider<Http>>,
gas_price_buffer: Option<u32>,
) -> Result<GasBreakdown, Error> {
let mut gas_price_cost = U256::zero();
let mut gas_price = U256::zero();
Expand Down Expand Up @@ -288,11 +287,6 @@ pub async fn get_current_gas_cost_in_usd(
ethers::utils::format_units(gas_price, "gwei").unwrap()
);

let buffer = gas_price_buffer
.map(|buffer| (U256::from(buffer) * gas_price) / U256::from(100u32))
.unwrap_or_default();
gas_price = gas_price + buffer;

Ok(GasBreakdown { gas_price, gas_price_cost: gas_price_cost.into(), unit_wei_cost: unit_wei })
}

Expand Down Expand Up @@ -423,7 +417,6 @@ mod test {
StateMachine::Evm(SEPOLIA_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -446,7 +439,6 @@ mod test {
StateMachine::Evm(SEPOLIA_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -469,7 +461,6 @@ mod test {
StateMachine::Evm(POLYGON_TESTNET_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -486,14 +477,10 @@ mod test {
let provider = Provider::<Http>::try_from(ethereum_rpc_uri).unwrap();
let client = Arc::new(provider.clone());

let ethereum_gas_cost_in_usd = get_current_gas_cost_in_usd(
StateMachine::Evm(GNOSIS_CHAIN_ID),
"",
client.clone(),
None,
)
.await
.unwrap();
let ethereum_gas_cost_in_usd =
get_current_gas_cost_in_usd(StateMachine::Evm(GNOSIS_CHAIN_ID), "", client.clone())
.await
.unwrap();

println!("Ethereum Gas Cost Gnosis Mainnet: {:?}", ethereum_gas_cost_in_usd);
}
Expand All @@ -513,7 +500,6 @@ mod test {
StateMachine::Evm(POLYGON_TESTNET_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -536,7 +522,6 @@ mod test {
StateMachine::Evm(BSC_TESTNET_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -558,7 +543,6 @@ mod test {
StateMachine::Evm(ARBITRUM_SEPOLIA_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -580,7 +564,6 @@ mod test {
StateMachine::Evm(OPTIMISM_SEPOLIA_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand All @@ -601,7 +584,6 @@ mod test {
StateMachine::Evm(OPTIMISM_SEPOLIA_CHAIN_ID),
&ethereum_etherscan_api_key,
client.clone(),
None,
)
.await
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion tesseract/evm/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ impl IsmpProvider for EvmClient {
self.state_machine,
&self.config.etherscan_api_key.clone(),
self.client.clone(),
self.config.gas_price_buffer,
)
.await?;
let mut gas_estimates = vec![];
Expand Down
11 changes: 8 additions & 3 deletions tesseract/evm/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ where
client.state_machine,
&client.config.etherscan_api_key.clone(),
client.client.clone(),
client.config.gas_price_buffer,
)
.await?
.gas_price * 2; // for good measure
Expand Down Expand Up @@ -228,19 +227,25 @@ pub async fn generate_contract_calls(
// Erigon does not support block overrides when tracing so we don't have the option of omiting
// the gas price by overriding the base fee
let set_gas_price = || !debug_trace || client.client_type.erigon();
let gas_price = if set_gas_price() {
let mut gas_price = if set_gas_price() {
get_current_gas_cost_in_usd(
client.state_machine,
&client.config.etherscan_api_key.clone(),
client.client.clone(),
client.config.gas_price_buffer,
)
.await?
.gas_price
} else {
Default::default()
};

// Only use gas price buffer when submitting transactions
if !debug_trace && client.config.gas_price_buffer.is_some() {
let buffer = (U256::from(client.config.gas_price_buffer.unwrap_or_default()) * gas_price) /
U256::from(100u32);
gas_price = gas_price + buffer
}

for message in messages {
match message {
Message::Consensus(msg) => {
Expand Down
2 changes: 1 addition & 1 deletion tesseract/relayer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tesseract"
version = "1.0.0"
version = "1.0.1"
edition = "2021"
description = "Chain agnostic relayer implementation for Hyperbridge"
authors = ["Polytope Labs <hello@polytope.technology>"]
Expand Down
Loading