When I use the method of setting the compute unit price of a transaction message for example a token swap, it sets the priority fee as intended. But when I try to set this compute unit price for a simple transfer message, it doesn't seem to utilize the priority fees. I am not having issues with the transfer itself, it executes perfectly fine and very quickly, but I don't really seem to understand why it doesn't utilize it. I understand that priority fees are based on the number of instructions, compute limit per instruction, etc. Is it because it is a system program instruction? I am just looking for some insight at why this happens.
Code below is just for context:
recentBlockhash = ((await w3.get_latest_blockhash(commitment=Commitment("confirmed"))).value).blockhash
priorityFee = set_compute_unit_price(gas)
amount = int(amount * 10 ** 9)
transactionMessage = Message(
[
transfer(
TransferParams(
from_pubkey=userKeypair.pubkey(),
to_pubkey=Pubkey.from_string(toAddress),
lamports=amount,
)
)
],
userKeypair.pubkey(),
)
accountKeys = transactionMessage.account_keys
rawInstructions = transactionMessage.instructions
newInstruction = CompiledInstruction(
program_id_index=len(accountKeys),
data=priorityFee.data,
accounts=rawInstructions[0].accounts,
)
rawInstructions.append(newInstruction)
newTransactionMessage = Message.new_with_compiled_instructions(
num_required_signatures=transactionMessage.header.num_required_signatures,
num_readonly_signed_accounts=transactionMessage.header.num_readonly_signed_accounts,
num_readonly_unsigned_accounts=transactionMessage.header.num_readonly_unsigned_accounts,
account_keys=accountKeys,
recent_blockhash=recentBlockhash,
instructions=transactionMessage.instructions,
)
userSignature = userKeypair.sign_message(message.to_bytes_versioned(newTransactionMessage))
signedTransaction = VersionedTransaction.populate(newTransactionMessage, [userSignature])
return signedTransaction