From dc6b7b1f10f827dc12c7942d4a655ec995841669 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 15 Mar 2017 04:04:22 -0700 Subject: [PATCH] rpc: rename _submitBlock. --- lib/http/rpc.js | 120 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index af03cdcd..8734d77c 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1047,65 +1047,7 @@ RPC.prototype.submitBlock = co(function* submitBlock(args, help) { block = Block.fromRaw(data); - return yield this._submitBlock(block); -}); - -RPC.prototype._submitBlock = co(function* _submitBlock(block) { - var unlock1 = yield this.locker.lock(); - var unlock2 = yield this.chain.locker.lock(); - try { - return yield this.__submitBlock(block); - } finally { - unlock2(); - unlock1(); - } -}); - -RPC.prototype.__submitBlock = co(function* __submitBlock(block) { - var entry, prev, state, tx; - - this.logger.info('Handling submitted block: %s.', block.rhash()); - - prev = yield this.chain.db.getEntry(block.prevBlock); - - if (prev) { - state = yield this.chain.getDeployments(block.ts, prev); - - // Fix eloipool bug (witness nonce is not present). - if (state.hasWitness() && block.getCommitmentHash()) { - tx = block.txs[0]; - if (!tx.hasWitness()) { - this.logger.warning('Submitted block had no witness nonce.'); - this.logger.debug(tx); - - // Recreate witness nonce (all zeroes). - tx.inputs[0].witness.set(0, encoding.ZERO_HASH); - tx.inputs[0].witness.compile(); - - tx.refresh(); - block.refresh(); - } - } - } - - try { - entry = yield this.chain._add(block); - } catch (err) { - if (err.type === 'VerifyError') { - this.logger.warning('RPC block rejected: %s (%s).', - block.rhash(), err.reason); - return 'rejected: ' + err.reason; - } - throw err; - } - - if (!entry) { - this.logger.warning('RPC block rejected: %s (bad-prevblk).', - block.rhash()); - return 'rejected: bad-prevblk'; - } - - return null; + return yield this.addBlock(block); }); RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) { @@ -1133,7 +1075,7 @@ RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) { block = Block.fromRaw(data); - return yield this._submitBlock(block); + return yield this.addBlock(block); } if (rules) @@ -2230,6 +2172,64 @@ RPC.prototype.updateWork = co(function* updateWork() { return attempt; }); +RPC.prototype.addBlock = co(function* addBlock(block) { + var unlock1 = yield this.locker.lock(); + var unlock2 = yield this.chain.locker.lock(); + try { + return yield this._addBlock(block); + } finally { + unlock2(); + unlock1(); + } +}); + +RPC.prototype._addBlock = co(function* _addBlock(block) { + var entry, prev, state, tx; + + this.logger.info('Handling submitted block: %s.', block.rhash()); + + prev = yield this.chain.db.getEntry(block.prevBlock); + + if (prev) { + state = yield this.chain.getDeployments(block.ts, prev); + + // Fix eloipool bug (witness nonce is not present). + if (state.hasWitness() && block.getCommitmentHash()) { + tx = block.txs[0]; + if (!tx.hasWitness()) { + this.logger.warning('Submitted block had no witness nonce.'); + this.logger.debug(tx); + + // Recreate witness nonce (all zeroes). + tx.inputs[0].witness.set(0, encoding.ZERO_HASH); + tx.inputs[0].witness.compile(); + + tx.refresh(); + block.refresh(); + } + } + } + + try { + entry = yield this.chain._add(block); + } catch (err) { + if (err.type === 'VerifyError') { + this.logger.warning('RPC block rejected: %s (%s).', + block.rhash(), err.reason); + return 'rejected: ' + err.reason; + } + throw err; + } + + if (!entry) { + this.logger.warning('RPC block rejected: %s (bad-prevblk).', + block.rhash()); + return 'rejected: bad-prevblk'; + } + + return null; +}); + RPC.prototype.totalTX = function totalTX() { return this.mempool ? this.mempool.totalTX : 0; };