diff --git a/README.md b/README.md index cd41e570..d2b586c4 100644 --- a/README.md +++ b/README.md @@ -273,9 +273,7 @@ pool.open().then(function() { var bcoin = require('bcoin').set('main'); var node = bcoin.fullnode({ - prune: false, - useCheckpoints: true, - debug: true, + checkpoints: true, // Primary wallet passphrase passsphrase: 'node', logLevel: 'info' diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 1b9f25d6..f9153613 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -176,7 +176,7 @@ Chain.prototype._open = co(function* open() { this.logger.info('Chain is loading.'); - if (this.options.useCheckpoints) + if (this.options.checkpoints) this.logger.info('Checkpoints are enabled.'); if (this.options.coinCache) @@ -566,7 +566,7 @@ Chain.prototype.verifyDuplicates = co(function* verifyDuplicates(block, prev, st * function will check the block reward, the sigops, * the tx values, and execute and verify the scripts (it * will attempt to do this on the worker pool). If - * useCheckpoints is enabled, it will skip verification + * `checkpoints` is enabled, it will skip verification * for historical data. * @private * @see TX#checkInputs @@ -1344,7 +1344,7 @@ Chain.prototype.verifyCheckpoint = function verifyCheckpoint(prev, hash) { var height = prev.height + 1; var checkpoint; - if (!this.options.useCheckpoints) + if (!this.options.checkpoints) return true; checkpoint = this.network.checkpointMap[height]; @@ -1682,7 +1682,7 @@ Chain.prototype.isFull = function isFull() { */ Chain.prototype.isInitial = function isInitial() { - if (this.options.useCheckpoints) { + if (this.options.checkpoints) { if (this.height < this.network.lastCheckpoint) return true; } @@ -1716,7 +1716,7 @@ Chain.prototype.maybeSync = function maybeSync() { */ Chain.prototype.hasChainwork = function hasChainwork() { - if (this.options.useCheckpoints) + if (this.options.checkpoints) return this.height >= this.network.lastCheckpoint; return this.tip.chainwork.cmp(this.network.pow.chainwork) >= 0; @@ -2313,7 +2313,7 @@ function ChainOptions(options) { this.coinCache = 0; this.entryCache = (2016 + 1) * 2 + 100; this.orphanLimit = 20 << 20; - this.useCheckpoints = false; + this.checkpoints = false; if (options) this.fromOptions(options); @@ -2405,9 +2405,9 @@ ChainOptions.prototype.fromOptions = function fromOptions(options) { this.orphanLimit = options.orphanLimit; } - if (options.useCheckpoints != null) { - assert(typeof options.useCheckpoints === 'boolean'); - this.useCheckpoints = options.useCheckpoints; + if (options.checkpoints != null) { + assert(typeof options.checkpoints === 'boolean'); + this.checkpoints = options.checkpoints; } return this; diff --git a/lib/blockchain/chainentry.js b/lib/blockchain/chainentry.js index 1041a03c..edc1d7ce 100644 --- a/lib/blockchain/chainentry.js +++ b/lib/blockchain/chainentry.js @@ -353,7 +353,7 @@ ChainEntry.prototype.getMedianTimeAsync = co(function* getMedianTimeAsync() { */ ChainEntry.prototype.isHistorical = function isHistorical() { - if (this.chain.options.useCheckpoints) { + if (this.chain.options.checkpoints) { if (this.height + 1 <= this.chain.network.lastCheckpoint) return true; } diff --git a/lib/http/server.js b/lib/http/server.js index 15f628df..c9a74e6a 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -10,11 +10,12 @@ /* jshint -W069 */ /* jshint noyield: true */ -var EventEmitter = require('events').EventEmitter; var assert = require('assert'); +var EventEmitter = require('events').EventEmitter; var HTTPBase = require('./base'); var util = require('../utils/util'); var co = require('../utils/co'); +var IP = require('../utils/ip'); var base58 = require('../utils/base58'); var Amount = require('../btc/amount'); var Address = require('../primitives/address'); @@ -1782,6 +1783,13 @@ HTTPOptions.prototype.fromOptions = function fromOptions(options) { this.ca = options.ca; } + // Allow no-auth implicitly + // if we're listening locally. + if (!options.apiKey && !options.serviceKey) { + if (IP.isLoopback(this.host)) + this.noAuth = true; + } + return this; }; diff --git a/lib/net/pool.js b/lib/net/pool.js index ecb70376..22e7a141 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -689,7 +689,7 @@ Pool.prototype.resolveHeaders = function resolveHeaders(peer) { Pool.prototype.getNextTip = function getNextTip(height) { var i, next; - if (this.options.useCheckpoints) { + if (this.options.checkpoints) { for (i = 0; i < this.network.checkpoints.length; i++) { next = this.network.checkpoints[i]; if (next.height > height) @@ -1803,7 +1803,7 @@ Pool.prototype._handleHeaders = co(function* handleHeaders(peer, packet) { node = new HeaderEntry(hash, height); if (node.height === this.headerTip.height) { - if (this.options.useCheckpoints) { + if (this.options.checkpoints) { if (node.hash !== this.headerTip.hash) { this.logger.warning( 'Peer sent an invalid checkpoint (%s).', @@ -3164,7 +3164,7 @@ function PoolOptions(options) { this.address = new NetAddress(); this.witness = true; - this.useCheckpoints = false; + this.checkpoints = false; this.spv = false; this.listen = false; this.headers = false; @@ -3236,12 +3236,12 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) { this.witness = this.chain.options.witness; } - if (options.useCheckpoints != null) { - assert(typeof options.useCheckpoints === 'boolean'); - assert(options.useCheckpoints === this.chain.options.useCheckpoints); - this.useCheckpoints = options.useCheckpoints; + if (options.checkpoints != null) { + assert(typeof options.checkpoints === 'boolean'); + assert(options.checkpoints === this.chain.options.checkpoints); + this.checkpoints = options.checkpoints; } else { - this.useCheckpoints = this.chain.options.useCheckpoints; + this.checkpoints = this.chain.options.checkpoints; } if (options.spv != null) { diff --git a/lib/node/config.js b/lib/node/config.js index 96c08dd9..22705c6f 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -174,11 +174,14 @@ config.parseData = function parseData(data, prefix, dirname) { options.witness = bool(data.witness); options.forceWitness = bool(data.forcewitness); options.prune = bool(data.prune); - options.useCheckpoints = bool(data.usecheckpoints); + options.checkpoints = bool(data.checkpoints); options.coinCache = mul(data.coincache, 1024 * 1024); options.indexTX = bool(data.indextx); options.indexAddress = bool(data.indexaddress); + if (data.usecheckpoints != null) + options.checkpoints = bool(data.usecheckpoints); + // Mempool options.limitFree = bool(data.limitfree); options.limitFreeRelay = bool(data.limitfreerelay); @@ -235,7 +238,7 @@ config.parseData = function parseData(data, prefix, dirname) { // Alias if (options.fast) { options.headers = true; - options.useCheckpoints = true; + options.checkpoints = true; options.cacheSize = 200 << 20; options.coinCache = 65 << 20; } diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index e4320185..44ee1ba9 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -69,7 +69,7 @@ function FullNode(options) { witness: this.options.witness, forceWitness: this.options.forceWitness, prune: this.options.prune, - useCheckpoints: this.options.useCheckpoints, + checkpoints: this.options.checkpoints, coinCache: this.options.coinCache, indexTX: this.options.indexTX, indexAddress: this.options.indexAddress @@ -142,7 +142,7 @@ function FullNode(options) { maxFiles: this.options.walletMaxFiles, cacheSize: this.options.walletCacheSize, witness: false, - useCheckpoints: this.options.useCheckpoints, + checkpoints: this.options.checkpoints, startHeight: this.options.startHeight, wipeNoReally: this.options.wipeNoReally, verify: false diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index 0f1b7fc5..bd685c89 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -53,7 +53,7 @@ function SPVNode(options) { cacheSize: this.options.cacheSize, witness: this.options.witness, forceWitness: this.options.forceWitness, - useCheckpoints: this.options.useCheckpoints, + checkpoints: this.options.checkpoints, spv: true }); @@ -85,7 +85,7 @@ function SPVNode(options) { maxFiles: this.options.walletMaxFiles, cacheSize: this.options.walletCacheSize, witness: false, - useCheckpoints: this.options.useCheckpoints, + checkpoints: this.options.checkpoints, startHeight: this.options.startHeight, wipeNoReally: this.options.wipeNoReally, verify: true, diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 42beda82..6370f749 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -1919,7 +1919,7 @@ WalletDB.prototype._addBlock = co(function* addBlock(entry, txs) { // Sync the state to the new tip. yield this.syncState(tip); - if (this.options.useCheckpoints) { + if (this.options.checkpoints) { if (tip.height <= this.network.lastCheckpoint) return total; } @@ -2169,7 +2169,7 @@ function WalletOptions(options) { this.spv = false; this.witness = false; - this.useCheckpoints = false; + this.checkpoints = false; this.startHeight = 0; this.keepBlocks = this.network.block.keepBlocks; this.wipeNoReally = false; @@ -2236,9 +2236,9 @@ WalletOptions.prototype.fromOptions = function fromOptions(options) { this.witness = options.witness; } - if (options.useCheckpoints != null) { - assert(typeof options.useCheckpoints === 'boolean'); - this.useCheckpoints = options.useCheckpoints; + if (options.checkpoints != null) { + assert(typeof options.checkpoints === 'boolean'); + this.checkpoints = options.checkpoints; } if (options.startHeight != null) {