walletdb: setLookahead.

This commit is contained in:
Christopher Jeffrey 2016-11-07 23:43:29 -08:00
parent 619143156b
commit 0825007c3d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -218,7 +218,7 @@ Account.fromOptions = function fromOptions(db, options) {
* @const {Number}
*/
Account.MAX_LOOKAHEAD = 50;
Account.MAX_LOOKAHEAD = 40;
/**
* Attempt to intialize the account (generating
@ -726,15 +726,36 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) {
*/
Account.prototype.setLookahead = co(function* setLookahead(lookahead) {
var i, key, depth, target;
var i, diff, key, depth, target;
if (lookahead <= this.lookahead) {
if (lookahead === this.lookahead) {
this.db.logger.warning(
'Lookahead is not increasing for: %s/%s.',
'Lookahead is not changing for: %s/%s.',
this.id, this.name);
return;
}
if (lookahead < this.lookahead) {
diff = this.lookahead - lookahead;
this.receiveDepth += diff;
this.receive = this.deriveReceive(this.receiveDepth - 1);
this.changeDepth += diff;
this.change = this.deriveChange(this.changeDepth - 1);
if (this.witness) {
this.nestedDepth += diff;
this.nested = this.deriveNested(this.nestedDepth - 1);
}
this.lookahead = lookahead;
this.save();
return;
}
depth = this.receiveDepth + this.lookahead
target = this.receiveDepth + lookahead;