mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
lightning: enable by default but without gossip
Enables lightning by creating a node private key and storing it in the wallet. The gossiper is not launched at start up, only if there are existing channels.
This commit is contained in:
parent
edc593a886
commit
6045de759b
4 changed files with 30 additions and 6 deletions
|
@ -449,11 +449,15 @@ class LNGossip(LNWorker):
|
|||
self.features |= LnFeatures.GOSSIP_QUERIES_OPT
|
||||
self.features |= LnFeatures.GOSSIP_QUERIES_REQ
|
||||
self.unknown_ids = set()
|
||||
self.has_started = False
|
||||
|
||||
def start_network(self, network: 'Network'):
|
||||
assert network
|
||||
if self.has_started:
|
||||
return
|
||||
super().start_network(network)
|
||||
asyncio.run_coroutine_threadsafe(self.taskgroup.spawn(self.maintain_db()), self.network.asyncio_loop)
|
||||
self.has_started = True
|
||||
|
||||
async def maintain_db(self):
|
||||
await self.channel_db.load_data()
|
||||
|
|
|
@ -355,8 +355,13 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
|
|||
self.channel_db = channel_db.ChannelDB(self)
|
||||
self.path_finder = lnrouter.LNPathFinder(self.channel_db)
|
||||
self.lngossip = lnworker.LNGossip()
|
||||
|
||||
def start_gossip(self):
|
||||
self.lngossip.start_network(self)
|
||||
|
||||
def stop_gossip(self):
|
||||
self.lngossip.stop()
|
||||
|
||||
def run_from_another_thread(self, coro, *, timeout=None):
|
||||
assert self._loop_thread != threading.current_thread(), 'must not be called from network thread'
|
||||
fut = asyncio.run_coroutine_threadsafe(coro, self.asyncio_loop)
|
||||
|
|
|
@ -163,6 +163,10 @@ class TestCreateRestoreWallet(WalletTestCase):
|
|||
gap_limit=1,
|
||||
config=self.config)
|
||||
wallet = d['wallet'] # type: Standard_Wallet
|
||||
|
||||
# lightning initialization
|
||||
self.assertTrue(wallet.db.get('lightning_privkey2').startswith('xprv'))
|
||||
|
||||
wallet.check_password(password)
|
||||
self.assertEqual(passphrase, wallet.keystore.get_passphrase(password))
|
||||
self.assertEqual(d['seed'], wallet.keystore.get_seed(password))
|
||||
|
|
|
@ -283,10 +283,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
|||
self.db.put('wallet_type', self.wallet_type)
|
||||
self.contacts = Contacts(self.db)
|
||||
self._coin_price_cache = {}
|
||||
# lightning
|
||||
ln_xprv = self.db.get('lightning_privkey2')
|
||||
self.lnworker = LNWallet(self, ln_xprv) if ln_xprv else None
|
||||
self.lnbackups = LNBackups(self)
|
||||
|
||||
self.lnworker = None
|
||||
self.lnbackups = None
|
||||
|
||||
def save_db(self):
|
||||
if self.storage:
|
||||
|
@ -366,6 +365,9 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
|||
if self.lnworker:
|
||||
network.maybe_init_lightning()
|
||||
self.lnworker.start_network(network)
|
||||
# only start gossiping when we already have channels
|
||||
if self.db.get('channels'):
|
||||
self.network.start_gossip()
|
||||
self.lnbackups.start_network(network)
|
||||
|
||||
def load_and_cleanup(self):
|
||||
|
@ -2426,6 +2428,16 @@ class Deterministic_Wallet(Abstract_Wallet):
|
|||
# for a few seconds!
|
||||
self.synchronize()
|
||||
|
||||
# create lightning keys
|
||||
if self.can_have_lightning():
|
||||
self.init_lightning()
|
||||
ln_xprv = self.db.get('lightning_privkey2')
|
||||
# lnworker can only be initialized once receiving addresses are available
|
||||
# therefore we instantiate lnworker in DeterministicWallet
|
||||
self.lnworker = LNWallet(self, ln_xprv) if ln_xprv else None
|
||||
# does it make sense to instantiate lnbackups without lnworker?
|
||||
self.lnbackups = LNBackups(self)
|
||||
|
||||
def has_seed(self):
|
||||
return self.keystore.has_seed()
|
||||
|
||||
|
@ -2805,7 +2817,6 @@ def create_new_wallet(*, path, config: SimpleConfig, passphrase=None, password=N
|
|||
wallet.update_password(old_pw=None, new_pw=password, encrypt_storage=encrypt_file)
|
||||
wallet.synchronize()
|
||||
msg = "Please keep your seed in a safe place; if you lose it, you will not be able to restore your wallet."
|
||||
|
||||
wallet.save_db()
|
||||
return {'seed': seed, 'wallet': wallet, 'msg': msg}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue