diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 4e0e69f9..d9f9f98a 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -52,11 +52,12 @@ function Chain(options) { this.fromJSON(require('./protocol/preload-full')); this.storage = null; - //this.resetHeight(133000); - //this.resetHeight(145000); - this.resetHeight(350000); - if (0) + // this.resetHeight(133000); + // this.resetHeight(145000); + // this.resetHeight(350000); + + // if (0) this.fromJSON({ v: 2, type: 'chain', @@ -73,6 +74,7 @@ function Chain(options) { ] }); + // if (0) if (!this.options.fullNode) this.fromJSON(network.preload); @@ -281,7 +283,7 @@ Chain.prototype.resetTime = function resetTime(ts) { Chain.prototype.add = function add(block, peer) { var initial = block; var code = Chain.codes.unchanged; - var hash, prevHash, prevHeight, entry; + var hash, prevHash, prevHeight, entry, tip; if (this.loading) { this.once('load', function() { @@ -351,22 +353,29 @@ Chain.prototype.add = function add(block, peer) { code = Chain.codes.unchanged; break; } + // Get _our_ tip as opposed to + // the attempted alternate tip. + tip = this.index.entries[entry.height]; // The block has equal chainwork (an // alternate tip). Reset the chain, find // a new peer, and wait to see who wins. this.resetHeight(entry.height - 1); - this.emit('fork', entry.height, entry.hash); + this.emit('fork', { + height: prevHeight + 1, + blocks: [tip.hash, entry.hash], + checkpoint: null + }); code = Chain.codes.forked; break; } // Do "contextual" verification on our block - // now that we're certain it's previous + // now that we're certain its previous // block is in the chain. if (!block.postVerify()) { throw new Error; - //code = Chain.codes.invalid; - //break; + code = Chain.codes.invalid; + break; } // Attempt to add block to the chain index. diff --git a/lib/bcoin/hd.js b/lib/bcoin/hd.js index 44431600..c5952c54 100644 --- a/lib/bcoin/hd.js +++ b/lib/bcoin/hd.js @@ -592,7 +592,7 @@ HDPublicKey.prototype.deriveString = function deriveString(path) { }; HD.prototype.getPrivate = function getPrivate() { - return this.pair.getPublic.apply(this.pair, arguments); + return this.pair.getPrivate.apply(this.pair, arguments); }; HD.prototype.sign = function sign(msg) {