From 25acdf74fe9073c1380cfda5d9c0eeb72d6aebf5 Mon Sep 17 00:00:00 2001 From: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com> Date: Thu, 14 Jul 2022 13:56:09 +0900 Subject: [PATCH] specify gas limit multiplier for relaying (#74) --- orchestrator/ethereum_gravity/src/logic_call.rs | 3 ++- orchestrator/ethereum_gravity/src/submit_batch.rs | 3 ++- orchestrator/ethereum_gravity/src/valset_update.rs | 3 ++- orchestrator/gorc/src/commands/orchestrator/start.rs | 1 + orchestrator/gorc/src/commands/relayer/start.rs | 1 + orchestrator/gorc/src/config.rs | 2 ++ orchestrator/orchestrator/src/main_loop.rs | 2 ++ orchestrator/relayer/src/batch_relaying.rs | 6 ++++++ orchestrator/relayer/src/logic_call_relaying.rs | 3 +++ orchestrator/relayer/src/main.rs | 1 + orchestrator/relayer/src/main_loop.rs | 12 +++++++++--- orchestrator/relayer/src/valset_relaying.rs | 9 ++++++++- 12 files changed, 39 insertions(+), 7 deletions(-) diff --git a/orchestrator/ethereum_gravity/src/logic_call.rs b/orchestrator/ethereum_gravity/src/logic_call.rs index 49281274e..82d99320c 100644 --- a/orchestrator/ethereum_gravity/src/logic_call.rs +++ b/orchestrator/ethereum_gravity/src/logic_call.rs @@ -72,7 +72,8 @@ pub async fn send_eth_logic_call( let contract_call = contract_call .gas(gas_cost.gas) - .gas_price(gas_cost.gas_price); + .gas_price(gas_cost.gas_price) + .legacy(); // must submit transactions as legacy due to bug in manually-specified EIP1559 gas limits let pending_tx = contract_call.send().await?; let tx_hash = *pending_tx; diff --git a/orchestrator/ethereum_gravity/src/submit_batch.rs b/orchestrator/ethereum_gravity/src/submit_batch.rs index 1eda0f9c0..cf8136c27 100644 --- a/orchestrator/ethereum_gravity/src/submit_batch.rs +++ b/orchestrator/ethereum_gravity/src/submit_batch.rs @@ -64,7 +64,8 @@ pub async fn send_eth_transaction_batch( let contract_call = contract_call .gas(gas_cost.gas) - .gas_price(gas_cost.gas_price); + .gas_price(gas_cost.gas_price) + .legacy(); // must submit transactions as legacy due to bug in manually-specified EIP1559 gas limits let pending_tx = contract_call.send().await?; let tx_hash = *pending_tx; diff --git a/orchestrator/ethereum_gravity/src/valset_update.rs b/orchestrator/ethereum_gravity/src/valset_update.rs index 3b8b44c92..7cd90ffec 100644 --- a/orchestrator/ethereum_gravity/src/valset_update.rs +++ b/orchestrator/ethereum_gravity/src/valset_update.rs @@ -50,7 +50,8 @@ pub async fn send_eth_valset_update( )?; let contract_call = contract_call .gas(gas_cost.gas) - .gas_price(gas_cost.gas_price); + .gas_price(gas_cost.gas_price) + .legacy(); // must submit transactions as legacy due to bug in manually-specified EIP1559 gas limits let pending_tx = contract_call.send().await?; let tx_hash = *pending_tx; diff --git a/orchestrator/gorc/src/commands/orchestrator/start.rs b/orchestrator/gorc/src/commands/orchestrator/start.rs index d80da2bf1..8ae5e18db 100644 --- a/orchestrator/gorc/src/commands/orchestrator/start.rs +++ b/orchestrator/gorc/src/commands/orchestrator/start.rs @@ -120,6 +120,7 @@ impl Runnable for StartCommand { gas_price, &config.metrics.listen_addr, config.ethereum.gas_price_multiplier, + config.ethereum.gas_multiplier, config.ethereum.blocks_to_search, config.cosmos.gas_adjustment, self.orchestrator_only, diff --git a/orchestrator/gorc/src/commands/relayer/start.rs b/orchestrator/gorc/src/commands/relayer/start.rs index 7b90b19fd..b1b766979 100644 --- a/orchestrator/gorc/src/commands/relayer/start.rs +++ b/orchestrator/gorc/src/commands/relayer/start.rs @@ -82,6 +82,7 @@ impl Runnable for StartCommand { contract_address, config.ethereum.gas_price_multiplier, &mut fee_manager, + config.ethereum.gas_multiplier, ) .await; }) diff --git a/orchestrator/gorc/src/config.rs b/orchestrator/gorc/src/config.rs index 80f4e7bb0..f9f7953b5 100644 --- a/orchestrator/gorc/src/config.rs +++ b/orchestrator/gorc/src/config.rs @@ -225,6 +225,7 @@ pub struct EthereumSection { pub key_derivation_path: String, pub rpc: String, pub gas_price_multiplier: f32, + pub gas_multiplier: f32, pub blocks_to_search: u64, } @@ -234,6 +235,7 @@ impl Default for EthereumSection { key_derivation_path: "m/44'/60'/0'/0/0".to_owned(), rpc: "http://localhost:8545".to_owned(), gas_price_multiplier: 1.0f32, + gas_multiplier: 1.0f32, blocks_to_search: 5000, } } diff --git a/orchestrator/orchestrator/src/main_loop.rs b/orchestrator/orchestrator/src/main_loop.rs index 95151cde2..29f4afa27 100644 --- a/orchestrator/orchestrator/src/main_loop.rs +++ b/orchestrator/orchestrator/src/main_loop.rs @@ -58,6 +58,7 @@ pub async fn orchestrator_main_loop( gas_price: (f64, String), metrics_listen: &net::SocketAddr, eth_gas_price_multiplier: f32, + eth_gas_multiplier: f32, blocks_to_search: u64, gas_adjustment: f64, relayer_opt_out: bool, @@ -106,6 +107,7 @@ pub async fn orchestrator_main_loop( gravity_contract_address, eth_gas_price_multiplier, &mut fee_manager, + eth_gas_multiplier, ); futures::future::join5(a, b, c, d, e).await; } else { diff --git a/orchestrator/relayer/src/batch_relaying.rs b/orchestrator/relayer/src/batch_relaying.rs index dc11537bc..e948b3f0c 100644 --- a/orchestrator/relayer/src/batch_relaying.rs +++ b/orchestrator/relayer/src/batch_relaying.rs @@ -39,6 +39,7 @@ pub async fn relay_batches( timeout: Duration, eth_gas_price_multiplier: f32, fee_manager: &mut FeeManager, + eth_gas_multiplier: f32, ) { let possible_batches = get_batches_and_signatures(current_valset.clone(), grpc_client, gravity_id.clone()).await; @@ -52,6 +53,7 @@ pub async fn relay_batches( gravity_id, timeout, eth_gas_price_multiplier, + eth_gas_multiplier, possible_batches, fee_manager, ) @@ -135,6 +137,7 @@ async fn submit_batches( gravity_id: String, timeout: Duration, eth_gas_price_multiplier: f32, + eth_gas_multiplier: f32, possible_batches: HashMap>, fee_manager: &mut FeeManager, ) { @@ -202,6 +205,7 @@ async fn submit_batches( } let total_cost = total_cost.unwrap(); let gas_price_as_f32 = downcast_to_f32(cost.gas_price).unwrap(); // if the total cost isn't greater, this isn't + let gas_as_f32 = downcast_to_f32(cost.gas).unwrap(); // same as above re: total cost if fee_manager .can_send_batch( @@ -225,6 +229,8 @@ async fn submit_batches( as u128) .into(); + cost.gas = ((gas_as_f32 * eth_gas_multiplier) as u128).into(); + let res = send_eth_transaction_batch( current_valset.clone(), oldest_signed_batch, diff --git a/orchestrator/relayer/src/logic_call_relaying.rs b/orchestrator/relayer/src/logic_call_relaying.rs index 174ceaf15..d3ec492e1 100644 --- a/orchestrator/relayer/src/logic_call_relaying.rs +++ b/orchestrator/relayer/src/logic_call_relaying.rs @@ -24,6 +24,7 @@ pub async fn relay_logic_calls( gravity_id: String, timeout: Duration, eth_gas_price_multiplier: f32, + eth_gas_multiplier: f32, logic_call_skips: &mut LogicCallSkips, ) { let latest_calls = match get_latest_logic_calls(grpc_client).await { @@ -141,6 +142,7 @@ pub async fn relay_logic_calls( } let total_cost = total_cost.unwrap(); let gas_price_as_f32 = downcast_to_f32(cost.gas_price).unwrap(); // if the total cost isn't greater, this isn't + let gas_as_f32 = downcast_to_f32(cost.gas).unwrap(); // same as above re: total cost info!( "We have detected latest LogicCall {} but latest on Ethereum is {} This LogicCall is estimated to cost {} Gas / {:.4} ETH to submit", @@ -151,6 +153,7 @@ pub async fn relay_logic_calls( ); cost.gas_price = ((gas_price_as_f32 * eth_gas_price_multiplier) as u128).into(); + cost.gas = ((gas_as_f32 * eth_gas_multiplier) as u128).into(); let res = send_eth_logic_call( current_valset, diff --git a/orchestrator/relayer/src/main.rs b/orchestrator/relayer/src/main.rs index d1d37e2f3..ba96a73bd 100644 --- a/orchestrator/relayer/src/main.rs +++ b/orchestrator/relayer/src/main.rs @@ -119,6 +119,7 @@ async fn main() { gravity_contract_address, 1f32, &mut fee_manager, + 1.1f32, ) .await } diff --git a/orchestrator/relayer/src/main_loop.rs b/orchestrator/relayer/src/main_loop.rs index d09a4a7fd..1f8bbf147 100644 --- a/orchestrator/relayer/src/main_loop.rs +++ b/orchestrator/relayer/src/main_loop.rs @@ -10,6 +10,7 @@ use std::time::Duration; use tonic::transport::Channel; pub const LOOP_SPEED: Duration = Duration::from_secs(17); +pub const PENDING_TX_TIMEOUT: Duration = Duration::from_secs(120); /// This function contains the orchestrator primary loop, it is broken out of the main loop so that /// it can be called in the test runner for easier orchestration of multi-node tests @@ -20,6 +21,7 @@ pub async fn relayer_main_loop( gravity_contract_address: EthAddress, eth_gas_price_multiplier: f32, fee_manager: &mut FeeManager, + eth_gas_multiplier: f32, ) { let mut grpc_client = grpc_client; @@ -52,7 +54,9 @@ pub async fn relayer_main_loop( &mut grpc_client, gravity_contract_address, gravity_id.clone(), - LOOP_SPEED, + PENDING_TX_TIMEOUT, + eth_gas_price_multiplier, + eth_gas_multiplier, ) .await; @@ -62,9 +66,10 @@ pub async fn relayer_main_loop( &mut grpc_client, gravity_contract_address, gravity_id.clone(), - LOOP_SPEED, + PENDING_TX_TIMEOUT, eth_gas_price_multiplier, fee_manager, + eth_gas_multiplier, ) .await; @@ -74,8 +79,9 @@ pub async fn relayer_main_loop( &mut grpc_client, gravity_contract_address, gravity_id.clone(), - LOOP_SPEED, + PENDING_TX_TIMEOUT, eth_gas_price_multiplier, + eth_gas_multiplier, &mut logic_call_skips, ) .await; diff --git a/orchestrator/relayer/src/valset_relaying.rs b/orchestrator/relayer/src/valset_relaying.rs index 0043b5873..ad47fa548 100644 --- a/orchestrator/relayer/src/valset_relaying.rs +++ b/orchestrator/relayer/src/valset_relaying.rs @@ -24,6 +24,8 @@ pub async fn relay_valsets( gravity_contract_address: EthAddress, gravity_id: String, timeout: Duration, + eth_gas_price_multiplier: f32, + eth_gas_multiplier: f32, ) { // we have to start with the current ethereum valset, we need to know what's currently // in the contract in order to determine if a new validator set is valid. @@ -162,7 +164,7 @@ pub async fn relay_valsets( ); return; } - let cost = cost.unwrap(); + let mut cost = cost.unwrap(); let total_cost = downcast_to_f32(cost.get_total()); if total_cost.is_none() { error!( @@ -172,6 +174,8 @@ pub async fn relay_valsets( return; } let total_cost = total_cost.unwrap(); + let gas_price_as_f32 = downcast_to_f32(cost.gas_price).unwrap(); // if the total cost isn't greater, this isn't + let gas_as_f32 = downcast_to_f32(cost.gas).unwrap(); // same as above re: total cost info!( "We have detected latest valset {} but latest on Ethereum is {} This valset is estimated to cost {} Gas / {:.4} ETH to submit", @@ -180,6 +184,9 @@ pub async fn relay_valsets( total_cost / one_eth_f32() ); + cost.gas_price = ((gas_price_as_f32 * eth_gas_price_multiplier) as u128).into(); + cost.gas = ((gas_as_f32 * eth_gas_multiplier) as u128).into(); + let relay_response = send_eth_valset_update( latest_cosmos_valset.clone(), current_eth_valset.clone(),