pass size into block and tx for maxsize checks.
This commit is contained in:
parent
7ffcc8e7f3
commit
5942209f41
@ -21,6 +21,7 @@ function Block(data, subtype) {
|
||||
this.flags = data.flags || [];
|
||||
this._network = data._network || false;
|
||||
this._raw = data._raw || null;
|
||||
this._size = data._size || 0;
|
||||
|
||||
// List of matched TXs
|
||||
this.tx = [];
|
||||
@ -80,6 +81,10 @@ Block.prototype.render = function render() {
|
||||
return bcoin.protocol.framer.block(this, this.subtype);
|
||||
};
|
||||
|
||||
Block.prototype.size = function render() {
|
||||
return this._size || this.render().length;
|
||||
};
|
||||
|
||||
Block.prototype.hasTX = function hasTX(hash) {
|
||||
return this.tx.indexOf(hash) !== -1;
|
||||
};
|
||||
@ -172,9 +177,11 @@ Block.prototype._checkBlock = function checkBlock() {
|
||||
if (this.ts > (Date.now() / 1000) + 2 * 60 * 60)
|
||||
return false;
|
||||
|
||||
// Size of all txs cant be bigger than MAX_BLOCK_SIZE
|
||||
if (this.txs.length > bcoin.protocol.constants.block.maxSize)
|
||||
// Size can't be bigger than MAX_BLOCK_SIZE
|
||||
if (this.txs.length > constants.block.maxSize
|
||||
|| this.size() > constants.block.maxSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First TX must be a coinbase
|
||||
if (!this.txs.length ||
|
||||
|
||||
@ -222,7 +222,8 @@ Parser.prototype.parseMerkleBlock = function parseMerkleBlock(p) {
|
||||
totalTX: readU32(p, 80),
|
||||
hashes: hashes,
|
||||
flags: flags,
|
||||
_raw: p.slice(0, 80)
|
||||
_raw: p.slice(0, 80),
|
||||
_size: p.length
|
||||
};
|
||||
};
|
||||
|
||||
@ -289,7 +290,8 @@ Parser.prototype.parseBlock = function parseBlock(p) {
|
||||
nonce: readU32(p, 76),
|
||||
totalTX: totalTX,
|
||||
txs: txs,
|
||||
_raw: p.slice(0, 80)
|
||||
_raw: p.slice(0, 80),
|
||||
_size: p.length
|
||||
};
|
||||
};
|
||||
|
||||
@ -381,7 +383,8 @@ Parser.prototype.parseTX = function parseTX(p) {
|
||||
inputs: txIn,
|
||||
outputs: txOut,
|
||||
lock: readU32(p, off),
|
||||
_off: off + 4
|
||||
_off: off + 4,
|
||||
_size: p.length
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ function TX(data, block) {
|
||||
this._hash = null;
|
||||
this._raw = data._raw || null;
|
||||
this._network = data._network || false;
|
||||
this._size = data._size || 0;
|
||||
this._lock = this.lock;
|
||||
|
||||
if (data.inputs) {
|
||||
@ -66,6 +67,10 @@ TX.prototype.render = function render() {
|
||||
return bcoin.protocol.framer.tx(this);
|
||||
};
|
||||
|
||||
TX.prototype.size = function size() {
|
||||
return this._size || this.render().length;
|
||||
};
|
||||
|
||||
TX.prototype.input = function input(i, index) {
|
||||
this._input(i, index);
|
||||
return this;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user