chain: minor.

This commit is contained in:
Christopher Jeffrey 2017-08-02 00:19:24 -07:00
parent a085214d54
commit a76442acde
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 5 additions and 4 deletions

View File

@ -77,7 +77,7 @@ function Chain(options) {
this.invalid = new LRU(100); this.invalid = new LRU(100);
this.state = new DeploymentState(); this.state = new DeploymentState();
this.tip = null; this.tip = new ChainEntry(this);
this.height = -1; this.height = -1;
this.synced = false; this.synced = false;
@ -1827,7 +1827,7 @@ Chain.prototype.maybeSync = function maybeSync() {
*/ */
Chain.prototype.hasChainwork = function hasChainwork() { Chain.prototype.hasChainwork = function hasChainwork() {
return this.tip.chainwork.cmp(this.network.pow.chainwork) >= 0; return this.tip.chainwork.gte(this.network.pow.chainwork);
}; };
/** /**
@ -1838,7 +1838,7 @@ Chain.prototype.hasChainwork = function hasChainwork() {
*/ */
Chain.prototype.hasCheckpoints = function hasCheckpoints() { Chain.prototype.hasCheckpoints = function hasCheckpoints() {
return this.tip.chainwork.cmp(this.network.lastChainwork) >= 0; return this.tip.chainwork.gte(this.network.lastChainwork);
}; };
/** /**

View File

@ -17,6 +17,7 @@ const BufferReader = require('../utils/reader');
const StaticWriter = require('../utils/staticwriter'); const StaticWriter = require('../utils/staticwriter');
const Headers = require('../primitives/headers'); const Headers = require('../primitives/headers');
const InvItem = require('../primitives/invitem'); const InvItem = require('../primitives/invitem');
const ZERO = new BN(0);
/** /**
* Represents an entry in the chain. Unlike * Represents an entry in the chain. Unlike
@ -56,7 +57,7 @@ function ChainEntry(chain, options, prev) {
this.bits = 0; this.bits = 0;
this.nonce = 0; this.nonce = 0;
this.height = -1; this.height = -1;
this.chainwork = null; this.chainwork = ZERO;
if (options) if (options)
this.fromOptions(options, prev); this.fromOptions(options, prev);