Error in ensureDomainExistence function: "Decode data for discriminant 85 is undefined"
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-stablebranch - Git commit hash for Iroha:
eec85ce9 -
@iroha2/clientver. 2.0.2 - Distro running Iroha peer(s): Ubuntu 20.04.5 LTS
- Distro running the client: Windows 10
-
uname -aoutput: Linux Hyper 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
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();
}
}
@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): https://github.com/hyperledger/iroha/commit/75da907f66d5270f407a50e06bc76cec41d3d409.
I am not sure that iroha2-stable is the same.
@6r1d, I am likely to close the issue due to its irrelevance.
Sure, but hopefully it will not repeat. I am not sure personally, so it would help if you explain a bit.
I think it is simply a compatibility issue.
However, I think it might be useful to implement this:
- https://github.com/hyperledger/iroha-javascript/issues/147