chain: drop newCoins option.

This commit is contained in:
Christopher Jeffrey 2016-11-29 21:01:48 -08:00
parent cc252b949d
commit e7bcbbb976
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
5 changed files with 10 additions and 40 deletions

View File

@ -626,10 +626,10 @@ Chain.prototype.verifyInputs = co(function* verifyInputs(block, prev, state) {
var i, view, tx, valid; var i, view, tx, valid;
if (this.options.spv) if (this.options.spv)
return new this.db.CoinView(); return new CoinView();
if (this.isGenesis(block)) if (this.isGenesis(block))
return new this.db.CoinView(); return new CoinView();
view = yield this.db.getCoinView(block); view = yield this.db.getCoinView(block);

View File

@ -19,8 +19,6 @@ var co = require('../utils/co');
var Network = require('../protocol/network'); var Network = require('../protocol/network');
var CoinView = require('./coinview'); var CoinView = require('./coinview');
var Coins = require('./coins'); var Coins = require('./coins');
var CoinViewOld = require('./coinview-old');
var CoinsOld = require('./coins-old');
var LDB = require('../db/ldb'); var LDB = require('../db/ldb');
var layout = require('./layout'); var layout = require('./layout');
var LRU = require('../utils/lru'); var LRU = require('../utils/lru');
@ -61,9 +59,6 @@ function ChainDB(chain) {
this.network = chain.network; this.network = chain.network;
this.options = new ChainOptions(chain.options); this.options = new ChainOptions(chain.options);
this.CoinView = this.options.newCoins ? CoinView : CoinViewOld;
this.Coins = this.options.newCoins ? Coins : CoinsOld;
this.db = LDB({ this.db = LDB({
location: chain.options.location, location: chain.options.location,
db: chain.options.db, db: chain.options.db,
@ -123,7 +118,7 @@ ChainDB.prototype._open = co(function* open() {
yield this.db.open(); yield this.db.open();
yield this.db.checkVersion('V', 1); yield this.db.checkVersion('V', 2);
state = yield this.getState(); state = yield this.getState();
options = yield this.getOptions(); options = yield this.getOptions();
@ -154,7 +149,7 @@ ChainDB.prototype._open = co(function* open() {
entry = ChainEntry.fromBlock(this.chain, block); entry = ChainEntry.fromBlock(this.chain, block);
this.logger.info('Writing genesis block to ChainDB.'); this.logger.info('Writing genesis block to ChainDB.');
yield this.save(entry, block, new this.CoinView()); yield this.save(entry, block, new CoinView());
} }
this.logger.info('Chain successfully loaded.'); this.logger.info('Chain successfully loaded.');
@ -638,7 +633,7 @@ ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
coins = this.coinCache.get(hash); coins = this.coinCache.get(hash);
if (coins) if (coins)
return this.Coins.parseCoin(coins, hash, index); return Coins.parseCoin(coins, hash, index);
coins = yield this.db.get(layout.c(hash)); coins = yield this.db.get(layout.c(hash));
@ -648,7 +643,7 @@ ChainDB.prototype.getCoin = co(function* getCoin(hash, index) {
if (state === this.state) if (state === this.state)
this.coinCache.set(hash, coins); this.coinCache.set(hash, coins);
return this.Coins.parseCoin(coins, hash, index); return Coins.parseCoin(coins, hash, index);
}); });
/** /**
@ -667,7 +662,7 @@ ChainDB.prototype.getCoins = co(function* getCoins(hash) {
coins = this.coinCache.get(hash); coins = this.coinCache.get(hash);
if (coins) if (coins)
return this.Coins.fromRaw(coins, hash); return Coins.fromRaw(coins, hash);
coins = yield this.db.get(layout.c(hash)); coins = yield this.db.get(layout.c(hash));
@ -677,7 +672,7 @@ ChainDB.prototype.getCoins = co(function* getCoins(hash) {
if (state === this.state) if (state === this.state)
this.coinCache.set(hash, coins); this.coinCache.set(hash, coins);
return this.Coins.fromRaw(coins, hash); return Coins.fromRaw(coins, hash);
}); });
/** /**
@ -698,7 +693,7 @@ ChainDB.prototype.hasCoins = function hasCoins(hash) {
*/ */
ChainDB.prototype.getCoinView = co(function* getCoinView(block, callback) { ChainDB.prototype.getCoinView = co(function* getCoinView(block, callback) {
var view = new this.CoinView(); var view = new CoinView();
var prevout = block.getPrevout(); var prevout = block.getPrevout();
var i, prev, coins; var i, prev, coins;
@ -1841,7 +1836,6 @@ function ChainOptions(options) {
this.prune = false; this.prune = false;
this.indexTX = false; this.indexTX = false;
this.indexAddress = false; this.indexAddress = false;
this.newCoins = false;
this.forceWitness = false; this.forceWitness = false;
@ -1877,11 +1871,6 @@ ChainOptions.prototype.fromOptions = function fromOptions(options) {
this.indexAddress = options.indexAddress; this.indexAddress = options.indexAddress;
} }
if (options.newCoins != null) {
assert(typeof options.newCoins === 'boolean');
this.newCoins = options.newCoins;
}
if (options.forceWitness != null) { if (options.forceWitness != null) {
assert(typeof options.forceWitness === 'boolean'); assert(typeof options.forceWitness === 'boolean');
this.forceWitness = options.forceWitness; this.forceWitness = options.forceWitness;
@ -1929,12 +1918,6 @@ ChainOptions.prototype.verify = function verify(options) {
if (!this.indexAddress && options.indexAddress) if (!this.indexAddress && options.indexAddress)
throw new Error('Cannot retroactively disable address indexing.'); throw new Error('Cannot retroactively disable address indexing.');
if (this.newCoins && !options.newCoins)
throw new Error('Cannot retroactively enable new coin serialization.');
if (!this.newCoins && options.newCoins)
throw new Error('Cannot retroactively disable new coin serialization.');
}; };
ChainOptions.prototype.toRaw = function toRaw() { ChainOptions.prototype.toRaw = function toRaw() {
@ -1956,9 +1939,6 @@ ChainOptions.prototype.toRaw = function toRaw() {
if (this.indexAddress) if (this.indexAddress)
flags |= 1 << 4; flags |= 1 << 4;
if (this.newCoins)
flags |= 1 << 5;
bw.writeU32(this.network.magic); bw.writeU32(this.network.magic);
bw.writeU32(flags); bw.writeU32(flags);
bw.writeU32(0); bw.writeU32(0);
@ -1979,7 +1959,6 @@ ChainOptions.prototype.fromRaw = function fromRaw(data) {
this.prune = (flags & 4) !== 0; this.prune = (flags & 4) !== 0;
this.indexTX = (flags & 8) !== 0; this.indexTX = (flags & 8) !== 0;
this.indexAddress = (flags & 16) !== 0; this.indexAddress = (flags & 16) !== 0;
this.newCoins = (flags & 32) !== 0;
return this; return this;
}; };

View File

@ -167,7 +167,6 @@ config.parseData = function parseData(data, prefix, dirname) {
options.coinCache = num(data.coincache); options.coinCache = num(data.coincache);
options.indexTX = bool(data.indextx); options.indexTX = bool(data.indextx);
options.indexAddress = bool(data.indexaddress); options.indexAddress = bool(data.indexaddress);
options.newCoins = bool(data.newcoins);
// Mempool // Mempool
options.limitFree = bool(data.limitfree); options.limitFree = bool(data.limitfree);

View File

@ -74,7 +74,6 @@ function FullNode(options) {
coinCache: this.options.coinCache, coinCache: this.options.coinCache,
indexTX: this.options.indexTX, indexTX: this.options.indexTX,
indexAddress: this.options.indexAddress, indexAddress: this.options.indexAddress,
newCoins: this.options.newCoins,
maxFiles: this.options.maxFiles maxFiles: this.options.maxFiles
}); });

View File

@ -17,7 +17,7 @@ describe('Chain', function() {
this.timeout(5000); this.timeout(5000);
node = new bcoin.fullnode({ db: 'memory', apiKey: 'foo', newCoins: true }); node = new bcoin.fullnode({ db: 'memory', apiKey: 'foo' });
// node.walletdb.client = new Client({ apiKey: 'foo', network: 'regtest' }); // node.walletdb.client = new Client({ apiKey: 'foo', network: 'regtest' });
chain = node.chain; chain = node.chain;
walletdb = node.walletdb; walletdb = node.walletdb;
@ -55,13 +55,6 @@ describe('Chain', function() {
return yield attempt.mineAsync(); return yield attempt.mineAsync();
}); });
it('should use correct coin serialiation', function() {
assert(node.chain.db.CoinView === require('../lib/blockchain/coinview'));
assert(node.chain.db.Coins === require('../lib/blockchain/coins'));
assert(node.chain.db.CoinView !== require('../lib/blockchain/coinview-old'));
assert(node.chain.db.Coins !== require('../lib/blockchain/coins-old'));
});
it('should open chain and miner', cob(function* () { it('should open chain and miner', cob(function* () {
miner.mempool = null; miner.mempool = null;
constants.tx.COINBASE_MATURITY = 0; constants.tx.COINBASE_MATURITY = 0;