rpc: add witness nonce for submitted blocks.

This commit is contained in:
Christopher Jeffrey 2016-12-15 16:12:35 -08:00
parent 6d1eb9fd36
commit 2e26909e85
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 45 additions and 1 deletions

View File

@ -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);
});

View File

@ -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);

View File

@ -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}

View File

@ -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`.