diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 17592306..b18bd056 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1438,6 +1438,16 @@ RPC.prototype.submitblock = co(function* submitblock(args) { block = Block.fromRaw(toString(args[0]), 'hex'); + if (block.getCommitmentHash()) { + if (!block.txs[0].hasWitness()) { + this.logger.warning('Submitted block had no witness nonce.'); + this.logger.debug(block.txs[0]); + block.txs[0].inputs[0].witness.set(0, constants.ZERO_HASH); + block.txs[0].clearCache(); + block.clearCache(); + } + } + return yield this._submitblock(block); }); diff --git a/lib/primitives/abstractblock.js b/lib/primitives/abstractblock.js index 243e9804..66b704b4 100644 --- a/lib/primitives/abstractblock.js +++ b/lib/primitives/abstractblock.js @@ -57,7 +57,7 @@ function AbstractBlock(options) { this._hash = null; this._hhash = null; this._size = null; - this._witnessSize = null; + this._witness = null; if (options) this.parseOptions(options); diff --git a/lib/primitives/block.js b/lib/primitives/block.js index 056c8da3..88410fd0 100644 --- a/lib/primitives/block.js +++ b/lib/primitives/block.js @@ -76,6 +76,20 @@ Block.fromOptions = function fromOptions(options) { return new Block().fromOptions(options); }; +/** + * Clear any cached values. + */ + +Block.prototype.clearCache = function clearCache() { + this._valid = null; + this._validHeaders = null; + this._hash = null; + this._hhash = null; + this._raw = null; + this._size = -1; + this._witness = -1; +}; + /** * Serialize the block. Include witnesses if present. * @returns {Buffer} diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index e8b9285f..cab23d6a 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -140,6 +140,26 @@ TX.prototype.clone = function clone() { return new TX(this); }; +/** + * Clear any cached values. + */ + +TX.prototype.clearCache = function clearCache() { + this._hash = null; + this._hhash = null; + this._whash = null; + + this._raw = null; + this._size = -1; + this._witness = -1; + + this._outputValue = -1; + this._inputValue = -1; + this._hashPrevouts = null; + this._hashSequence = null; + this._hashOutputs = null; +}; + /** * Hash the transaction with the non-witness serialization. * @param {String?} enc - Can be `'hex'` or `null`.