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;
if (this.options.spv)
return new this.db.CoinView();
return new CoinView();
if (this.isGenesis(block))
return new this.db.CoinView();
return new CoinView();
view = yield this.db.getCoinView(block);

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ describe('Chain', function() {
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' });
chain = node.chain;
walletdb = node.walletdb;
@ -55,13 +55,6 @@ describe('Chain', function() {
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* () {
miner.mempool = null;
constants.tx.COINBASE_MATURITY = 0;