mempool requireStandard defaults and miner block version.

This commit is contained in:
Christopher Jeffrey 2016-04-19 21:07:53 -07:00
parent c95681ae3f
commit 4d7124830a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 46 additions and 8 deletions

View File

@ -78,7 +78,9 @@ function Mempool(options) {
this.limitFree = this.options.limitFree !== false;
this.limitFreeRelay = this.options.limitFreeRelay || 15;
this.relayPriority = this.options.relayPriority !== false;
this.requireStandard = this.options.requireStandard !== false;
this.requireStandard = this.options.requireStandard != null
? this.options.requireStandard
: network.requireStandard;
this.rejectInsaneFees = this.options.rejectInsaneFees !== false;
// Use an in-memory binary search tree by default

View File

@ -146,9 +146,10 @@ Miner.prototype._init = function _init() {
/**
* Start mining.
* @param {Number?} version - Custom block version.
*/
Miner.prototype.start = function start() {
Miner.prototype.start = function start(version) {
var self = this;
this.stop();
@ -156,7 +157,7 @@ Miner.prototype.start = function start() {
this.running = true;
// Create a new block and start hashing
this.createBlock(function(err, attempt) {
this.createBlock(version, function(err, attempt) {
if (err)
return self.emit('error', err);
@ -212,19 +213,31 @@ Miner.prototype.stop = function stop() {
/**
* Create a block "attempt".
* @param {Number?} version - Custom block version.
* @param {Function} callback - Returns [Error, {@link MinerBlock}].
*/
Miner.prototype.createBlock = function createBlock(callback) {
Miner.prototype.createBlock = function createBlock(version, callback) {
var self = this;
var ts = Math.max(bcoin.now(), this.chain.tip.ts + 1);
var attempt;
if (typeof version === 'function') {
callback = version;
version = null;
}
function computeVersion(callback) {
if (version != null)
return callback(null, version);
self.chain.computeBlockVersion(self.chain.tip, callback);
}
if (!this.loaded) {
this.open(function(err) {
if (err)
return callback(err);
self.createBlock(callback);
self.createBlock(version, callback);
});
return;
}
@ -237,7 +250,7 @@ Miner.prototype.createBlock = function createBlock(callback) {
return callback(err);
// Calculate version with versionbits
self.chain.computeBlockVersion(self.chain.tip, function(err, version) {
computeVersion(function(err, version) {
if (err)
return callback(err);
@ -285,14 +298,20 @@ Miner.prototype.createBlock = function createBlock(callback) {
/**
* Mine a single block.
* @param {Number?} version - Custom block version.
* @param {Function} callback - Returns [Error, [{@link Block}]].
*/
Miner.prototype.mineBlock = function mineBlock(callback) {
Miner.prototype.mineBlock = function mineBlock(version, callback) {
var self = this;
if (typeof version === 'function') {
callback = version;
version = null;
}
// Create a new block and start hashing
this.createBlock(function(err, attempt) {
this.createBlock(version, function(err, attempt) {
if (err)
return callback(err);

View File

@ -401,6 +401,15 @@ main.address.prefixesByVal = utils.revMap(main.address.prefixes);
main.address.versionsByVal = utils.revMap(main.address.versions);
/**
* Default value for whether the mempool
* accepts non-standard transactions.
* @const {Boolean}
* @default
*/
main.requireStandard = true;
/*
* Testnet (v3)
* https://en.bitcoin.it/wiki/Testnet
@ -534,6 +543,8 @@ testnet.address = {
testnet.address.prefixesByVal = utils.revMap(testnet.address.prefixes);
testnet.address.versionsByVal = utils.revMap(testnet.address.versions);
testnet.requireStandard = false;
/*
* Regtest
*/
@ -659,6 +670,8 @@ regtest.address = {
regtest.address.prefixesByVal = utils.revMap(regtest.address.prefixes);
regtest.address.versionsByVal = utils.revMap(regtest.address.versions);
regtest.requireStandard = false;
/*
* segnet3
*/
@ -767,6 +780,8 @@ segnet3.address = {
segnet3.address.prefixesByVal = utils.revMap(segnet3.address.prefixes);
segnet3.address.versionsByVal = utils.revMap(segnet3.address.versions);
segnet3.requireStandard = false;
/*
* segnet4
*/
@ -888,3 +903,5 @@ segnet4.address = {
segnet4.address.prefixesByVal = utils.revMap(segnet4.address.prefixes);
segnet4.address.versionsByVal = utils.revMap(segnet4.address.versions);
segnet4.requireStandard = false;