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

feat(solana): add support for priority fees #34

Closed
wants to merge 5 commits into from

Conversation

gabrielKerekes
Copy link
Collaborator

Fixes trezor#11518.

Default priority fee should 5000 lamports - 50_000 compute units limit * 100_000 micro-lamports per unit. If the network is congested the fee (namely the price per unit) should be even higher based on the getRecentPrioritizationFees RPC call.

I haven't yet been able to test this properly with a congested network (i.e. transaction passes on this branch but not on production). I'll see if I can do that tonight as it seems the network activity is highest in the evenings.

@gabrielKerekes gabrielKerekes self-assigned this Mar 21, 2024
@memoriesadrift memoriesadrift self-requested a review March 21, 2024 14:07
Copy link
Collaborator

@memoriesadrift memoriesadrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes, otherwise LGTM

import BigNumber from 'bignumber.js';

const DEFAULT_COMPUTE_UNIT_PRICE = 100_000; // micro-lamports, value taken from other wallets
const DEFAULT_COMPUTE_UNIT_LIMIT = 50_000; // sending tokens with token account creation requires ~28K units
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this is fine, but while doing some reading I came across this article where solana recommends "To best optimize our transaction, request exactly CU with the Compute Budget Program when adding additional priority fees."
I'm not sure what the reason is behind that as I think only as many CU as needed are used anyway.
Could you quickly test this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think only as many CU as needed are used anyway

If you reserve 500K CUs, you pay for 500K CUs even if your transaction only uses 500.

Thanks for the comment though, because it pushed to revisit this and in the end I also implemented transaction simulation into the priority fee computations and so the limit will be exactly what the transaction needs + 20%. This article mentions a buffer of 10%, so we add 20% just to be sure.

However I'm not 100% convinced about this approach since e.g. SOL transfer now adds 18 lamports as fee i.e. the final fee is 5018 lamports instead of 5000 and I'm not entirely sure that's enough :D I'll discuss with Trezor guys, the previous approach is still implemented if we drop the last two commits.

Comment on lines 27 to 55
const computeUnitPrice = new BigNumber(
Math.max(networkPriorityFee, DEFAULT_COMPUTE_UNIT_PRICE),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to Math.min here to save the user fees if the network isn't congested?
i.e. if all the recent priority fees are 0, as is often the case on devnet, I'd expect to not have to pay any priority fees.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we want to always set a priority fee just to be sure the transactions go through. Same is true for other wallets as well.

Comment on lines +11 to +30
if (result.value == null) {
throw new Error('Could not estimate fee for transaction.');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this throws when the value is null, the priority fee will never get calculated in blockchainEstimateFee. Do you think that should happen or do we want to add a default priority fee on top in that case too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a default priority fee configured which will be used if this throws. I'm not sure exactly how it works in the background but it does.

@gabrielKerekes gabrielKerekes force-pushed the feat/solana-priority-fees branch 3 times, most recently from e5a6ccb to f7c2e31 Compare March 22, 2024 12:31
Combine `signatureSubscribe` and `getSignatureStatus` when confirming transactions. This resolves the issue with Quicknode not sending a signature update event. Transaction will confirm if either a signature update event is received or if the periodic `getSignatureStatus` confirms the transaction as `finalized`.
@gabrielKerekes gabrielKerekes force-pushed the feat/solana-priority-fees branch from 47c5763 to ad45b89 Compare March 26, 2024 13:25
@gabrielKerekes
Copy link
Collaborator Author

Merged via trezor#11703.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Solana: Include priority fee in TX
2 participants