Skip to content

Commit

Permalink
specify gas limit multiplier for relaying (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy authored Jul 14, 2022
1 parent 742da80 commit 25acdf7
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 7 deletions.
3 changes: 2 additions & 1 deletion orchestrator/ethereum_gravity/src/logic_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion orchestrator/ethereum_gravity/src/submit_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion orchestrator/ethereum_gravity/src/valset_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions orchestrator/gorc/src/commands/orchestrator/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions orchestrator/gorc/src/commands/relayer/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl Runnable for StartCommand {
contract_address,
config.ethereum.gas_price_multiplier,
&mut fee_manager,
config.ethereum.gas_multiplier,
)
.await;
})
Expand Down
2 changes: 2 additions & 0 deletions orchestrator/gorc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions orchestrator/orchestrator/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions orchestrator/relayer/src/batch_relaying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +53,7 @@ pub async fn relay_batches(
gravity_id,
timeout,
eth_gas_price_multiplier,
eth_gas_multiplier,
possible_batches,
fee_manager,
)
Expand Down Expand Up @@ -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<EthAddress, Vec<SubmittableBatch>>,
fee_manager: &mut FeeManager,
) {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions orchestrator/relayer/src/logic_call_relaying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions orchestrator/relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async fn main() {
gravity_contract_address,
1f32,
&mut fee_manager,
1.1f32,
)
.await
}
12 changes: 9 additions & 3 deletions orchestrator/relayer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion orchestrator/relayer/src/valset_relaying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!(
Expand All @@ -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",
Expand All @@ -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(),
Expand Down

0 comments on commit 25acdf7

Please sign in to comment.