0

I wanted to use the getRecentPrioritizationFees Solana JSON-RPC method to compute a prioritization fee estimation.

According to the Solana documentation, this method has an accounts array parameter that, according to their documents, means the following:

If this parameter is provided, the response will reflect a fee to land a transaction locking all of the provided accounts as writable.

I tried this out via the https://api.mainnet-beta.solana.com cluster but got only 0 as fee values as a result when sending an empty array. Only when trying to use some accounts as parameter I could get some non-0 responses.

Based on that, I have two questions:

  1. Will I always get 0-valued fees when passing an empty array? Would it be possible that there is a bug that always returns 0?
  2. What exactly does it mean, from the method's documentation, that "the response will reflect a fee to land a transaction locking all of the provided accounts as writable."? Does this mean that the node will return data by looking at its priority fee cache using these accounts as keys?

1 Answer 1

1

The implementation can be a bit confusing, but it's quite short, so here's the code:

    pub fn get_prioritization_fees(&self, account_keys: &[Pubkey]) -> HashMap<Slot, u64> {
        self.cache
            .read()
            .unwrap()
            .iter()
            .filter_map(|(slot, prioritization_fee)| {
                let prioritization_fee_read = prioritization_fee.lock().unwrap();
                prioritization_fee_read.is_finalized().then(|| {
                    let mut fee = prioritization_fee_read
                        .get_min_transaction_fee()
                        .unwrap_or_default();
                    for account_key in account_keys {
                        if let Some(account_fee) =
                            prioritization_fee_read.get_writable_account_fee(account_key)
                        {
                            fee = std::cmp::max(fee, account_fee);
                        }
                    }
                    Some((*slot, fee))
                })
            })
            .flatten()
            .collect()
    }

To answer your questions:

  1. Because of let mut fee = prioritization_fee_read.get_min_transaction_fee().unwrap_or_default();, with an empty array, you'll at least the get minimal transaction fee that landed on the network.

  2. Yep that's exactly it! Right now it's just using a simple max of all fees, but you could imagine this getting more sophisticated as transactions lock many accounts.

Here's the code for reference: https://github.com/solana-labs/solana/blob/13107b4eb69120f672896f48d77affa9df45e8b4/runtime/src/prioritization_fee_cache.rs#L364

6
  • Thanks for answering! Yeah it felt clearer once I looked at the code. I believe the docs could have some indication that there is a minimization happening as a result of this. Also, didn't you mean "min" instead of "max" in "Right now it's just using a simple max of all fees" ? Commented Mar 13, 2023 at 12:36
  • Yeah it is pretty confusing... for "max", I was referring to the accounts under consideration, ie the line fee = std::cmp::max(fee, account_fee);
    – Jon C
    Commented Mar 14, 2023 at 13:09
  • Aaaah yeah, I forgotten about that. So that makes me more confused regarding this :D. It first gets the minimum prioritization fee seen at the given slot, but then when checking each account individually, it performs a maximization operation? Is this description correct? If it is, why would it do it? Commented Mar 15, 2023 at 14:18
  • 1
    Yep that's exactly it. The endpoint wants to tell you how much priority fee you need at a minimum to land your transaction. You pass all of the accounts that you want to lock, and it fetches the minimums for all of those accounts. If you want to land your transaction, the minimum that you need to pay is the maximum of all of those amounts
    – Jon C
    Commented Mar 15, 2023 at 20:04
  • Aaah great explanation, that makes more sense now. Thanks again! Commented Mar 16, 2023 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.