This commit is contained in:
Christopher Jeffrey 2016-04-18 17:02:33 -07:00
parent f8d49f0653
commit 949f8684b0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
5 changed files with 89 additions and 66 deletions

View File

@ -850,15 +850,17 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac
100)); 100));
} }
if (self.options.verifySync !== true) //if (self.options.verifySync !== true)
continue; // continue;
if (!scriptCheck) if (!scriptCheck)
continue; continue;
// Verify the scripts // Verify the scripts
if (!tx.verify(j, true, flags)) { if (!tx.verify(j, true, flags)) {
assert(!historical, 'BUG: Invalid inputs in historical data!'); utils.print(tx.rhash);
console.error(tx.inputs[j]);
//assert(!historical, 'BUG: Invalid inputs in historical data!');
return callback(new VerifyError(block, return callback(new VerifyError(block,
'invalid', 'invalid',
'mandatory-script-verify-flag-failed', 'mandatory-script-verify-flag-failed',
@ -877,7 +879,7 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac
if (block.getClaimed().cmp(block.getReward()) > 0) if (block.getClaimed().cmp(block.getReward()) > 0)
return callback(new VerifyError(block, 'invalid', 'bad-cb-amount', 100)); return callback(new VerifyError(block, 'invalid', 'bad-cb-amount', 100));
if (self.options.verifySync === true) //if (self.options.verifySync === true)
return callback(); return callback();
if (!scriptCheck) if (!scriptCheck)

View File

@ -280,7 +280,7 @@ Pool.prototype._init = function _init() {
this.chain.on('orphan', function(block, data, peer) { this.chain.on('orphan', function(block, data, peer) {
self.emit('orphan', data, peer); self.emit('orphan', data, peer);
// Resolve orphan chain // Resolve orphan chain
self.resolveOrphan(self.peers.load, null, data.hash); // self.resolveOrphan(self.peers.load, null, data.hash);
}); });
this.chain.on('full', function() { this.chain.on('full', function() {
@ -830,8 +830,8 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
peer.sendReject(block, err.code, err.reason, err.score); peer.sendReject(block, err.code, err.reason, err.score);
if (err.reason === 'bad-prevblk') { if (err.reason === 'bad-prevblk') {
// self.chain.purgePending(); if (peer === self.peers.load)
// self.resolveOrphan(peer, null, block.hash('hex')); self.resolveOrphan(peer, null, block.hash('hex'));
} }
self.scheduleRequests(peer); self.scheduleRequests(peer);
@ -1262,6 +1262,11 @@ Pool.prototype._removePeer = function _removePeer(peer) {
this.peers.all.splice(i, 1); this.peers.all.splice(i, 1);
if (this.peers.load === peer) { if (this.peers.load === peer) {
Object.keys(this.request.map).forEach(function(hash) {
var item = this.request.map[hash];
if (item.peer === peer)
item.finish();
}, this);
bcoin.debug('Removed loader peer (%s).', peer.host); bcoin.debug('Removed loader peer (%s).', peer.host);
this.peers.load = null; this.peers.load = null;
} }

View File

@ -482,7 +482,8 @@ testnet.block = {
bip34height: 21111, bip34height: 21111,
bip34hash: 'f88ecd9912d00d3f5c2a8e0f50417d3e415c75b3abe584346da9b32300000000', bip34hash: 'f88ecd9912d00d3f5c2a8e0f50417d3e415c75b3abe584346da9b32300000000',
pruneAfterHeight: 1000, pruneAfterHeight: 1000,
maxTipAge: 0x7fffffff // maxTipAge: 0x7fffffff
maxTipAge: 24 * 60 * 60
}; };
testnet.witness = false; testnet.witness = false;

View File

@ -15,7 +15,7 @@ var BufferWriter = require('./writer');
var opcodes = constants.opcodes; var opcodes = constants.opcodes;
var STACK_TRUE = new Buffer([1]); var STACK_TRUE = new Buffer([1]);
var STACK_FALSE = new Buffer([]); var STACK_FALSE = new Buffer([]);
var STACK_NEGATE = new Buffer([0xff]); var STACK_NEGATE = new Buffer([0x81]);
/** /**
* A big number (bn.js) * A big number (bn.js)
@ -417,6 +417,8 @@ Stack.prototype.slice = function slice(start, end) {
*/ */
Stack.prototype.splice = function splice(i, remove, insert) { Stack.prototype.splice = function splice(i, remove, insert) {
if (insert === undefined)
return this.items.splice(i, remove);
return this.items.splice(i, remove, insert); return this.items.splice(i, remove, insert);
}; };
@ -610,10 +612,10 @@ Stack.prototype._pickroll = function pickroll(op, flags) {
val = this.pop(); val = this.pop();
n = Script.num(val, flags).toNumber(); n = Script.num(val, flags).toNumber();
if (n <= 0 || n > this.length) if (n < 0 || n >= this.length)
throw new ScriptError('Bad value.', op); throw new ScriptError('Bad value.', op);
val = this.get(-n - 1); val = this.top(-n - 1);
if (op === opcodes.OP_ROLL) if (op === opcodes.OP_ROLL)
this.splice(this.length - n - 1, 1); this.splice(this.length - n - 1, 1);
@ -1180,10 +1182,10 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
n = Script.num(stack.pop(), flags); n = Script.num(stack.pop(), flags);
switch (op) { switch (op) {
case opcodes.OP_1ADD: case opcodes.OP_1ADD:
n.iadd(1); n.iaddn(1);
break; break;
case opcodes.OP_1SUB: case opcodes.OP_1SUB:
n.isub(1); n.isubn(1);
break; break;
case opcodes.OP_2MUL: case opcodes.OP_2MUL:
n.iushln(1); n.iushln(1);
@ -1229,7 +1231,8 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
case opcodes.OP_LESSTHANOREQUAL: case opcodes.OP_LESSTHANOREQUAL:
case opcodes.OP_GREATERTHANOREQUAL: case opcodes.OP_GREATERTHANOREQUAL:
case opcodes.OP_MIN: case opcodes.OP_MIN:
case opcodes.OP_MAX: { case opcodes.OP_MAX:
case opcodes.OP_WITHIN: {
switch (op) { switch (op) {
case opcodes.OP_ADD: case opcodes.OP_ADD:
case opcodes.OP_SUB: case opcodes.OP_SUB:
@ -1318,10 +1321,9 @@ Script.prototype.interpret = function interpret(stack, flags, tx, index, version
} }
if (typeof n === 'boolean') if (typeof n === 'boolean')
n = new bn(n ? 1 : 0); n = new bn(n ? 1 : 0);
res = Script.bool(n);
if (op === opcodes.OP_NUMEQUALVERIFY) { if (op === opcodes.OP_NUMEQUALVERIFY) {
if (!res) if (!Script.bool(n))
return false; throw new ScriptError('Verify failed.', op, ip);
} else { } else {
stack.push(Script.array(n)); stack.push(Script.array(n));
} }
@ -1756,6 +1758,8 @@ Script.bool = function bool(value) {
*/ */
Script.num = function num(value, flags, size) { Script.num = function num(value, flags, size) {
var result, n;
assert(Buffer.isBuffer(value)); assert(Buffer.isBuffer(value));
if (flags == null) if (flags == null)
@ -1782,21 +1786,20 @@ Script.num = function num(value, flags, size) {
} }
} }
// If we are signed, do (~num + 1) to get if (value.length === 0)
// the positive counterpart and set bn's return new bn(0);
// negative flag.
result = new bn(value, 'le');
// If the input vector's most significant byte is
// 0x80, remove it from the result's msb and return
// a negative.
if (value[value.length - 1] & 0x80) { if (value[value.length - 1] & 0x80) {
if (utils.isNegZero(value, 'le')) { n = new bn(0x80).ushln(8 * (value.length - 1)).notn(64);
value = new bn(0); return result.uand(n).neg();
} else {
value = new bn(value, 'le');
value = value.notn(size * 8).addn(1).neg();
}
} else {
value = new bn(value, 'le');
} }
return value; return result;
}; };
/** /**
@ -1812,6 +1815,8 @@ Script.num = function num(value, flags, size) {
*/ */
Script.array = function(value) { Script.array = function(value) {
var neg, result;
if (Buffer.isBuffer(value)) if (Buffer.isBuffer(value))
return value; return value;
@ -1820,19 +1825,33 @@ Script.array = function(value) {
assert(bn.isBN(value)); assert(bn.isBN(value));
// Convert the number to the
// negative byte representation.
if (value.isNeg()) {
if (value.cmpn(0) === 0)
value = new bn(0);
else
value = value.neg().notn(value.byteLength() * 8).subn(1);
}
if (value.cmpn(0) === 0) if (value.cmpn(0) === 0)
return STACK_FALSE; return STACK_FALSE;
return value.toBuffer('le'); // If the most significant byte is >= 0x80
// and the value is positive, push a new
// zero-byte to make the significant
// byte < 0x80 again.
// If the most significant byte is >= 0x80
// and the value is negative, push a new
// 0x80 byte that will be popped off when
// converting to an integral.
// If the most significant byte is < 0x80
// and the value is negative, add 0x80 to
// it, since it will be subtracted and
// interpreted as a negative when
// converting to an integral.
neg = value.cmpn(0) < 0;
result = value.toArray('le');
if (result[result.length - 1] & 0x80)
result.push(neg ? 0x80 : 0);
else if (neg)
result[result.length - 1] |= 0x80;
return new Buffer(result);
}; };
/** /**
@ -1927,7 +1946,7 @@ Script.checkMinimal = function checkMinimal(value, flags) {
if (value.length === 1 && value[0] >= 1 && value[0] <= 16) if (value.length === 1 && value[0] >= 1 && value[0] <= 16)
return false; return false;
if (value.length === 1 && value[0] === 0xff) if (value.length === 1 && value[0] === 0x81)
return false; return false;
if (value.length <= 75) if (value.length <= 75)
@ -3824,45 +3843,41 @@ Script.decode = function decode(buf) {
if (op >= 0x01 && op <= 0x4b) { if (op >= 0x01 && op <= 0x4b) {
code.push(buf.slice(off, off + op)); code.push(buf.slice(off, off + op));
off += op; off += op;
if (off > buf.length) { // if (off > buf.length) {
utils.hidden(code[code.length - 1], 'pushdata', { utils.hidden(code[code.length - 1], 'pushdata', {
opcode: null, opcode: null,
size: op size: op
}); });
}
} else if (op === opcodes.OP_PUSHDATA1) { } else if (op === opcodes.OP_PUSHDATA1) {
size = buf[off]; size = buf[off];
off += 1; off += 1;
code.push(buf.slice(off, off + size)); code.push(buf.slice(off, off + size));
off += size; off += size;
if (size <= 0x4b || off > buf.length) { // if (size <= 0x4b || off > buf.length) {
utils.hidden(code[code.length - 1], 'pushdata', { utils.hidden(code[code.length - 1], 'pushdata', {
opcode: op, opcode: op,
size: size size: size
}); });
}
} else if (op === opcodes.OP_PUSHDATA2) { } else if (op === opcodes.OP_PUSHDATA2) {
size = utils.readU16(buf, off); size = utils.readU16(buf, off);
off += 2; off += 2;
code.push(buf.slice(off, off + size)); code.push(buf.slice(off, off + size));
off += size; off += size;
if (size <= 0xff || off > buf.length) { // if (size <= 0xff || off > buf.length) {
utils.hidden(code[code.length - 1], 'pushdata', { utils.hidden(code[code.length - 1], 'pushdata', {
opcode: op, opcode: op,
size: size size: size
}); });
}
} else if (op === opcodes.OP_PUSHDATA4) { } else if (op === opcodes.OP_PUSHDATA4) {
size = utils.readU32(buf, off); size = utils.readU32(buf, off);
off += 4; off += 4;
code.push(buf.slice(off, off + size)); code.push(buf.slice(off, off + size));
off += size; off += size;
if (size <= 0xffff || off > buf.length) { // if (size <= 0xffff || off > buf.length) {
utils.hidden(code[code.length - 1], 'pushdata', { utils.hidden(code[code.length - 1], 'pushdata', {
opcode: op, opcode: op,
size: size size: size
}); });
}
} else { } else {
code.push(op); code.push(op);
} }
@ -3928,7 +3943,7 @@ Script.encode = function encode(code, writer) {
} else if (op[0] >= 1 && op[0] <= 16) { } else if (op[0] >= 1 && op[0] <= 16) {
p.writeU8(op[0] + 0x50); p.writeU8(op[0] + 0x50);
continue; continue;
} else if (op[0] === 0xff) { } else if (op[0] === 0x81) {
p.writeU8(opcodes.OP_1NEGATE); p.writeU8(opcodes.OP_1NEGATE);
continue; continue;
} }

View File

@ -63,7 +63,7 @@ function TX(data, block, index) {
data = {}; data = {};
this.type = 'tx'; this.type = 'tx';
this.version = data.version || 1; this.version = data.version != null ? data.version : 1;
this.flag = data.flag || 1; this.flag = data.flag || 1;
this.inputs = []; this.inputs = [];
this.outputs = []; this.outputs = [];