From f1f5a2e5d38c803e7cd904764fe5d1facf213e62 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 2 Nov 2016 17:08:15 -0700 Subject: [PATCH] account: remove change lookahead. --- lib/wallet/account.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/wallet/account.js b/lib/wallet/account.js index 79c1f864..5e8dcb45 100644 --- a/lib/wallet/account.js +++ b/lib/wallet/account.js @@ -452,9 +452,9 @@ Account.prototype.createKey = co(function* createKey(branch) { this.receive = key; break; case 1: + // Note: no lookahead here. key = this.deriveChange(this.changeDepth); - lookahead = this.deriveChange(this.changeDepth + this.lookahead); - yield this.saveKey(lookahead); + yield this.saveKey(key); this.changeDepth++; this.change = key; break; @@ -626,7 +626,13 @@ Account.prototype.initDepth = co(function* initDepth() { yield this.saveKey(this.receive); - // Change Address + // Lookahead + for (i = 0; i < this.lookahead; i++) { + key = this.deriveReceive(i + 1); + yield this.saveKey(key); + } + + // Change Address (no lookahead) this.change = this.deriveChange(0); this.changeDepth = 1; @@ -638,20 +644,8 @@ Account.prototype.initDepth = co(function* initDepth() { this.nestedDepth = 1; yield this.saveKey(this.nested); - } - // Lookaheads - for (i = 0; i < this.lookahead; i++) { - key = this.deriveReceive(i + 1); - yield this.saveKey(key); - } - - for (i = 0; i < this.lookahead; i++) { - key = this.deriveChange(i + 1); - yield this.saveKey(key); - } - - if (this.witness) { + // Lookahead for (i = 0; i < this.lookahead; i++) { key = this.deriveNested(i + 1); yield this.saveKey(key); @@ -677,7 +671,7 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) { if (receive > this.receiveDepth) { depth = this.receiveDepth + this.lookahead; - assert(receive <= depth); + assert(this.lookahead === 0 || receive <= depth); for (i = depth; i < receive + this.lookahead; i++) { key = this.deriveReceive(i); @@ -692,14 +686,10 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) { } if (change > this.changeDepth) { - depth = this.changeDepth + this.lookahead; + assert(change === this.changeDepth + 1); - assert(change <= depth); - - for (i = depth; i < change + this.lookahead; i++) { - key = this.deriveChange(i); - yield this.saveKey(key); - } + key = this.deriveChange(change - 1); + yield this.saveKey(key); this.change = this.deriveChange(change - 1); this.changeDepth = change; @@ -710,7 +700,7 @@ Account.prototype.syncDepth = co(function* syncDepth(receive, change, nested) { if (this.witness && nested > this.nestedDepth) { depth = this.nestedDepth + this.lookahead; - assert(nested <= depth); + assert(this.lookahead === 0 || nested <= depth); for (i = depth; i < nested + this.lookahead; i++) { key = this.deriveNested(i);