Skip to content

Commit 31ed23a

Browse files
committed
Accept XTM SubmitBlock hash responses
Tari SubmitBlock reports successful XTM submissions with result.block_hash and no status OK field. The generic object-result acceptor treated those accepted blocks as unknown RPC results, retried them, and sent false block-submit failure emails on sg/de nodes.
1 parent 8c3e8c2 commit 31ed23a

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/coins/core/factories.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,15 @@ function acceptStatusOkObject(ctx) {
11441144
return !!(ctx.rpcResult && typeof ctx.rpcResult.result === "object" && ctx.rpcResult.result && ctx.rpcResult.result.status === "OK");
11451145
}
11461146

1147+
// Tari SubmitBlock returns result.block_hash without status OK on success.
1148+
// Treating it as generic object result makes valid XTM blocks retry and alert.
1149+
function acceptXtmBlockHashResult(ctx) {
1150+
if (!ctx.rpcResult || typeof ctx.rpcResult.result !== "object" || !ctx.rpcResult.result) return false;
1151+
const blockHash = ctx.rpcResult.result.block_hash;
1152+
if (Array.isArray(blockHash) || Buffer.isBuffer(blockHash)) return blockHash.length > 0;
1153+
return typeof blockHash === "string" && blockHash.length > 0;
1154+
}
1155+
11471156
function acceptNonRejectedResponse(ctx) { return !!(ctx.rpcResult && ctx.rpcResult.response !== "rejected"); }
11481157

11491158
function acceptAccepted202String(ctx) { return typeof ctx.rpcResult === "string" && ctx.rpcStatus == 202; }
@@ -1176,7 +1185,10 @@ function resolveEthSubmittedBlockHash(ctx, callback) {
11761185
}
11771186

11781187
function resolveXtmSubmittedBlockHash(ctx, callback) {
1179-
return callback(Buffer.from(ctx.rpcResult.result.block_hash).toString("hex"));
1188+
const blockHash = ctx.rpcResult && ctx.rpcResult.result && ctx.rpcResult.result.block_hash;
1189+
if (Array.isArray(blockHash) || Buffer.isBuffer(blockHash)) return callback(Buffer.from(blockHash).toString("hex"));
1190+
if (typeof blockHash === "string") return callback(blockHash);
1191+
return callback("0".repeat(64));
11801192
}
11811193

11821194
function submitCryptonoteBlock(ctx) {
@@ -1344,6 +1356,7 @@ const pool = {
13441356
submitSuccess: "boolean",
13451357
sendLoginResult: sendXtmCLoginResult,
13461358
verifySpecialShare: verifyXtmCShare,
1359+
acceptSubmittedBlock: acceptXtmBlockHashResult,
13471360
resolveSubmittedBlockHash: resolveXtmSubmittedBlockHash,
13481361
submitBlockRpc: submitXtmCBlock,
13491362
jobAlgo: "cuckaroo",
@@ -1353,6 +1366,7 @@ const pool = {
13531366
};
13541367
pool.submitAccept = Object.freeze({
13551368
statusOkObject: acceptStatusOkObject,
1369+
xtmBlockHashResult: acceptXtmBlockHashResult,
13561370
accepted202String: acceptAccepted202String
13571371
});
13581372
pool.blockHash = Object.freeze({

lib/coins/xtm_t.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { blob, pool, pow, preset, rpc } = require("./core/factories.js");
44
module.exports = preset.directReserve({ port: 18146, coin: "XTM-T", blobType: 106, algo: "rx/0", blobTypeName: "xtm-t",
55
blob: blob.xtmT(),
66
pool: pool.standard({
7+
acceptSubmittedBlock: pool.submitAccept.xtmBlockHashResult,
78
resolveSubmittedBlockHash: pool.blockHash.xtmRpcHash,
89
submitBlockRpc: pool.blockSubmit.xtmRx
910
}),

tests/pool/coin/submitters.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ test("xtm submit and verify handlers preserve the pre-refactor special-case tari
514514
}
515515
});
516516

517+
assert.equal(xtmTPool.acceptSubmittedBlock({ rpcResult: { result: { block_hash: [0, 1, 2, 255] } } }), true);
518+
assert.equal(xtmTPool.acceptSubmittedBlock({ rpcResult: { result: { block_hash: "11".repeat(32) } } }), true);
519+
assert.equal(xtmTPool.acceptSubmittedBlock({ rpcResult: { result: { status: "OK" } } }), false);
520+
assert.equal(xtmTPool.acceptSubmittedBlock({ rpcResult: { result: { status: "FAILED" } } }), false);
521+
assert.equal(xtmCPool.acceptSubmittedBlock({ rpcResult: { result: { block_hash: [1, 2, 3] } } }), true);
522+
assert.equal(xtmCPool.acceptSubmittedBlock({ rpcResult: { result: { status: "OK" } } }), false);
523+
517524
assert.equal(resolvedRxHash, "000102ff");
518525
assert.equal(xtmRxCalls.length, 1);
519526
assert.equal(xtmRxCalls[0].port, 18146);

0 commit comments

Comments
 (0)