more standardness.
This commit is contained in:
parent
0720c6c64a
commit
945c2f9564
@ -393,7 +393,7 @@ Block.prototype.toCompact = function toCompact() {
|
|||||||
Block.fromCompact = function fromCompact(buf) {
|
Block.fromCompact = function fromCompact(buf) {
|
||||||
var p = new BufferReader(buf);
|
var p = new BufferReader(buf);
|
||||||
var hashes = [];
|
var hashes = [];
|
||||||
var version = p.read32();
|
var version = p.readU32(); // Technically signed
|
||||||
var prevBlock = p.readHash('hex');
|
var prevBlock = p.readHash('hex');
|
||||||
var merkleRoot = p.readHash('hex');
|
var merkleRoot = p.readHash('hex');
|
||||||
var ts = p.readU32();
|
var ts = p.readU32();
|
||||||
|
|||||||
@ -247,7 +247,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
hash: utils.toHex(hash),
|
hash: utils.toHex(hash),
|
||||||
version: p.read32(),
|
version: p.readU32(), // Technically signed
|
||||||
prevBlock: p.readHash('hex'),
|
prevBlock: p.readHash('hex'),
|
||||||
merkleRoot: p.readHash('hex'),
|
merkleRoot: p.readHash('hex'),
|
||||||
ts: p.readU32(),
|
ts: p.readU32(),
|
||||||
|
|||||||
@ -267,7 +267,7 @@ ChainBlock.fromRaw = function fromRaw(chain, buf) {
|
|||||||
|
|
||||||
return new ChainBlock(chain, {
|
return new ChainBlock(chain, {
|
||||||
hash: utils.toHex(hash),
|
hash: utils.toHex(hash),
|
||||||
version: p.read32(),
|
version: p.readU32(), // Technically signed
|
||||||
prevBlock: p.readHash('hex'),
|
prevBlock: p.readHash('hex'),
|
||||||
merkleRoot: p.readHash('hex'),
|
merkleRoot: p.readHash('hex'),
|
||||||
ts: p.readU32(),
|
ts: p.readU32(),
|
||||||
|
|||||||
@ -308,11 +308,17 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
|
|||||||
|
|
||||||
hash = tx.hash('hex');
|
hash = tx.hash('hex');
|
||||||
|
|
||||||
assert(tx.ts === 0);
|
|
||||||
|
|
||||||
callback = utils.wrap(callback, unlock);
|
callback = utils.wrap(callback, unlock);
|
||||||
callback = utils.asyncify(callback);
|
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 (!this.chain.segwitActive) {
|
||||||
if (tx.hasWitness()) {
|
if (tx.hasWitness()) {
|
||||||
peer.sendReject(tx, 'nonstandard', 'no-witness-yet', 0);
|
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));
|
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) {
|
if (this.requireStandard) {
|
||||||
ts = utils.now();
|
if (!tx.isStandard(flags, ret)) {
|
||||||
height = this.chain.height + 1;
|
|
||||||
if (!tx.isStandard(flags, ts, height, ret)) {
|
|
||||||
peer.sendReject(tx, 'nonstandard', ret.reason, 0);
|
peer.sendReject(tx, 'nonstandard', ret.reason, 0);
|
||||||
return callback(new VerifyError(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 minTime = -1;
|
||||||
var coinHeight;
|
var coinHeight;
|
||||||
|
|
||||||
if ((tx.version >>> 0) < 2 || !hasFlag)
|
if (tx.version < 2 || !hasFlag)
|
||||||
return utils.asyncify(callback)(null, minHeight, minTime);
|
return utils.asyncify(callback)(null, minHeight, minTime);
|
||||||
|
|
||||||
utils.forEachSerial(tx.inputs, function(input, next) {
|
utils.forEachSerial(tx.inputs, function(input, next) {
|
||||||
|
|||||||
@ -251,7 +251,7 @@ Parser.parseMerkleBlock = function parseMerkleBlock(p) {
|
|||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|
||||||
version = p.read32();
|
version = p.readU32(); // Technically signed
|
||||||
prevBlock = p.readHash();
|
prevBlock = p.readHash();
|
||||||
merkleRoot = p.readHash();
|
merkleRoot = p.readHash();
|
||||||
ts = p.readU32();
|
ts = p.readU32();
|
||||||
@ -293,7 +293,7 @@ Parser.parseHeaders = function parseHeaders(p) {
|
|||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
headers.push({
|
headers.push({
|
||||||
version: p.read32(),
|
version: p.readU32(), // Technically signed
|
||||||
prevBlock: p.readHash(),
|
prevBlock: p.readHash(),
|
||||||
merkleRoot: p.readHash(),
|
merkleRoot: p.readHash(),
|
||||||
ts: p.readU32(),
|
ts: p.readU32(),
|
||||||
@ -317,7 +317,7 @@ Parser.parseBlock = function parseBlock(p) {
|
|||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|
||||||
version = p.read32();
|
version = p.readU32(); // Technically signed
|
||||||
prevBlock = p.readHash();
|
prevBlock = p.readHash();
|
||||||
merkleRoot = p.readHash();
|
merkleRoot = p.readHash();
|
||||||
ts = p.readU32();
|
ts = p.readU32();
|
||||||
@ -352,7 +352,7 @@ Parser.parseBlockCompact = function parseBlockCompact(p) {
|
|||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|
||||||
version = p.read32();
|
version = p.readU32(); // Technically signed
|
||||||
prevBlock = p.readHash();
|
prevBlock = p.readHash();
|
||||||
merkleRoot = p.readHash();
|
merkleRoot = p.readHash();
|
||||||
ts = p.readU32();
|
ts = p.readU32();
|
||||||
@ -362,7 +362,7 @@ Parser.parseBlockCompact = function parseBlockCompact(p) {
|
|||||||
totalTX = p.readVarint();
|
totalTX = p.readVarint();
|
||||||
|
|
||||||
if (version > 1 && totalTX > 0) {
|
if (version > 1 && totalTX > 0) {
|
||||||
p.read32();
|
p.readU32(); // Technically signed
|
||||||
inCount = p.readVarint();
|
inCount = p.readVarint();
|
||||||
|
|
||||||
if (inCount === 0) {
|
if (inCount === 0) {
|
||||||
@ -505,7 +505,7 @@ Parser.parseTX = function parseTX(p) {
|
|||||||
if (Parser.isWitnessTX(p))
|
if (Parser.isWitnessTX(p))
|
||||||
return Parser.parseWitnessTX(p);
|
return Parser.parseWitnessTX(p);
|
||||||
|
|
||||||
version = p.readU32();
|
version = p.readU32(); // Technically signed
|
||||||
inCount = p.readVarint();
|
inCount = p.readVarint();
|
||||||
|
|
||||||
txIn = new Array(inCount);
|
txIn = new Array(inCount);
|
||||||
@ -565,13 +565,14 @@ Parser.parseWitnessTX = function parseWitnessTX(p) {
|
|||||||
p = new BufferReader(p);
|
p = new BufferReader(p);
|
||||||
p.start();
|
p.start();
|
||||||
|
|
||||||
version = p.readU32();
|
version = p.readU32(); // Technically signed
|
||||||
marker = p.readU8();
|
marker = p.readU8();
|
||||||
flag = p.readU8();
|
|
||||||
|
|
||||||
if (marker !== 0)
|
if (marker !== 0)
|
||||||
throw new Error('Invalid witness tx (marker != 0)');
|
throw new Error('Invalid witness tx (marker != 0)');
|
||||||
|
|
||||||
|
flag = p.readU8();
|
||||||
|
|
||||||
if (flag === 0)
|
if (flag === 0)
|
||||||
throw new Error('Invalid witness tx (flag == 0)');
|
throw new Error('Invalid witness tx (flag == 0)');
|
||||||
|
|
||||||
|
|||||||
@ -804,7 +804,7 @@ TX.prototype.isSane = function isSane(ret) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// IsStandardTx
|
// IsStandardTx
|
||||||
TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
|
TX.prototype.isStandard = function isStandard(flags, ret) {
|
||||||
var i, input, output, type;
|
var i, input, output, type;
|
||||||
var nulldata = 0;
|
var nulldata = 0;
|
||||||
var maxVersion = constants.tx.version;
|
var maxVersion = constants.tx.version;
|
||||||
@ -815,21 +815,11 @@ TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
|
|||||||
if (flags == null)
|
if (flags == null)
|
||||||
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
flags = constants.flags.STANDARD_VERIFY_FLAGS;
|
||||||
|
|
||||||
if (flags & constants.flags.VERIFY_CHECKSEQUENCEVERIFY)
|
if (this.version < 1 || this.version > constants.tx.version) {
|
||||||
maxVersion = Math.max(maxVersion, 2);
|
|
||||||
|
|
||||||
if ((this.version >>> 0) < 1 || (this.version >>> 0) > maxVersion) {
|
|
||||||
ret.reason = 'version';
|
ret.reason = 'version';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ts != null) {
|
|
||||||
if (!this.isFinal(ts, height)) {
|
|
||||||
ret.reason = 'non-final';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getVirtualSize() > constants.tx.maxSize) {
|
if (this.getVirtualSize() > constants.tx.maxSize) {
|
||||||
ret.reason = 'tx-size';
|
ret.reason = 'tx-size';
|
||||||
return false;
|
return false;
|
||||||
@ -843,7 +833,7 @@ TX.prototype.isStandard = function isStandard(flags, ts, height, ret) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX Not accurate
|
// Not accurate
|
||||||
if (this.isCoinbase())
|
if (this.isCoinbase())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user