more standardness.

This commit is contained in:
Christopher Jeffrey 2016-03-30 14:43:06 -07:00
parent 0720c6c64a
commit 945c2f9564
6 changed files with 37 additions and 30 deletions

View File

@ -393,7 +393,7 @@ Block.prototype.toCompact = function toCompact() {
Block.fromCompact = function fromCompact(buf) {
var p = new BufferReader(buf);
var hashes = [];
var version = p.read32();
var version = p.readU32(); // Technically signed
var prevBlock = p.readHash('hex');
var merkleRoot = p.readHash('hex');
var ts = p.readU32();

View File

@ -247,7 +247,7 @@ Chain.prototype._preload = function _preload(callback) {
return {
hash: utils.toHex(hash),
version: p.read32(),
version: p.readU32(), // Technically signed
prevBlock: p.readHash('hex'),
merkleRoot: p.readHash('hex'),
ts: p.readU32(),

View File

@ -267,7 +267,7 @@ ChainBlock.fromRaw = function fromRaw(chain, buf) {
return new ChainBlock(chain, {
hash: utils.toHex(hash),
version: p.read32(),
version: p.readU32(), // Technically signed
prevBlock: p.readHash('hex'),
merkleRoot: p.readHash('hex'),
ts: p.readU32(),

View File

@ -308,11 +308,17 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
hash = tx.hash('hex');
assert(tx.ts === 0);
callback = utils.wrap(callback, unlock);
callback = utils.asyncify(callback);
if (tx.ts !== 0) {
peer.sendReject(tx, 'alreadyknown', 'txn-already-in-mempool', 0);
return callback(new VerifyError(
'alreadyknown',
'txn-already-in-mempool',
0));
}
if (!this.chain.segwitActive) {
if (tx.hasWitness()) {
peer.sendReject(tx, 'nonstandard', 'no-witness-yet', 0);
@ -330,10 +336,20 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
return callback(new VerifyError('invalid', 'coinbase', 100));
}
// ts = locktimeFlags & LOCKTIME_MEDIAN_PAST
// ? self.chain.tip.getMedianTime()
// : utils.now();
ts = utils.now();
height = this.chain.height + 1;
if (!tx.isFinal(ts, height)) {
peer.sendReject(tx, 'nonstandard', 'non-final', 0);
return callback(new VerifyError('nonstandard', 'non-final', 0));
}
if (this.requireStandard) {
ts = utils.now();
height = this.chain.height + 1;
if (!tx.isStandard(flags, ts, height, ret)) {
if (!tx.isStandard(flags, ret)) {
peer.sendReject(tx, 'nonstandard', ret.reason, 0);
return callback(new VerifyError(ret.reason, 0));
}
@ -817,7 +833,7 @@ Mempool.prototype.getLocks = function getLocks(tx, flags, entry, callback) {
var minTime = -1;
var coinHeight;
if ((tx.version >>> 0) < 2 || !hasFlag)
if (tx.version < 2 || !hasFlag)
return utils.asyncify(callback)(null, minHeight, minTime);
utils.forEachSerial(tx.inputs, function(input, next) {

View File

@ -251,7 +251,7 @@ Parser.parseMerkleBlock = function parseMerkleBlock(p) {
p = new BufferReader(p);
p.start();
version = p.read32();
version = p.readU32(); // Technically signed
prevBlock = p.readHash();
merkleRoot = p.readHash();
ts = p.readU32();
@ -293,7 +293,7 @@ Parser.parseHeaders = function parseHeaders(p) {
for (i = 0; i < count; i++) {
headers.push({
version: p.read32(),
version: p.readU32(), // Technically signed
prevBlock: p.readHash(),
merkleRoot: p.readHash(),
ts: p.readU32(),
@ -317,7 +317,7 @@ Parser.parseBlock = function parseBlock(p) {
p = new BufferReader(p);
p.start();
version = p.read32();
version = p.readU32(); // Technically signed
prevBlock = p.readHash();
merkleRoot = p.readHash();
ts = p.readU32();
@ -352,7 +352,7 @@ Parser.parseBlockCompact = function parseBlockCompact(p) {
p = new BufferReader(p);
p.start();
version = p.read32();
version = p.readU32(); // Technically signed
prevBlock = p.readHash();
merkleRoot = p.readHash();
ts = p.readU32();
@ -362,7 +362,7 @@ Parser.parseBlockCompact = function parseBlockCompact(p) {
totalTX = p.readVarint();
if (version > 1 && totalTX > 0) {
p.read32();
p.readU32(); // Technically signed
inCount = p.readVarint();
if (inCount === 0) {
@ -505,7 +505,7 @@ Parser.parseTX = function parseTX(p) {
if (Parser.isWitnessTX(p))
return Parser.parseWitnessTX(p);
version = p.readU32();
version = p.readU32(); // Technically signed
inCount = p.readVarint();
txIn = new Array(inCount);
@ -565,13 +565,14 @@ Parser.parseWitnessTX = function parseWitnessTX(p) {
p = new BufferReader(p);
p.start();
version = p.readU32();
version = p.readU32(); // Technically signed
marker = p.readU8();
flag = p.readU8();
if (marker !== 0)
throw new Error('Invalid witness tx (marker != 0)');
flag = p.readU8();
if (flag === 0)
throw new Error('Invalid witness tx (flag == 0)');

View File

@ -804,7 +804,7 @@ TX.prototype.isSane = function isSane(ret) {
};
// IsStandardTx
TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
TX.prototype.isStandard = function isStandard(flags, ret) {
var i, input, output, type;
var nulldata = 0;
var maxVersion = constants.tx.version;
@ -815,21 +815,11 @@ TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
if (flags == null)
flags = constants.flags.STANDARD_VERIFY_FLAGS;
if (flags & constants.flags.VERIFY_CHECKSEQUENCEVERIFY)
maxVersion = Math.max(maxVersion, 2);
if ((this.version >>> 0) < 1 || (this.version >>> 0) > maxVersion) {
if (this.version < 1 || this.version > constants.tx.version) {
ret.reason = 'version';
return false;
}
if (ts != null) {
if (!this.isFinal(ts, height)) {
ret.reason = 'non-final';
return false;
}
}
if (this.getVirtualSize() > constants.tx.maxSize) {
ret.reason = 'tx-size';
return false;
@ -843,7 +833,7 @@ TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
return false;
}
// XXX Not accurate
// Not accurate
if (this.isCoinbase())
continue;