lnworker: imports, formatting, whitespace
This commit is contained in:
@@ -35,16 +35,17 @@ from . import constants, util
|
|||||||
from .util import (
|
from .util import (
|
||||||
profiler, OldTaskGroup, ESocksProxy, NetworkRetryManager, JsonRPCClient, NotEnoughFunds, EventListener,
|
profiler, OldTaskGroup, ESocksProxy, NetworkRetryManager, JsonRPCClient, NotEnoughFunds, EventListener,
|
||||||
event_listener, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions, ignore_exceptions,
|
event_listener, bfh, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions, ignore_exceptions,
|
||||||
make_aiohttp_session, timestamp_to_datetime, random_shuffled_copy, is_private_netaddress,
|
make_aiohttp_session, random_shuffled_copy, is_private_netaddress,
|
||||||
UnrelatedTransactionException, LightningHistoryItem
|
UnrelatedTransactionException, LightningHistoryItem
|
||||||
)
|
)
|
||||||
from .fee_policy import FeePolicy, FixedFeePolicy
|
from .fee_policy import (
|
||||||
from .fee_policy import (FEERATE_FALLBACK_STATIC_FEE, FEE_LN_ETA_TARGET, FEE_LN_LOW_ETA_TARGET,
|
FeePolicy, FEERATE_FALLBACK_STATIC_FEE, FEE_LN_ETA_TARGET, FEE_LN_LOW_ETA_TARGET,
|
||||||
FEERATE_PER_KW_MIN_RELAY_LIGHTNING, FEE_LN_MINIMUM_ETA_TARGET)
|
FEERATE_PER_KW_MIN_RELAY_LIGHTNING, FEE_LN_MINIMUM_ETA_TARGET
|
||||||
|
)
|
||||||
from .invoices import Invoice, PR_UNPAID, PR_PAID, PR_INFLIGHT, PR_FAILED, LN_EXPIRY_NEVER, BaseInvoice
|
from .invoices import Invoice, PR_UNPAID, PR_PAID, PR_INFLIGHT, PR_FAILED, LN_EXPIRY_NEVER, BaseInvoice
|
||||||
from .bitcoin import COIN, opcodes, make_op_return, address_to_scripthash, DummyAddress
|
from .bitcoin import COIN, opcodes, make_op_return, address_to_scripthash, DummyAddress
|
||||||
from .bip32 import BIP32Node
|
from .bip32 import BIP32Node
|
||||||
from .address_synchronizer import TX_HEIGHT_LOCAL, TX_TIMESTAMP_INF
|
from .address_synchronizer import TX_HEIGHT_LOCAL
|
||||||
from .transaction import (
|
from .transaction import (
|
||||||
Transaction, get_script_type_from_output_script, PartialTxOutput, PartialTransaction, PartialTxInput
|
Transaction, get_script_type_from_output_script, PartialTxOutput, PartialTransaction, PartialTxInput
|
||||||
)
|
)
|
||||||
@@ -53,7 +54,10 @@ from .crypto import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .onion_message import OnionMessageManager
|
from .onion_message import OnionMessageManager
|
||||||
from .lntransport import LNTransport, LNResponderTransport, LNTransportBase, LNPeerAddr, split_host_port, extract_nodeid, ConnStringFormatError
|
from .lntransport import (
|
||||||
|
LNTransport, LNResponderTransport, LNTransportBase, LNPeerAddr, split_host_port, extract_nodeid,
|
||||||
|
ConnStringFormatError
|
||||||
|
)
|
||||||
from .lnpeer import Peer, LN_P2P_NETWORK_TIMEOUT
|
from .lnpeer import Peer, LN_P2P_NETWORK_TIMEOUT
|
||||||
from .lnaddr import lnencode, LnAddr, lndecode
|
from .lnaddr import lnencode, LnAddr, lndecode
|
||||||
from .lnchannel import Channel, AbstractChannel, ChannelState, PeerState, HTLCWithStatus, ChannelBackup
|
from .lnchannel import Channel, AbstractChannel, ChannelState, PeerState, HTLCWithStatus, ChannelBackup
|
||||||
@@ -1044,7 +1048,8 @@ class LNWallet(LNWorker):
|
|||||||
|
|
||||||
def get_payment_value(
|
def get_payment_value(
|
||||||
self, info: Optional['PaymentInfo'],
|
self, info: Optional['PaymentInfo'],
|
||||||
plist: List[HTLCWithStatus]) -> Tuple[PaymentDirection, int, Optional[int], int]:
|
plist: List[HTLCWithStatus]
|
||||||
|
) -> Tuple[PaymentDirection, int, Optional[int], int]:
|
||||||
""" fee_msat is included in amount_msat"""
|
""" fee_msat is included in amount_msat"""
|
||||||
assert plist
|
assert plist
|
||||||
amount_msat = sum(int(x.direction) * x.htlc.amount_msat for x in plist)
|
amount_msat = sum(int(x.direction) * x.htlc.amount_msat for x in plist)
|
||||||
@@ -1447,14 +1452,16 @@ class LNWallet(LNWorker):
|
|||||||
return
|
return
|
||||||
fee_policy = FeePolicy(f'feerate:{FEERATE_FALLBACK_STATIC_FEE}')
|
fee_policy = FeePolicy(f'feerate:{FEERATE_FALLBACK_STATIC_FEE}')
|
||||||
try:
|
try:
|
||||||
self.mktx_for_open_channel(coins=coins, funding_sat=min_funding_sat, node_id=bytes(32), fee_policy=fee_policy)
|
self.mktx_for_open_channel(
|
||||||
|
coins=coins, funding_sat=min_funding_sat, node_id=bytes(32), fee_policy=fee_policy)
|
||||||
funding_sat = min_funding_sat
|
funding_sat = min_funding_sat
|
||||||
except NotEnoughFunds:
|
except NotEnoughFunds:
|
||||||
return
|
return
|
||||||
# if available, suggest twice that amount:
|
# if available, suggest twice that amount:
|
||||||
if 2 * min_funding_sat <= self.config.LIGHTNING_MAX_FUNDING_SAT:
|
if 2 * min_funding_sat <= self.config.LIGHTNING_MAX_FUNDING_SAT:
|
||||||
try:
|
try:
|
||||||
self.mktx_for_open_channel(coins=coins, funding_sat=2*min_funding_sat, node_id=bytes(32), fee_policy=fee_policy)
|
self.mktx_for_open_channel(
|
||||||
|
coins=coins, funding_sat=2*min_funding_sat, node_id=bytes(32), fee_policy=fee_policy)
|
||||||
funding_sat = 2 * min_funding_sat
|
funding_sat = 2 * min_funding_sat
|
||||||
except NotEnoughFunds:
|
except NotEnoughFunds:
|
||||||
pass
|
pass
|
||||||
@@ -1906,7 +1913,7 @@ class LNWallet(LNWorker):
|
|||||||
peer = self._peers.get(node_id)
|
peer = self._peers.get(node_id)
|
||||||
if not peer:
|
if not peer:
|
||||||
return False
|
return False
|
||||||
return (peer.their_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ECLAIR)\
|
return (peer.their_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ECLAIR)
|
||||||
or peer.their_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ELECTRUM))
|
or peer.their_features.supports(LnFeatures.OPTION_TRAMPOLINE_ROUTING_OPT_ELECTRUM))
|
||||||
|
|
||||||
def suggest_peer(self) -> Optional[bytes]:
|
def suggest_peer(self) -> Optional[bytes]:
|
||||||
@@ -2867,10 +2874,10 @@ class LNWallet(LNWorker):
|
|||||||
continue
|
continue
|
||||||
if direction == SENT:
|
if direction == SENT:
|
||||||
if chan1.can_pay(delta*1000):
|
if chan1.can_pay(delta*1000):
|
||||||
return (chan1, chan2, delta)
|
return chan1, chan2, delta
|
||||||
else:
|
else:
|
||||||
if chan1.can_receive(delta*1000):
|
if chan1.can_receive(delta*1000):
|
||||||
return (chan2, chan1, delta)
|
return chan2, chan1, delta
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@@ -3254,9 +3261,12 @@ class LNWallet(LNWorker):
|
|||||||
self.lnwatcher.add_channel(cb)
|
self.lnwatcher.add_channel(cb)
|
||||||
|
|
||||||
def save_forwarding_failure(
|
def save_forwarding_failure(
|
||||||
self, payment_key:str, *,
|
self,
|
||||||
|
payment_key: str,
|
||||||
|
*,
|
||||||
error_bytes: Optional[bytes] = None,
|
error_bytes: Optional[bytes] = None,
|
||||||
failure_message: Optional['OnionRoutingFailure'] = None):
|
failure_message: Optional['OnionRoutingFailure'] = None
|
||||||
|
) -> None:
|
||||||
error_hex = error_bytes.hex() if error_bytes else None
|
error_hex = error_bytes.hex() if error_bytes else None
|
||||||
failure_hex = failure_message.to_bytes().hex() if failure_message else None
|
failure_hex = failure_message.to_bytes().hex() if failure_message else None
|
||||||
self.forwarding_failures[payment_key] = (error_hex, failure_hex)
|
self.forwarding_failures[payment_key] = (error_hex, failure_hex)
|
||||||
|
|||||||
@@ -2288,9 +2288,10 @@ class OnchainHistoryItem(NamedTuple):
|
|||||||
'group_id': self.group_id,
|
'group_id': self.group_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class LightningHistoryItem(NamedTuple):
|
class LightningHistoryItem(NamedTuple):
|
||||||
payment_hash: str
|
payment_hash: Optional[str]
|
||||||
preimage: str
|
preimage: Optional[str]
|
||||||
amount_msat: int
|
amount_msat: int
|
||||||
fee_msat: Optional[int]
|
fee_msat: Optional[int]
|
||||||
type: str
|
type: str
|
||||||
|
|||||||
Reference in New Issue
Block a user