From 590c4350e9ae86b9b862e059b3abf28d6e20b0b7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 25 Jul 2017 02:14:24 -0700 Subject: [PATCH] rpc: fix submitwork. --- lib/http/rpc.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index eaa7abb1..2bd5a7ef 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1029,11 +1029,11 @@ RPC.prototype._submitWork = async function _submitWork(data) { if (data.length !== 128) throw new RPCError(errs.INVALID_PARAMETER, 'Invalid work size.'); - header = Headers.fromHead(data); - data = data.slice(0, 80); data = swap32(data); + header = Headers.fromHead(data); + if (header.prevBlock !== attempt.prevBlock || header.bits !== attempt.bits) { return false; @@ -1047,8 +1047,7 @@ RPC.prototype._submitWork = async function _submitWork(data) { if (!nonces) return false; - n1 = nonces.nonce1; - n2 = nonces.nonce2; + [n1, n2] = nonces; nonce = header.nonce; ts = header.ts; @@ -2332,7 +2331,7 @@ RPC.prototype.updateWork = async function updateWork() { root = attempt.getRoot(n1, n2); root = root.toString('hex'); - this.merkleMap.set(root, new Nonces(n1, n2)); + this.merkleMap.set(root, [n1, n2]); return attempt; } @@ -2352,7 +2351,7 @@ RPC.prototype.updateWork = async function updateWork() { this.attempt = attempt; this.lastActivity = util.now(); - this.merkleMap.set(root, new Nonces(n1, n2)); + this.merkleMap.set(root, [n1, n2]); return attempt; }; @@ -2737,11 +2736,6 @@ function toDeployment(id, version, status) { }; } -function Nonces(n1, n2) { - this.nonce1 = n1; - this.nonce2 = n2; -} - function parseAddress(raw, network) { try { return Address.fromString(raw, network);