gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
929 stars 264 forks source link

Priority Fee during this congested period. #193

Closed metarsit closed 7 months ago

metarsit commented 7 months ago

Context (TLDR;)

Current code

    limit := computebudget.NewSetComputeUnitLimitInstruction(500000).Build()
    feesInit := computebudget.NewSetComputeUnitPriceInstructionBuilder().
        SetMicroLamports(3000).Build()

    trf := system.NewTransferInstruction(
        bigAmt.Uint64(),
        accountFrom.PublicKey(),
        accountTo,
    ).Build()

    log.Info("Creating Transaction")
    tx, err := solana.NewTransactionBuilder().
        AddInstruction(feesInit).
        AddInstruction(limit).
        AddInstruction(trf).
        SetRecentBlockHash(recent).
        SetFeePayer(accountFrom.PublicKey()).
        Build()
    if err != nil {
        return errors.Wrap(err, "unable to create new transaction")
    }

Some help I may need

  1. Did I use the wrong value for the limit and fee? (I followed #166)
  2. Is there a better way to build this transaction before signing and sending it?

I really appreciate any help you can provide. I am pretty new to this and hope I can get a kickstart on this. Thank you very much.

0xvbetsun commented 7 months ago

@metarsit IMO official doc and Helius article are the best for kicking-off.

Your code looks good to me. You're trying to set the prioritization fee as 6_500 Lamports in your example.

500_000 * 3_000  * 0.000001 + 5_000 = 6_500

where: 500_000 - compute unit limit 3_000 - compute unit price 0.000001 - convert microlLamports to Lamports 5_000 - base fee in Lamports

If you can't land your tx with 6_500 Lamports, current commissions may be higher due to congestion.

I'd suggest using getrecentprioritizationfees RPC method to understand the current market condition. And here is an example of the call in this SDK

metarsit commented 7 months ago

Thank you for a great share on the information @0xvbetsun! I understand this a bit better now. However, I have tried to set even crazier fee but the success rate is still very low. Is there any other way to improve the success rate?

0xvbetsun commented 7 months ago

You're welcome, @metarsit I don't, actually, have a super-secret technique to achieve a 100% landing rate. Just a well-known recommendations:

Here is a page from Tritone One with those recommendations

Also, you can get some inspiration for how to send tx directly to the current leader from Helius Atlas

metarsit commented 7 months ago

Thanks both! I will apply these changes! ❤️