Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Nov 12, 2024
1 parent f9754aa commit 7a8ea78
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
23 changes: 10 additions & 13 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,17 @@ impl Transaction for TxEip1559 {
}

fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
match base_fee {
None => self.max_fee_per_gas,
Some(base_fee) => {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
base_fee.map_or(self.max_fee_per_gas, |base_fee| {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
}
})
}

fn is_dynamic_fee(&self) -> bool {
Expand Down
23 changes: 10 additions & 13 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,17 @@ impl Transaction for TxEip4844 {
}

fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
match base_fee {
None => self.max_fee_per_gas,
Some(base_fee) => {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
base_fee.map_or(self.max_fee_per_gas, |base_fee| {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
}
})
}

fn is_dynamic_fee(&self) -> bool {
Expand Down
23 changes: 10 additions & 13 deletions crates/consensus/src/transaction/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,17 @@ impl Transaction for TxEip7702 {
}

fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
match base_fee {
None => self.max_fee_per_gas,
Some(base_fee) => {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
base_fee.map_or(self.max_fee_per_gas, |base_fee| {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let tip = self.max_fee_per_gas.saturating_sub(base_fee as u128);
if tip > self.max_priority_fee_per_gas {
self.max_priority_fee_per_gas + base_fee as u128
} else {
// otherwise return the max fee per gas
self.max_fee_per_gas
}
}
})
}

fn is_dynamic_fee(&self) -> bool {
Expand Down
33 changes: 15 additions & 18 deletions crates/network/src/any/unknowns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,22 @@ impl alloy_consensus::Transaction for UnknownTypedTransaction {
return gas_price;
}

match base_fee {
None => self.max_fee_per_gas(),
Some(base_fee) => {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let max_fee = self.max_fee_per_gas();
if max_fee == 0 {
return 0;
}
let Some(max_prio_fee) = self.max_priority_fee_per_gas() else { return max_fee };
let tip = max_fee.saturating_sub(base_fee as u128);
if tip > max_prio_fee {
max_prio_fee + base_fee as u128
} else {
// otherwise return the max fee per gas
max_fee
}
base_fee.map_or(self.max_fee_per_gas(), |base_fee| {
// if the tip is greater than the max priority fee per gas, set it to the max
// priority fee per gas + base fee
let max_fee = self.max_fee_per_gas();
if max_fee == 0 {
return 0;
}
}
let Some(max_prio_fee) = self.max_priority_fee_per_gas() else { return max_fee };
let tip = max_fee.saturating_sub(base_fee as u128);
if tip > max_prio_fee {
max_prio_fee + base_fee as u128
} else {
// otherwise return the max fee per gas
max_fee
}
})
}

fn is_dynamic_fee(&self) -> bool {
Expand Down

0 comments on commit 7a8ea78

Please sign in to comment.