Esempio n. 1
0
    def test_find_path_for_payment(self):
        class fake_network:
            config = self.config
            asyncio_loop = asyncio.get_event_loop()
            trigger_callback = lambda *args: None
            register_callback = lambda *args: None
            interface = None

        fake_network.channel_db = lnrouter.ChannelDB(fake_network())
        fake_network.channel_db.data_loaded.set()
        cdb = fake_network.channel_db
        path_finder = lnrouter.LNPathFinder(cdb)
        self.assertEqual(cdb.num_channels, 0)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02cccccccccccccccccccccccccccccccc',
                'short_channel_id': bfh('0000000000000001'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.assertEqual(cdb.num_channels, 1)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000002'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'short_channel_id': bfh('0000000000000003'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02cccccccccccccccccccccccccccccccc',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000004'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02dddddddddddddddddddddddddddddddd',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000005'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000006'),
                'chain_hash': QtumTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        o = lambda i: i.to_bytes(8, "big")
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(99),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(999),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(99999999),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': QtumTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        path = path_finder.find_path_for_payment(
            b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
            b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 100000)
        self.assertEqual([
            PathEdge(node_id=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                     short_channel_id=bfh('0000000000000003')),
            PathEdge(node_id=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                     short_channel_id=bfh('0000000000000002')),
        ], path)
        start_node = b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
        route = path_finder.create_route_from_path(path, start_node)
        self.assertEqual(b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                         route[0].node_id)
        self.assertEqual(bfh('0000000000000003'), route[0].short_channel_id)

        # need to duplicate tear_down here, as we also need to wait for the sql thread to stop
        self.asyncio_loop.call_soon_threadsafe(self._stop_loop.set_result, 1)
        self._loop_thread.join(timeout=1)
        cdb.sql_thread.join(timeout=1)
Esempio n. 2
0
    def test_find_path_for_payment(self):
        class fake_network:
            config = self.config
            asyncio_loop = asyncio.get_event_loop()
            trigger_callback = lambda *args: None
            register_callback = lambda *args: None
            interface = None

        fake_network.channel_db = lnrouter.ChannelDB(fake_network())
        cdb = fake_network.channel_db
        path_finder = lnrouter.LNPathFinder(cdb)
        self.assertEqual(cdb.num_channels, 0)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02cccccccccccccccccccccccccccccccc',
                'short_channel_id': bfh('0000000000000001'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        self.assertEqual(cdb.num_channels, 1)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000002'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'short_channel_id': bfh('0000000000000003'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02cccccccccccccccccccccccccccccccc',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000004'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02dddddddddddddddddddddddddddddddd',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000005'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000006'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': b'\x00\x00',
                'features': b''
            },
            trusted=True)
        o = lambda i: i.to_bytes(8, "big")
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(99),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(999),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(99999999),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': o(10),
            'htlc_minimum_msat': o(250),
            'fee_base_msat': o(100),
            'fee_proportional_millionths': o(150),
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': b'\x00\x00\x00\x00'
        })
        path = path_finder.find_path_for_payment(
            b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
            b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 100000)
        self.assertEqual([(b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                           b'\x00\x00\x00\x00\x00\x00\x00\x03'),
                          (b'\x02cccccccccccccccccccccccccccccccc',
                           b'\x00\x00\x00\x00\x00\x00\x00\x01'),
                          (b'\x02dddddddddddddddddddddddddddddddd',
                           b'\x00\x00\x00\x00\x00\x00\x00\x04'),
                          (b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                           b'\x00\x00\x00\x00\x00\x00\x00\x05')], path)
        start_node = b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
        route = path_finder.create_route_from_path(path, start_node)
        self.assertEqual(route[0].node_id, start_node)
        self.assertEqual(route[0].short_channel_id, bfh('0000000000000003'))
Esempio n. 3
0
    def test_find_path_for_payment(self):
        class fake_network:
            config = self.config
            asyncio_loop = asyncio.get_event_loop()
            trigger_callback = lambda *args: None
            register_callback = lambda *args: None
            interface = None

        fake_network.channel_db = lnrouter.ChannelDB(fake_network())
        fake_network.channel_db.data_loaded.set()
        cdb = fake_network.channel_db
        path_finder = lnrouter.LNPathFinder(cdb)
        self.assertEqual(cdb.num_channels, 0)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02cccccccccccccccccccccccccccccccc',
                'short_channel_id': bfh('0000000000000001'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.assertEqual(cdb.num_channels, 1)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000002'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                'short_channel_id': bfh('0000000000000003'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02cccccccccccccccccccccccccccccccc',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02cccccccccccccccccccccccccccccccc',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000004'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02dddddddddddddddddddddddddddddddd',
                'node_id_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'bitcoin_key_1': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_2': b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                'short_channel_id': bfh('0000000000000005'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_announcement(
            {
                'node_id_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'node_id_2': b'\x02dddddddddddddddddddddddddddddddd',
                'bitcoin_key_1': b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                'bitcoin_key_2': b'\x02dddddddddddddddddddddddddddddddd',
                'short_channel_id': bfh('0000000000000006'),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000001'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 99,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000002'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000003'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000004'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000005'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 999,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 99999999,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        cdb.add_channel_update({
            'short_channel_id': bfh('0000000000000006'),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        path = path_finder.find_path_for_payment(
            nodeA=b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
            nodeB=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
            invoice_amount_msat=100000)
        self.assertEqual([
            PathEdge(start_node=b'\x02aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
                     end_node=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                     short_channel_id=bfh('0000000000000003')),
            PathEdge(start_node=b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                     end_node=b'\x02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                     short_channel_id=bfh('0000000000000002')),
        ], path)
        route = path_finder.create_route_from_path(path)
        self.assertEqual(b'\x02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
                         route[0].node_id)
        self.assertEqual(bfh('0000000000000003'), route[0].short_channel_id)

        cdb.stop()
        asyncio.run_coroutine_threadsafe(cdb.stopped_event.wait(),
                                         self.asyncio_loop).result()
Esempio n. 4
0
    def prepare_graph(self):
        """
        Network topology with channel ids:
                3
            A  ---  B
            |    2/ |
          6 |   E   | 1
            | /5 \7 |
            D  ---  C
                4
        valid routes from A -> E:
        A -3-> B -2-> E
        A -6-> D -5-> E
        A -6-> D -4-> C -7-> E
        A -3-> B -1-> C -7-> E
        A -6-> D -4-> C -1-> B -2-> E
        A -3-> B -1-> C -4-> D -5-> E
        """
        class fake_network:
            config = self.config
            asyncio_loop = asyncio.get_event_loop()
            trigger_callback = lambda *args: None
            register_callback = lambda *args: None
            interface = None

        fake_network.channel_db = lnrouter.ChannelDB(fake_network())
        fake_network.channel_db.data_loaded.set()
        self.cdb = fake_network.channel_db
        self.path_finder = lnrouter.LNPathFinder(self.cdb)
        self.assertEqual(self.cdb.num_channels, 0)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('b'),
                'node_id_2': node('c'),
                'bitcoin_key_1': node('b'),
                'bitcoin_key_2': node('c'),
                'short_channel_id': channel(1),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.assertEqual(self.cdb.num_channels, 1)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('b'),
                'node_id_2': node('e'),
                'bitcoin_key_1': node('b'),
                'bitcoin_key_2': node('e'),
                'short_channel_id': channel(2),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('a'),
                'node_id_2': node('b'),
                'bitcoin_key_1': node('a'),
                'bitcoin_key_2': node('b'),
                'short_channel_id': channel(3),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('c'),
                'node_id_2': node('d'),
                'bitcoin_key_1': node('c'),
                'bitcoin_key_2': node('d'),
                'short_channel_id': channel(4),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('d'),
                'node_id_2': node('e'),
                'bitcoin_key_1': node('d'),
                'bitcoin_key_2': node('e'),
                'short_channel_id': channel(5),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('a'),
                'node_id_2': node('d'),
                'bitcoin_key_1': node('a'),
                'bitcoin_key_2': node('d'),
                'short_channel_id': channel(6),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)
        self.cdb.add_channel_announcements(
            {
                'node_id_1': node('c'),
                'node_id_2': node('e'),
                'bitcoin_key_1': node('c'),
                'bitcoin_key_2': node('e'),
                'short_channel_id': channel(7),
                'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
                'len': 0,
                'features': b''
            },
            trusted=True)

        def add_chan_upd(payload):
            self.cdb.add_channel_update(payload, verify=False)

        add_chan_upd({
            'short_channel_id': channel(1),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(1),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(2),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 99,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(2),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(3),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(3),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(4),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(4),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(5),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(5),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 999,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(6),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 200,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(6),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(7),
            'message_flags': b'\x00',
            'channel_flags': b'\x00',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })
        add_chan_upd({
            'short_channel_id': channel(7),
            'message_flags': b'\x00',
            'channel_flags': b'\x01',
            'cltv_expiry_delta': 10,
            'htlc_minimum_msat': 250,
            'fee_base_msat': 100,
            'fee_proportional_millionths': 150,
            'chain_hash': BitcoinTestnet.rev_genesis_bytes(),
            'timestamp': 0
        })