metaplex-foundation / umi-hotline

2 stars 0 forks source link

encoding overruns uint8 array when signing all transactions with walletAdapter with UMI #8

Closed joefitter closed 1 year ago

joefitter commented 1 year ago

Umi version

0.7.5

Code

function getUmiChunks(instructionSet: TransactionBuilder[]) {
    return chunkBy(instructionSet, (ch: TransactionBuilder[], i: number) => {
      if (!instructionSet[i + 1]){
        return true;
      }

      const t = transactionBuilder()
        .add(flatten(ch))
        .add(flatten(instructionSet[i + 1]))

      return !t.fitsInOneTransaction(umi);
    })
  }

const instructions = toSend.map((item: Metadata) => {
  const inst = transferV1(umi, {
    destinationOwner: publicKey(recipient),
    mint: fromWeb3JsPublicKey(item.mintAddress),
    tokenStandard: item.tokenStandard!
  })

  return inst
})

const chunks = getUmiChunks(instructions);
const txns = await Promise.all(chunks.map(async builders => {
  const txn = builders.reduce((t, item) => t.add(item), transactionBuilder())
  return txn.buildWithLatestBlockhash(umi)
}))

await umi.identity.signAllTransactions(txns) // error

Error

WalletSignTransactionError: encoding overruns Uint8Array
    at StandardWalletAdapter._StandardWalletAdapter_signAllTransactions [as signAllTransactions] (adapter.js:327:1)
    at Object.eval [as signAllTransactions] (WalletProviderBase.js:168:1)
    at Object.signAllTransactions (createSignerFromWalletAdapter.mjs:28:1)
    at eval (index.tsx:239:26)
    at step (tslib.es6.js:147:1)
    at Object.eval [as next] (tslib.es6.js:128:46)
    at asyncGeneratorStep (_async_to_generator.mjs:3:1)
    at _next (_async_to_generator.mjs:25:1)
joefitter commented 1 year ago

Hi - this is when using the walletAdpater like so:

const wallet = useWallet()
const umi = createUmi(endpoint, rpcOptions)
    .use(walletAdapterIdentity(wallet))
    .use(mplTokenMetadata())
joefitter commented 1 year ago

Further to this - it appears the transactionBuilder.isSmallEnough getter returns true for the instructions although when built they result in a transaction that's too large.

Does this method take signers, blockhash etc into account?

lorisleiva commented 1 year ago

Hi there,

The encoding overruns UInt8Array error occurs because one of the transaction is too large so your latest comment is very relevant.

The methods that compute transaction sizes compile and serialise transactions as if they were going to be sent which means they do take everything into account including blockhash and signers.

All I can think of is you are setting the blockhash after splitting them by transaction size so there could be a discrepancy here. Although the method that compute the size should allocate a mock blockhash when missing to accommodate for that.

Also note that there is a unsafeSplitByTransactionSize on the transaction builder that does more or less what you are trying to achieve.

lorisleiva commented 1 year ago

Hey Joe, I'm closing this since it's been a while but feel free to reopen if/when necessary. 🙏