Closed szg251 closed 7 months ago
I've been looking into this without success so far. I was originally suspecting an issue with the TypeScript client and possible coercion there. But no. The server is also working as expecting and the error comes from the node as far as I can tell. I've been tracing this back to the very messages sent to the node and, the node replies False
even for transactions that are part of the mempool snapshot for some reason.
I've inspected the current implementation and interestingly, the server-side implements the hasTransaction
handler by using a side set of transaction id which is said to be "maintained in sync with the transaction in the mempool". I suppose that this statement might be invalid.
I invite you to open a ticket on so let them know about the issue. Here's a minimal reproduction script using Ogmios on the Preview network (which assumes a my.sk
and my.addr
files with a secret key and an address respectively, with enough funds).
const WebSocket = require('ws');
const { execSync } = require('node:child_process');
const { readFileSync } = require('node:fs');
const ADDR = readFileSync("./my.addr");
const SECRET_KEY = "./my.sk";
const SOCKET_PATH = "/tmp/node.socket";
const NETWORK_MAGIC = 2 // 0: mainnet, 1: preprod, 2: preview
const ws = new WebSocket('ws://127.0.0.1:1337');
function rpc(method, params = {}, id) {
return JSON.stringify({
jsonrpc: '2.0',
method,
params,
id
});
}
function cli(cmd, ...opts) {
const is = str => cmd.includes(str);
if (is("build") || is("query") || is("submit")) {
opts.unshift(`--socket-path ${SOCKET_PATH}`);
}
if (is("build") || is("query") || is("sign") || is("submit")) {
opts.unshift(`--testnet-magic ${NETWORK_MAGIC}`);
}
if (is("build") || is("sign")) {
opts.unshift(`--out-file /tmp/tx.cbor`);
}
if (is("txid") || is("sign") || is("submit")) {
opts.unshift(`--tx-file /tmp/tx.cbor`);
}
return execSync(`cardano-cli ${cmd} ${opts.join(" ")}`).toString();
}
let txId;
ws.on('open', () => {
const utxo = cli("query utxo", `--address ${ADDR}`);
console.log(utxo);
const utxoRef = utxo
.split("\n")[2]
.split(" ")
.map(x => x.trim())
.filter(x => x !== "");
cli("transaction build",
`--tx-in ${utxoRef[0]}#${utxoRef[1]}`,
`--change-address ${ADDR}`
);
txId = cli("transaction txid").trim();
cli("transaction sign", `--signing-key-file ${SECRET_KEY}`);
console.log(`submitting ${txId}`);
cli("transaction submit");
ws.send(rpc('acquireMempool'));
});
ws.on('message', (response) => {
const { result, error, method } = JSON.parse(response);
if (error) {
console.log(error);
ws.close();
return;
}
console.log(`${method} -> ${JSON.stringify(result)}`);
if (method === 'acquireMempool') {
ws.send(rpc('hasTransaction', { id: txId }))
} else if (method === 'hasTransaction' || result.transaction) {
ws.send(rpc('nextTransaction'));
} else {
ws.close();
}
});
ws.on('error', e => {
console.error('Oopsie', e);
process.exit(1)
});
This outputs the following:
TxHash TxIx Amount
--------------------------------------------------------------------------------------
cfaaf224394adde30fdf2962e78ec63bff14ae65cfece5ddee116ec4789821c6 0 8687960 lovelace + TxOutDatumNone
submitting 868d331ab1348f5c87c09c12bb719593ba0434c7607af503fe78dacec55ffca7
acquireMempool -> {"acquired":"mempool","slot":44029808}
hasTransaction -> false
nextTransaction -> {"transaction":{"id":"868d331ab1348f5c87c09c12bb719593ba0434c7607af503fe78dacec55ffca7"}}
nextTransaction -> {"transaction":null}
I found the issue in the consensus --> https://github.com/IntersectMBO/ouroboros-consensus/issues/1009
There's possibly a fix I can do in Ogmios while this gets fixed.
What Git revision / release tag are you using?
6.0.1
Do you use any client SDK? If yes, which one?
None
Describe what the problem is?
hasTransaction
returns afalse
even though the transaction can be confirmed vianextTransaction
calls. A simple example:The logs produced by
dbg
:What should be the expected behavior?
HasTransaction returns true when tx is in mempool
If applicable, what are the logs from the server around the occurence of the problem?
No response