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

FileAppendTransaction: transaction did not have exactly one node ID set or list is locked if setNodeAccountIds is specify. #2168

Closed
RaphaelMessian opened this issue Feb 26, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@RaphaelMessian
Copy link

RaphaelMessian commented Feb 26, 2024

Description

When creating a large fileId to deploy a contract I get the error "transaction did not have exactly one node ID set".
If I try to add a setNodeAccountIds to the transaction I get a new error "list is locked".
This problem occurs on FileAppendTransaction and I also get this error when trying to set a nodeAccountIds on a fileCreateTransaction.

Steps to reproduce

This is the code i'm running using React and the hashgraph js sdk.

          onClick={async () => {
          let helloHedera = require("../MyNFT.json");
          const bytecode = helloHedera.bytecode;
          let byteCodeArray = [];
          for (let i = 0; i < Math.trunc(bytecode.length / 2048); i ++) {
            byteCodeArray.push(bytecode.substring(i * 2048, (i + 1) * 2048));
          }
          const signer = hc.getSigner(AccountId.fromString(fromAccountId));
          const fileCreateTx = await new FileCreateTransaction()
            .setContents(byteCodeArray[0])
            //.setNodeAccountIds([AccountId.fromString("0.0.3")])
            .freezeWithSigner(signer)

          const executeFileTx = await fileCreateTx.executeWithSigner(signer);
          const receipt = await executeFileTx.getReceiptWithSigner(signer);
          const fileId = receipt.fileId;
          console.log("fileId", fileId);

          const nodeId = [];
          nodeId.push(new AccountId(3));

          let i = 1;
          while (i < byteCodeArray.length) {
            const fileAppendTx = await new FileAppendTransaction()
              .setFileId(fileId as any)
              .setContents(byteCodeArray[i])
              //.setNodeAccountIds(nodeId)
              .setMaxTransactionFee(new Hbar(2))
              .freezeWithSigner(signer);
            const signAppendTx = await fileAppendTx.signWithSigner(signer);
            const executeAppendTx = await signAppendTx.executeWithSigner(signer);
            const appendFileReceipt = await executeAppendTx.getReceiptWithSigner(signer);
            console.log("appendFileReceipt", appendFileReceipt.status.toString());
            i++;
          }
        }}

Additional context

No response

Hedera network

testnet

Version

v2.40.0

Operating system

None

@RaphaelMessian RaphaelMessian added the bug Something isn't working label Feb 26, 2024
@RaphaelMessian RaphaelMessian changed the title FileAppendTransaction: transaction did not have exactly one node ID set and list is locked if setNodeAccountIds is specify. FileAppendTransaction: transaction did not have exactly one node ID set or list is locked if setNodeAccountIds is specify. Feb 26, 2024
@svetoslav-nikol0v
Copy link
Contributor

svetoslav-nikol0v commented Mar 1, 2024

Hello RaphaelMessian,

We've tried to reproduce the issue using the snippet below in a new node project but we couldn't:

What we've done:

  1. Generated a large bytecode enough to be chunked, and executed the example but we got UNAUTHORIZED error
  2. Then we used setKeys() method in FileCreateTransaction to set the keys which must sign any transactions modifying this file. This is required.
  3. Then we executed the example again and then it passed successfully
  4. Also we used setNodeAccountIds() method to set different number of node account ids and again it passed successfully

The bytecode that we used was chunked to 29 chunks. You can try the example below with your bytecode and see if it will be appended correctly.

The difference between your and our example is the signer. You're getting the signer from hashconnect, and we're setting it locally with Wallet. Which makes me think the problem comes from there but we'll need more time to investigate.

import {
      AccountId,
      PrivateKey,
      Wallet,
      LocalProvider,
      FileAppendTransaction,
      FileCreateTransaction,
      Hbar,
  } from '@hashgraph/sdk';
  
  import dotenv from 'dotenv';
  
  dotenv.config();
  
  async function main() {
      // Ensure required environment variables are available
      if (
              !process.env.OPERATOR_ID ||
              !process.env.OPERATOR_KEY ||
              !process.env.HEDERA_NETWORK
          ) {
          throw new Error('Please set required keys in .env file.');
      }
  
      // Configure client using environment variables
      const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
      const operatorKey = PrivateKey.fromStringDer(process.env.OPERATOR_KEY);
      const wallet = new Wallet(
          operatorId,
          operatorKey,
          new LocalProvider()
      )

    let bytecode = ''
    let byteCodeArray = [];
    for (let i = 0; i < Math.trunc(bytecode.length / 2048); i ++) {
        byteCodeArray.push(bytecode.substring(i * 2048, (i + 1) * 2048));
    }

    const fileCreateTx = await new FileCreateTransaction()
        .setKeys([wallet.getAccountKey()])
        .setContents(byteCodeArray[0])
        .freezeWithSigner(wallet)

    const executeFileTx = await fileCreateTx.executeWithSigner(wallet);
    const receipt = await executeFileTx.getReceiptWithSigner(wallet);
    const fileId = receipt.fileId;

    // const nodesIDs = [ new AccountId(3) ];

    let i = 1;
    while (i < byteCodeArray.length) {
        const fileAppendTx = await new FileAppendTransaction()
            .setFileId(fileId)
            // .setNodeAccountIds(nodesIDs)
            .setContents(byteCodeArray[i])
            .setMaxTransactionFee(new Hbar(2))
            .freezeWithSigner(wallet);
        const signAppendTx = await fileAppendTx.signWithSigner(wallet);
        const executeAppendTx = await signAppendTx.executeWithSigner(wallet);
        const appendFileReceipt = await executeAppendTx.getReceiptWithSigner(wallet);
        console.log("appendFileReceipt", appendFileReceipt.status.toString());
        i++;
    }

}

main();

@agadzhalov agadzhalov self-assigned this Mar 5, 2024
@SimiHunjan
Copy link
Contributor

@RaphaelMessian is this still an issue or can we close?

@RaphaelMessian
Copy link
Author

RaphaelMessian commented Apr 16, 2024

@SimiHunjan I don't have any feedback from hashpack team, the problem seems to be coming from their signer.
I've opened a ticket on their discord and I'm still waiting for an answer.
You can close I think it's not related to the sdk

@SimiHunjan
Copy link
Contributor

Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants