Browse Source

cli: Fix priority fee calculation causing panic on localnet (#3318)

acheron 11 months ago
parent
commit
b6724d2bcb
2 changed files with 5 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 4 0
      cli/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -86,6 +86,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - ts: Update `engines.node` to `>= 17` ([#3301](https://github.com/coral-xyz/anchor/pull/3301)).
 - ts: Update `engines.node` to `>= 17` ([#3301](https://github.com/coral-xyz/anchor/pull/3301)).
 - cli: Use OS-agnostic paths ([#3307](https://github.com/coral-xyz/anchor/pull/3307)).
 - cli: Use OS-agnostic paths ([#3307](https://github.com/coral-xyz/anchor/pull/3307)).
 - avm: Use `rustc 1.79.0` when installing versions older than v0.31 ([#3315](https://github.com/coral-xyz/anchor/pull/3315)).
 - avm: Use `rustc 1.79.0` when installing versions older than v0.31 ([#3315](https://github.com/coral-xyz/anchor/pull/3315)).
+- cli: Fix priority fee calculation causing panic on localnet ([#3318](https://github.com/coral-xyz/anchor/pull/3318)).
 
 
 ### Breaking
 ### Breaking
 
 

+ 4 - 0
cli/src/lib.rs

@@ -4726,6 +4726,10 @@ fn get_recommended_micro_lamport_fee(client: &RpcClient, priority_fee: Option<u6
     }
     }
 
 
     let mut fees = client.get_recent_prioritization_fees(&[])?;
     let mut fees = client.get_recent_prioritization_fees(&[])?;
+    if fees.is_empty() {
+        // Fees may be empty, e.g. on localnet
+        return Ok(0);
+    }
 
 
     // Get the median fee from the most recent recent 150 slots' prioritization fee
     // Get the median fee from the most recent recent 150 slots' prioritization fee
     fees.sort_unstable_by_key(|fee| fee.prioritization_fee);
     fees.sort_unstable_by_key(|fee| fee.prioritization_fee);