From fc41af5889803699ab092e2f7534f97d33d7fcf3 Mon Sep 17 00:00:00 2001
From: Victor Shyba <victor1984@riseup.net>
Date: Tue, 9 Oct 2018 22:39:29 -0300
Subject: [PATCH] set wallet max_gap after sync

---
 lbrynet/wallet/account.py | 7 +++++++
 lbrynet/wallet/ledger.py  | 1 +
 2 files changed, 8 insertions(+)

diff --git a/lbrynet/wallet/account.py b/lbrynet/wallet/account.py
index 8a3b3e974..297d55682 100644
--- a/lbrynet/wallet/account.py
+++ b/lbrynet/wallet/account.py
@@ -115,6 +115,13 @@ class Account(BaseAccount):
                 indent=2
             ))
 
+    @defer.inlineCallbacks
+    def save_max_gap(self):
+        gap = yield self.get_max_gap()
+        self.receiving.gap = max(20, gap['max_receiving_gap'] + 1)
+        self.change.gap = max(6, gap['max_change_gap'] + 1)
+        self.wallet.save()
+
     def get_balance(self, confirmations=0, include_claims=False, **constraints):
         if not include_claims:
             constraints.update({'is_claim': 0, 'is_update': 0, 'is_support': 0})
diff --git a/lbrynet/wallet/ledger.py b/lbrynet/wallet/ledger.py
index a147e22d5..66a2bad36 100644
--- a/lbrynet/wallet/ledger.py
+++ b/lbrynet/wallet/ledger.py
@@ -83,6 +83,7 @@ class MainNetLedger(BaseLedger):
         yield defer.DeferredList([
             a.maybe_migrate_certificates() for a in self.accounts
         ])
+        yield defer.DeferredList([a.save_max_gap() for a in self.accounts])
 
 
 class TestNetLedger(MainNetLedger):