kevinheavey / solders

A high-performance Python toolkit for Solana, written in Rust
https://kevinheavey.github.io/solders/
Apache License 2.0
232 stars 26 forks source link

Not enough signers when setting compute units #83

Closed fakebl0ck closed 7 months ago

fakebl0ck commented 8 months ago

Getting this error when trying to set compute units: solders.SignerError: not enough signers

Simple code example:

...

transaction = Transaction()
transaction.add(set_compute_unit_limit(1_000_000))
transaction.add(set_compute_unit_price(1_000))
transaction.add(transfer(TransferParams(
    from_pubkey=sender.pubkey(),
    to_pubkey=receiver.pubkey(),
    lamports=int(0.001*LAMPORT_PER_SOL))
    ))

signature = client.send_transaction(transaction, sender)

There is no error when removing the 2 instructions for setting compute units.

kevinheavey commented 8 months ago

Can you check if you get the same error when using solders.transaction.Transaction?

fakebl0ck commented 8 months ago

Haven't tried with solders.transaction.Transaction but found the issue is gone when explicitly setting the fee payer during the construction of the Transaction object


transaction = Transaction(fee_payer=sender)
transaction.add(set_compute_unit_limit(1_000_000))
transaction.add(set_compute_unit_price(1_000))
transaction.add(transfer(TransferParams(
    from_pubkey=sender.pubkey(),
    to_pubkey=receiver.pubkey(),
    lamports=int(0.001*LAMPORT_PER_SOL))
    ))

signature = client.send_transaction(transaction, sender)

It looks like when not explicitly setting the fee_payer, solana.transaction grabs the first account of the message to use as the fee payer, that's why it was working before adding the instructions ahead of the transfer.

FB

kevinheavey commented 7 months ago

My point was I don't think this is a Solders issue, Solders is just where the error bubbles up

992capybara commented 7 months ago

Also had this issue. Fixed it by @kevinheavey 's suggestion to use Solder's transaction class instead of solana's

If using solana.transaction,


from solana.transaction import Transaction
from solders.message import Message
from solders.transaction import Transaction as SoldersTransaction

blockhash = client.get_latest_blockhash().value.blockhash # a solana client
sender = Keypair.from_base58_string("") # some bs58 string
messages = Message([
              set_compute_unit_price(1_000), # priority fee
              transfer(TransferParams(
                  from_pubkey=sender.pubkey(),
                  to_pubkey=receiver,
                  lamports=int(txn.amount) # amt of lamports to transfer
              ))
], sender.pubkey())
solders_txn = SoldersTransaction([sender], messages, blockhash)
tx = Transaction().from_solders(solders_txn)
tx_resp = client.send_transaction(tx, sender)```
xandyxor commented 7 months ago

Also had this issue. Fixed it by @kevinheavey 's suggestion to use Solder's transaction class instead of solana's

If using solana.transaction,

from solana.transaction import Transaction
from solders.message import Message
from solders.transaction import Transaction as SoldersTransaction

blockhash = client.get_latest_blockhash().value.blockhash # a solana client
sender = Keypair.from_base58_string("") # some bs58 string
messages = Message([
              set_compute_unit_price(1_000), # priority fee
              transfer(TransferParams(
                  from_pubkey=sender.pubkey(),
                  to_pubkey=receiver,
                  lamports=int(txn.amount) # amt of lamports to transfer
              ))
], sender.pubkey())
solders_txn = SoldersTransaction([sender], messages, blockhash)
tx = Transaction().from_solders(solders_txn)
tx_resp = client.send_transaction(tx, sender)```

AttributeError: 'Transaction' object has no attribute 'from_solders'