Skip to content

Commit

Permalink
Merge pull request #432 from PeggyJV/bolten/legacy-logic-calls
Browse files Browse the repository at this point in the history
Specify gas limit multiplier for relaying
  • Loading branch information
EricBolten authored Jul 13, 2022
2 parents 2099d7a + 95b0eb6 commit 2e36426
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 8 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 @@ -108,6 +108,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
2 changes: 2 additions & 0 deletions orchestrator/gorc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 @@ -83,6 +84,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 @@ -55,6 +55,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 @@ -98,6 +99,7 @@ pub async fn orchestrator_main_loop(
grpc_client.clone(),
gravity_contract_address,
eth_gas_price_multiplier,
eth_gas_multiplier,
);
futures::future::join5(a, b, c, d, e).await;
} else {
Expand Down
5 changes: 5 additions & 0 deletions orchestrator/relayer/src/batch_relaying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn relay_batches(
gravity_id: String,
timeout: Duration,
eth_gas_price_multiplier: f32,
eth_gas_multiplier: f32,
) {
let possible_batches =
get_batches_and_signatures(current_valset.clone(), grpc_client, gravity_id.clone()).await;
Expand All @@ -50,6 +51,7 @@ pub async fn relay_batches(
gravity_id,
timeout,
eth_gas_price_multiplier,
eth_gas_multiplier,
possible_batches,
)
.await;
Expand Down Expand Up @@ -132,6 +134,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>>,
) {
let ethereum_block_height = if let Ok(bn) = eth_client.get_block_number().await {
Expand Down Expand Up @@ -198,6 +201,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

info!(
"We have detected latest batch {} but latest on Ethereum is {} This batch is estimated to cost {} Gas / {:.4} ETH to submit",
Expand All @@ -208,6 +212,7 @@ async fn submit_batches(
);

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_transaction_batch(
current_valset.clone(),
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
3 changes: 2 additions & 1 deletion orchestrator/relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ async fn main() {
eth_client,
connections.grpc.unwrap(),
gravity_contract_address,
1f32,
1.1f32,
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 @@ -9,6 +9,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 @@ -18,6 +19,7 @@ pub async fn relayer_main_loop(
grpc_client: GravityQueryClient<Channel>,
gravity_contract_address: EthAddress,
eth_gas_price_multiplier: f32,
eth_gas_multiplier: f32,
) {
let mut grpc_client = grpc_client;
let gravity_id = get_gravity_id(gravity_contract_address, eth_client.clone()).await;
Expand Down Expand Up @@ -49,7 +51,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 @@ -59,8 +63,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 @@ -70,8 +75,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 2e36426

Please sign in to comment.