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

Error in ensureDomainExistence function: "Decode data for discriminant 85 is undefined" #126

Closed
6r1d opened this issue Sep 20, 2022 · 5 comments
Labels

Comments

@6r1d
Copy link
Contributor

6r1d commented Sep 20, 2022

Today, Youssef Mohammad reported an error occuring with Iroha-JS in Iroha Telegram.

Log
js
file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/core/dist/lib.mjs:583
  throw new Error(`Decode data for discriminant ${discriminant} is undefined; decoders schema: ${formatDecoders(decoders)}`);
        ^

Error: Decode data for discriminant 85 is undefined; decoders schema: 0 => Decode(...), 1 => Signature(...), 2 => Permission(...), 3 => Evaluate(...), 4 => Find(...), 5 => Conversion(...)
  at decodeEnum (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/core/dist/lib.mjs:583:11)
  at file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/core/dist/lib.mjs:590:22
  at trackDecode (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/definition-runtime/dist/lib.mjs:19:61)
  at decodeTracked (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/definition-runtime/dist/lib.mjs:238:37)
  at WalkerImpl.decode (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/core/dist/lib.mjs:16:19)
  at Function.fromBuffer (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@scale-codec/definition-runtime/dist/lib.mjs:243:37)
  at Client.request (file:///C:/Users/ASUS/Desktop/crowd-funding/node_modules/@iroha2/client/dist/lib.mjs:350:42)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async ensureDomainExistence (file:///C:/Users/ASUS/Desktop/crowd-funding/client.js:120:18)
  at async file:///C:/Users/ASUS/Desktop/crowd-funding/client.js:136:1

Node.js v18.9.0

Details reported:

  • A bare-metal version of Iroha
  • iroha2-stable branch
  • Git commit hash for Iroha: eec85ce9
  • @iroha2/client ver. 2.0.2
  • Distro running Iroha peer(s): Ubuntu 20.04.5 LTS
  • Distro running the client: Windows 10
  • uname -a output: Linux Hyper 5.4.0-125-generic Refactor crypto wasm #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
@6r1d 6r1d changed the title Error in ensureDomainExistence function Error in ensureDomainExistence function: "Decode data for discriminant 85 is undefined" Sep 20, 2022
@6r1d
Copy link
Contributor Author

6r1d commented Sep 20, 2022

Youssef also reported a decoded error: Unhandled rejection: WarpQueryError(Decode(ParityScale)).

It was displayed by modifying a file: node_modules\@iroha2\client\dist\lib.mjs

Modified code:

    async request(query, params) {
        const scope = createScope();
        const { createHash } = useCryptoAssertive();
        const url = this.forceGetApiURL();
        const accountId = this.forceGetAccountId();
        const keyPair = this.forceGetKeyPair();
        const payload = QueryPayload({
            query,
            account_id: accountId,
            timestamp_ms: BigInt(Date.now()),
            filter: params?.filter ?? PredicateBox('Raw', Predicate('Pass')),
        });
        try {
            let queryBytes,queryString;
            scope.run(() => {
                const payloadHash = collect(createHash(QueryPayload.toBuffer(payload)));
                const signature = makeSignature(keyPair, payloadHash.bytes());
                queryString = VersionedSignedQueryRequest('V1', SignedQueryRequest({ payload, signature }))
                console.log(SignedQueryRequest({ payload, signature }))
                queryBytes = VersionedSignedQueryRequest.toBuffer(VersionedSignedQueryRequest('V1', SignedQueryRequest({ payload, signature })));
            });
            const response = await this.forceGetFetch()(url + ENDPOINT_QUERY, {
                method: 'POST',
                body: queryBytes,
            }).then();

            /* ADDED BY YOUSSEF MOHAMMAD TO DECODE RUST ERROR MESSAGE */

            console.log(await response.text())

            /*  */
            const buffer = await response.arrayBuffer();
            const decoder = new TextDecoder("utf-8");
            console.log("QS",queryBytes, queryBytes.length, decoder.decode(queryBytes))

            const bytes = new Uint8Array(buffer);
            fs.writeFileSync('./iroha-query.bin',queryBytes)
            if (response.status === 200) {
                // OK
                const value = VersionedPaginatedQueryResult.fromBuffer(bytes).as('V1');
                return Enum.variant('Ok', value);
            }
            else {
                // ERROR
                try {
                  const error = QueryError.fromBuffer(bytes);
                  return Enum.variant('Err', error);  
                } catch(e) {
                  const decoder = new TextDecoder("utf-8");
                  //throw new Error(decoder.decode(bytes));
                  return decoder.decode(bytes);
                }
            }
        }
        finally {
            scope.free();
        }
    }

@0x009922
Copy link
Contributor

@6r1d, please mention me directly and add iroha2 label to the issue so it can be more accessible for my attention. Thanks.

In general, I think it is a versioning issue. @iroha2/client and @iroha2/data-model v2.0.2 targets Iroha 2 RC6 (previous LTS): hyperledger-iroha/iroha@75da907.

I am not sure that iroha2-stable is the same.

@0x009922
Copy link
Contributor

0x009922 commented Feb 27, 2023

@6r1d, I am likely to close the issue due to its irrelevance.

@6r1d
Copy link
Contributor Author

6r1d commented Feb 28, 2023

Sure, but hopefully it will not repeat. I am not sure personally, so it would help if you explain a bit.

@0x009922
Copy link
Contributor

I think it is simply a compatibility issue.

However, I think it might be useful to implement this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants