mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
extend 'add_peer', 'list_peers' commands to gossip
This commit is contained in:
parent
c454564ed6
commit
ef5ad5f22f
3 changed files with 37 additions and 34 deletions
|
@ -53,6 +53,7 @@ from .wallet import Abstract_Wallet, create_new_wallet, restore_wallet_from_text
|
||||||
from .address_synchronizer import TX_HEIGHT_LOCAL
|
from .address_synchronizer import TX_HEIGHT_LOCAL
|
||||||
from .mnemonic import Mnemonic
|
from .mnemonic import Mnemonic
|
||||||
from .lnutil import SENT, RECEIVED
|
from .lnutil import SENT, RECEIVED
|
||||||
|
from .lnutil import LnFeatures
|
||||||
from .lnutil import ln_dummy_address
|
from .lnutil import ln_dummy_address
|
||||||
from .lnpeer import channel_id_from_funding_tx
|
from .lnpeer import channel_id_from_funding_tx
|
||||||
from .plugin import run_hook
|
from .plugin import run_hook
|
||||||
|
@ -965,18 +966,21 @@ class Commands:
|
||||||
|
|
||||||
# lightning network commands
|
# lightning network commands
|
||||||
@command('wn')
|
@command('wn')
|
||||||
async def add_peer(self, connection_string, timeout=20, wallet: Abstract_Wallet = None):
|
async def add_peer(self, connection_string, timeout=20, gossip=False, wallet: Abstract_Wallet = None):
|
||||||
await wallet.lnworker.add_peer(connection_string)
|
lnworker = self.network.lngossip if gossip else wallet.lnworker
|
||||||
|
await lnworker.add_peer(connection_string)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@command('wn')
|
@command('wn')
|
||||||
async def list_peers(self, wallet: Abstract_Wallet = None):
|
async def list_peers(self, gossip=False, wallet: Abstract_Wallet = None):
|
||||||
|
lnworker = self.network.lngossip if gossip else wallet.lnworker
|
||||||
return [{
|
return [{
|
||||||
'node_id':p.pubkey.hex(),
|
'node_id':p.pubkey.hex(),
|
||||||
'address':p.transport.name(),
|
'address':p.transport.name(),
|
||||||
'initialized':p.is_initialized(),
|
'initialized':p.is_initialized(),
|
||||||
|
'features': str(LnFeatures(p.features)),
|
||||||
'channels': [c.funding_outpoint.to_str() for c in p.channels.values()],
|
'channels': [c.funding_outpoint.to_str() for c in p.channels.values()],
|
||||||
} for p in wallet.lnworker.peers.values()]
|
} for p in lnworker.peers.values()]
|
||||||
|
|
||||||
@command('wpn')
|
@command('wpn')
|
||||||
async def open_channel(self, connection_string, amount, push_amount=0, password=None, wallet: Abstract_Wallet = None):
|
async def open_channel(self, connection_string, amount, push_amount=0, password=None, wallet: Abstract_Wallet = None):
|
||||||
|
@ -1165,6 +1169,7 @@ command_options = {
|
||||||
'from_height': (None, "Only show transactions that confirmed after given block height"),
|
'from_height': (None, "Only show transactions that confirmed after given block height"),
|
||||||
'to_height': (None, "Only show transactions that confirmed before given block height"),
|
'to_height': (None, "Only show transactions that confirmed before given block height"),
|
||||||
'iknowwhatimdoing': (None, "Acknowledge that I understand the full implications of what I am about to do"),
|
'iknowwhatimdoing': (None, "Acknowledge that I understand the full implications of what I am about to do"),
|
||||||
|
'gossip': (None, "Apply command to gossip node instead of wallet"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,7 @@ class Peer(Logger):
|
||||||
self.lnworker = lnworker
|
self.lnworker = lnworker
|
||||||
self.privkey = self.transport.privkey # local privkey
|
self.privkey = self.transport.privkey # local privkey
|
||||||
self.features = self.lnworker.features
|
self.features = self.lnworker.features
|
||||||
|
self.their_features = 0
|
||||||
self.node_ids = [self.pubkey, privkey_to_pubkey(self.privkey)]
|
self.node_ids = [self.pubkey, privkey_to_pubkey(self.privkey)]
|
||||||
self.network = lnworker.network
|
self.network = lnworker.network
|
||||||
self.channel_db = lnworker.network.channel_db
|
self.channel_db = lnworker.network.channel_db
|
||||||
|
@ -200,15 +201,15 @@ class Peer(Logger):
|
||||||
if self._received_init:
|
if self._received_init:
|
||||||
self.logger.info("ALREADY INITIALIZED BUT RECEIVED INIT")
|
self.logger.info("ALREADY INITIALIZED BUT RECEIVED INIT")
|
||||||
return
|
return
|
||||||
their_features = LnFeatures(int.from_bytes(payload['features'], byteorder="big"))
|
self.their_features = LnFeatures(int.from_bytes(payload['features'], byteorder="big"))
|
||||||
their_globalfeatures = int.from_bytes(payload['globalfeatures'], byteorder="big")
|
their_globalfeatures = int.from_bytes(payload['globalfeatures'], byteorder="big")
|
||||||
their_features |= their_globalfeatures
|
self.their_features |= their_globalfeatures
|
||||||
# check transitive dependencies for received features
|
# check transitive dependencies for received features
|
||||||
if not their_features.validate_transitive_dependecies():
|
if not self.their_features.validate_transitive_dependecies():
|
||||||
raise GracefulDisconnect("remote did not set all dependencies for the features they sent")
|
raise GracefulDisconnect("remote did not set all dependencies for the features they sent")
|
||||||
# check if features are compatible, and set self.features to what we negotiated
|
# check if features are compatible, and set self.features to what we negotiated
|
||||||
try:
|
try:
|
||||||
self.features = ln_compare_features(self.features, their_features)
|
self.features = ln_compare_features(self.features, self.their_features)
|
||||||
except IncompatibleLightningFeatures as e:
|
except IncompatibleLightningFeatures as e:
|
||||||
self.initialized.set_exception(e)
|
self.initialized.set_exception(e)
|
||||||
raise GracefulDisconnect(f"{str(e)}")
|
raise GracefulDisconnect(f"{str(e)}")
|
||||||
|
|
|
@ -392,6 +392,29 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
|
||||||
peer.close_and_cleanup()
|
peer.close_and_cleanup()
|
||||||
self._clear_addr_retry_times()
|
self._clear_addr_retry_times()
|
||||||
|
|
||||||
|
@log_exceptions
|
||||||
|
async def add_peer(self, connect_str: str) -> Peer:
|
||||||
|
node_id, rest = extract_nodeid(connect_str)
|
||||||
|
peer = self._peers.get(node_id)
|
||||||
|
if not peer:
|
||||||
|
if rest is not None:
|
||||||
|
host, port = split_host_port(rest)
|
||||||
|
else:
|
||||||
|
addrs = self.channel_db.get_node_addresses(node_id)
|
||||||
|
if not addrs:
|
||||||
|
raise ConnStringFormatError(_('Don\'t know any addresses for node:') + ' ' + bh2u(node_id))
|
||||||
|
host, port, timestamp = self.choose_preferred_address(addrs)
|
||||||
|
port = int(port)
|
||||||
|
# Try DNS-resolving the host (if needed). This is simply so that
|
||||||
|
# the caller gets a nice exception if it cannot be resolved.
|
||||||
|
try:
|
||||||
|
await asyncio.get_event_loop().getaddrinfo(host, port)
|
||||||
|
except socket.gaierror:
|
||||||
|
raise ConnStringFormatError(_('Hostname does not resolve (getaddrinfo failed)'))
|
||||||
|
# add peer
|
||||||
|
peer = await self._add_peer(host, port, node_id)
|
||||||
|
return peer
|
||||||
|
|
||||||
|
|
||||||
class LNGossip(LNWorker):
|
class LNGossip(LNWorker):
|
||||||
max_age = 14*24*3600
|
max_age = 14*24*3600
|
||||||
|
@ -716,9 +739,6 @@ class LNWallet(LNWorker):
|
||||||
self.logger.info('REBROADCASTING CLOSING TX')
|
self.logger.info('REBROADCASTING CLOSING TX')
|
||||||
await self.network.try_broadcasting(force_close_tx, 'force-close')
|
await self.network.try_broadcasting(force_close_tx, 'force-close')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@log_exceptions
|
@log_exceptions
|
||||||
async def _open_channel_coroutine(self, *, connect_str: str, funding_tx: PartialTransaction,
|
async def _open_channel_coroutine(self, *, connect_str: str, funding_tx: PartialTransaction,
|
||||||
funding_sat: int, push_sat: int,
|
funding_sat: int, push_sat: int,
|
||||||
|
@ -750,29 +770,6 @@ class LNWallet(LNWorker):
|
||||||
channels_db[chan.channel_id.hex()] = chan.storage
|
channels_db[chan.channel_id.hex()] = chan.storage
|
||||||
self.wallet.save_backup()
|
self.wallet.save_backup()
|
||||||
|
|
||||||
@log_exceptions
|
|
||||||
async def add_peer(self, connect_str: str) -> Peer:
|
|
||||||
node_id, rest = extract_nodeid(connect_str)
|
|
||||||
peer = self._peers.get(node_id)
|
|
||||||
if not peer:
|
|
||||||
if rest is not None:
|
|
||||||
host, port = split_host_port(rest)
|
|
||||||
else:
|
|
||||||
addrs = self.channel_db.get_node_addresses(node_id)
|
|
||||||
if not addrs:
|
|
||||||
raise ConnStringFormatError(_('Don\'t know any addresses for node:') + ' ' + bh2u(node_id))
|
|
||||||
host, port, timestamp = self.choose_preferred_address(addrs)
|
|
||||||
port = int(port)
|
|
||||||
# Try DNS-resolving the host (if needed). This is simply so that
|
|
||||||
# the caller gets a nice exception if it cannot be resolved.
|
|
||||||
try:
|
|
||||||
await asyncio.get_event_loop().getaddrinfo(host, port)
|
|
||||||
except socket.gaierror:
|
|
||||||
raise ConnStringFormatError(_('Hostname does not resolve (getaddrinfo failed)'))
|
|
||||||
# add peer
|
|
||||||
peer = await self._add_peer(host, port, node_id)
|
|
||||||
return peer
|
|
||||||
|
|
||||||
def mktx_for_open_channel(self, *, coins: Sequence[PartialTxInput], funding_sat: int,
|
def mktx_for_open_channel(self, *, coins: Sequence[PartialTxInput], funding_sat: int,
|
||||||
fee_est=None) -> PartialTransaction:
|
fee_est=None) -> PartialTransaction:
|
||||||
dummy_address = ln_dummy_address()
|
dummy_address = ln_dummy_address()
|
||||||
|
|
Loading…
Add table
Reference in a new issue