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

Reorg & Escalation testing #11

Merged
merged 6 commits into from
Dec 27, 2023
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
38 changes: 0 additions & 38 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ url = "2.4.1"
uuid = { version = "0.8", features = ["v4"] }

[dev-dependencies]
fake-rpc = { path = "crates/fake-rpc" }
indoc = "2.0.3"
test-case = "3.1.0"

Expand Down
52 changes: 0 additions & 52 deletions crates/fake-rpc/Cargo.toml

This file was deleted.

153 changes: 0 additions & 153 deletions crates/fake-rpc/src/lib.rs

This file was deleted.

30 changes: 0 additions & 30 deletions crates/fake-rpc/src/main.rs

This file was deleted.

31 changes: 1 addition & 30 deletions src/broadcast_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ethers::types::{Eip1559TransactionRequest, U256};
use ethers::types::U256;
use eyre::ContextCompat;

use self::gas_estimation::FeesEstimate;
Expand All @@ -19,35 +19,6 @@ pub fn calculate_gas_fees_from_estimates(
(max_fee_per_gas, max_priority_fee_per_gas)
}

pub fn escalate_priority_fee(
max_base_fee_per_gas: U256,
max_network_fee_per_gas: U256,
current_max_priority_fee_per_gas: U256,
escalation_count: usize,
tx: &mut Eip1559TransactionRequest,
) {
// Min increase of 20% on the priority fee required for a replacement tx
let increased_gas_price_percentage =
U256::from(100 + (10 * (1 + escalation_count)));

let factor = U256::from(100);

let new_max_priority_fee_per_gas = current_max_priority_fee_per_gas
* increased_gas_price_percentage
/ factor;

let new_max_priority_fee_per_gas =
std::cmp::min(new_max_priority_fee_per_gas, max_network_fee_per_gas);

let new_max_fee_per_gas =
max_base_fee_per_gas + new_max_priority_fee_per_gas;
let new_max_fee_per_gas =
std::cmp::min(new_max_fee_per_gas, max_network_fee_per_gas);

tx.max_fee_per_gas = Some(new_max_fee_per_gas);
tx.max_priority_fee_per_gas = Some(new_max_priority_fee_per_gas);
}

pub async fn should_send_transaction(
app: &App,
relayer_id: &str,
Expand Down
29 changes: 28 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::server::routes::network::NewNetworkInfo;
use crate::server::routes::relayer::{
CreateApiKeyResponse, CreateRelayerRequest, CreateRelayerResponse,
};
use crate::server::routes::transaction::{SendTxRequest, SendTxResponse};
use crate::server::routes::transaction::{
GetTxResponse, SendTxRequest, SendTxResponse,
};

pub struct TxSitterClient {
client: reqwest::Client,
Expand Down Expand Up @@ -43,6 +45,17 @@ impl TxSitterClient {
Ok(response.json().await?)
}

async fn json_get<R>(&self, url: &str) -> eyre::Result<R>
where
R: serde::de::DeserializeOwned,
{
let response = self.client.get(url).send().await?;

let response = Self::validate_response(response).await?;

Ok(response.json().await?)
}

async fn validate_response(response: Response) -> eyre::Result<Response> {
if !response.status().is_success() {
let body = response.text().await?;
Expand Down Expand Up @@ -77,6 +90,20 @@ impl TxSitterClient {
.await
}

pub async fn get_tx(
&self,
api_key: &ApiKey,
tx_id: &str,
) -> eyre::Result<GetTxResponse> {
self.json_get(&format!(
"{}/1/api/{api_key}/tx/{tx_id}",
self.url,
api_key = api_key,
tx_id = tx_id
))
.await
}

pub async fn create_network(
&self,
chain_id: u64,
Expand Down
Loading