1
0

ln gossip: don't put own channels into db; always pass them to fn calls

Previously we would put fake chan announcement and fake outgoing chan upd
for own channels into db (to make path finding work). See Peer.add_own_channel().
Now, instead of above, we pass a "my_channels" param to the relevant ChannelDB methods.
This commit is contained in:
SomberNight
2020-02-17 20:38:41 +01:00
parent 7d65fe1ba3
commit 46d8080c76
6 changed files with 188 additions and 149 deletions

View File

@@ -18,7 +18,7 @@ from electrum.lnpeer import Peer
from electrum.lnutil import LNPeerAddr, Keypair, privkey_to_pubkey
from electrum.lnutil import LightningPeerConnectionClosed, RemoteMisbehaving
from electrum.lnutil import PaymentFailure, LnLocalFeatures
from electrum.lnchannel import channel_states, peer_states
from electrum.lnchannel import channel_states, peer_states, Channel
from electrum.lnrouter import LNPathFinder
from electrum.channel_db import ChannelDB
from electrum.lnworker import LNWallet, NoPathFound
@@ -77,7 +77,7 @@ class MockWallet:
return False
class MockLNWallet:
def __init__(self, remote_keypair, local_keypair, chan, tx_queue):
def __init__(self, remote_keypair, local_keypair, chan: 'Channel', tx_queue):
self.remote_keypair = remote_keypair
self.node_keypair = local_keypair
self.network = MockNetwork(tx_queue)
@@ -88,6 +88,8 @@ class MockLNWallet:
self.localfeatures = LnLocalFeatures(0)
self.localfeatures |= LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
self.pending_payments = defaultdict(asyncio.Future)
chan.lnworker = self
chan.node_id = remote_keypair.pubkey
def get_invoice_status(self, key):
pass
@@ -127,6 +129,7 @@ class MockLNWallet:
_pay_to_route = LNWallet._pay_to_route
force_close_channel = LNWallet.force_close_channel
get_first_timestamp = lambda self: 0
payment_completed = LNWallet.payment_completed
class MockTransport:
def __init__(self, name):
@@ -264,7 +267,7 @@ class TestPeer(ElectrumTestCase):
pay_req = self.prepare_invoice(w2)
async def pay():
result = await LNWallet._pay(w1, pay_req)
self.assertEqual(result, True)
self.assertTrue(result)
gath.cancel()
gath = asyncio.gather(pay(), p1._message_loop(), p2._message_loop())
async def f():