walletdb: switch back to lookahead of 10.

This commit is contained in:
Christopher Jeffrey 2016-11-07 16:47:51 -08:00
parent 93d2c8811f
commit 4fcb07ff5f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 24 additions and 14 deletions

View File

@ -67,7 +67,7 @@ function Account(db, options) {
this.receiveDepth = 0;
this.changeDepth = 0;
this.nestedDepth = 0;
this.lookahead = 5;
this.lookahead = 10;
this.accountKey = null;
this.keys = [];
@ -441,9 +441,9 @@ Account.prototype.createKey = co(function* createKey(branch) {
this.receive = key;
break;
case 1:
// Note: no lookahead here.
key = this.deriveChange(this.changeDepth);
yield this.saveKey(key);
lookahead = this.deriveReceive(this.changeDepth + this.lookahead);
yield this.saveKey(lookahead);
this.changeDepth++;
this.change = key;
break;
@ -621,12 +621,18 @@ Account.prototype.initDepth = co(function* initDepth() {
yield this.saveKey(key);
}
// Change Address (no lookahead)
// Change Address
this.change = this.deriveChange(0);
this.changeDepth = 1;
yield this.saveKey(this.change);
// Lookahead
for (i = 0; i < this.lookahead; i++) {
key = this.deriveChange(i + 1);
yield this.saveKey(key);
}
// Nested Address
if (this.witness) {
this.nested = this.deriveNested(0);
@ -660,7 +666,7 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) {
if (receive > this.receiveDepth) {
depth = this.receiveDepth + this.lookahead;
assert(this.lookahead === 0 || receive <= depth);
assert(receive <= depth + 1);
for (i = depth; i < receive + this.lookahead; i++) {
key = this.deriveReceive(i);
@ -675,12 +681,16 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) {
}
if (change > this.changeDepth) {
assert(change === this.changeDepth + 1);
depth = this.changeDepth + this.lookahead;
key = this.deriveChange(change - 1);
yield this.saveKey(key);
assert(change <= depth + 1);
this.change = key;
for (i = depth; i < change + this.lookahead; i++) {
key = this.deriveChange(i);
yield this.saveKey(key);
}
this.change = this.deriveChange(change - 1);
this.changeDepth = change;
derived = true;
@ -689,7 +699,7 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) {
if (this.witness && nested > this.nestedDepth) {
depth = this.nestedDepth + this.lookahead;
assert(this.lookahead === 0 || nested <= depth);
assert(nested <= depth + 1);
for (i = depth; i < nested + this.lookahead; i++) {
key = this.deriveNested(i);

View File

@ -194,10 +194,10 @@ function accountFromRaw(data) {
account.m = p.readU8();
account.n = p.readU8();
account.accountIndex = p.readU32();
account.receiveDepth = p.readU32() + 5;
account.changeDepth = p.readU32() + 10;
account.nestedDepth = p.readU32() + (account.witness ? 5 : 0);
account.lookahead = 5;
account.receiveDepth = p.readU32();
account.changeDepth = p.readU32();
account.nestedDepth = p.readU32();
account.lookahead = 10;
account.accountKey = p.readBytes(82);
account.keys = [];