-
Notifications
You must be signed in to change notification settings - Fork 430
/
GasPriceTxComparerHelper.cs
33 lines (27 loc) · 1.15 KB
/
GasPriceTxComparerHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using Nethermind.Core;
using Nethermind.Int256;
namespace Nethermind.Consensus.Comparers
{
public static class GasPriceTxComparerHelper
{
public static int Compare(Transaction? x, Transaction? y, in UInt256 baseFee, bool isEip1559Enabled)
{
if (ReferenceEquals(x, y)) return 0;
if (y is null) return 1;
if (x is null) return -1;
// EIP1559 changed the way we're sorting transactions. The transaction with a higher miner tip should go first
if (isEip1559Enabled)
{
UInt256 xGasPrice = UInt256.Min(x.MaxFeePerGas, x.MaxPriorityFeePerGas + baseFee);
UInt256 yGasPrice = UInt256.Min(y.MaxFeePerGas, y.MaxPriorityFeePerGas + baseFee);
if (xGasPrice < yGasPrice) return 1;
if (xGasPrice > yGasPrice) return -1;
return y.MaxFeePerGas.CompareTo(x.MaxFeePerGas);
}
// the old way of sorting transactions
return y.GasPrice.CompareTo(x.GasPrice);
}
}
}