pool: disable checkpoints properly. rename prop for consistency.
This commit is contained in:
parent
e7413aabb7
commit
c44fc3bcef
@ -110,7 +110,7 @@ function Pool(options) {
|
|||||||
this.pendingFilter = null;
|
this.pendingFilter = null;
|
||||||
this.pendingRefill = null;
|
this.pendingRefill = null;
|
||||||
|
|
||||||
this.headersFirst = false;
|
this.checkpoints = false;
|
||||||
this.headerChain = new List();
|
this.headerChain = new List();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
@ -233,13 +233,15 @@ Pool.prototype.resetChain = function resetChain() {
|
|||||||
if (!this.options.checkpoints)
|
if (!this.options.checkpoints)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.headersFirst = false;
|
this.checkpoints = false;
|
||||||
|
this.chain.checkpoints = false;
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
|
|
||||||
if (tip.height < this.network.lastCheckpoint) {
|
if (tip.height < this.network.lastCheckpoint) {
|
||||||
this.headersFirst = true;
|
this.checkpoints = true;
|
||||||
|
this.chain.checkpoints = true;
|
||||||
this.headerTip = this.getNextTip(tip.height);
|
this.headerTip = this.getNextTip(tip.height);
|
||||||
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
|
this.headerChain.push(new HeaderEntry(tip.hash, tip.height));
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
@ -364,7 +366,8 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
|||||||
this.pendingRefill = null;
|
this.pendingRefill = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.headersFirst = false;
|
this.checkpoints = false;
|
||||||
|
this.chain.checkpoints = false;
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
@ -616,11 +619,6 @@ Pool.prototype.sendSync = co(function* sendSync(peer) {
|
|||||||
peer.syncing = true;
|
peer.syncing = true;
|
||||||
peer.blockTime = util.ms();
|
peer.blockTime = util.ms();
|
||||||
|
|
||||||
if (this.headersFirst) {
|
|
||||||
peer.sendGetHeaders([tip.hash], this.headerTip.hash);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
locator = yield this.chain.getLocator();
|
locator = yield this.chain.getLocator();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -628,6 +626,11 @@ Pool.prototype.sendSync = co(function* sendSync(peer) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.checkpoints) {
|
||||||
|
peer.sendGetHeaders(locator, this.headerTip.hash);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
peer.sendGetBlocks(locator);
|
peer.sendGetBlocks(locator);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1396,7 +1399,7 @@ Pool.prototype.handleBlockInv = co(function* handleBlockInv(peer, hashes) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Request headers instead.
|
// Request headers instead.
|
||||||
if (this.headersFirst)
|
if (this.checkpoints)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
@ -1751,7 +1754,7 @@ Pool.prototype._handleHeaders = co(function* handleHeaders(peer, packet) {
|
|||||||
var checkpoint = false;
|
var checkpoint = false;
|
||||||
var i, header, hash, height, last, node;
|
var i, header, hash, height, last, node;
|
||||||
|
|
||||||
if (!this.headersFirst)
|
if (!this.checkpoints)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.syncing)
|
if (!this.syncing)
|
||||||
@ -1926,7 +1929,7 @@ Pool.prototype._addBlock = co(function* addBlock(peer, block) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.type === 'VerifyError') {
|
if (err.type === 'VerifyError') {
|
||||||
if (err.reason === 'bad-prevblk') {
|
if (err.reason === 'bad-prevblk') {
|
||||||
if (this.headersFirst) {
|
if (this.checkpoints) {
|
||||||
peer.increaseBan(10);
|
peer.increaseBan(10);
|
||||||
this.emit('error', err, peer);
|
this.emit('error', err, peer);
|
||||||
return;
|
return;
|
||||||
@ -1958,7 +1961,7 @@ Pool.prototype._addBlock = co(function* addBlock(peer, block) {
|
|||||||
Pool.prototype.resolveChain = co(function* resolveChain(peer, hash) {
|
Pool.prototype.resolveChain = co(function* resolveChain(peer, hash) {
|
||||||
var node = this.headerChain.head;
|
var node = this.headerChain.head;
|
||||||
|
|
||||||
if (!this.headersFirst)
|
if (!this.checkpoints)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!peer.loader)
|
if (!peer.loader)
|
||||||
@ -2016,10 +2019,10 @@ Pool.prototype.resolveChain = co(function* resolveChain(peer, hash) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.switchSync = co(function* switchSync(peer, hash) {
|
Pool.prototype.switchSync = co(function* switchSync(peer, hash) {
|
||||||
assert(this.headersFirst);
|
assert(this.checkpoints);
|
||||||
|
|
||||||
|
this.checkpoints = false;
|
||||||
this.chain.checkpoints = false;
|
this.chain.checkpoints = false;
|
||||||
this.headersFirst = false;
|
|
||||||
this.headerTip = null;
|
this.headerTip = null;
|
||||||
this.headerChain.reset();
|
this.headerChain.reset();
|
||||||
this.headerNext = null;
|
this.headerNext = null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user