Browse Source

lnutil.make_funding_input: don't return payment pubkeys

order depends on who is initiator anyway
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
committed by ThomasV
parent
commit
04ec7e9968
  1. 7
      electrum/lnchan.py
  2. 21
      electrum/lnutil.py

7
electrum/lnchan.py

@ -159,7 +159,8 @@ class Channel(PrintError):
def get_state(self): def get_state(self):
return self._state return self._state
def check_can_pay(self, amount_msat): def check_can_pay(self, amount_msat: int) -> None:
# FIXME channel reserve
if self.get_state() != 'OPEN': if self.get_state() != 'OPEN':
raise PaymentFailure('Channel not open') raise PaymentFailure('Channel not open')
if self.available_to_spend(LOCAL) < amount_msat: if self.available_to_spend(LOCAL) < amount_msat:
@ -168,6 +169,8 @@ class Channel(PrintError):
raise PaymentFailure('Too many HTLCs already in channel') raise PaymentFailure('Too many HTLCs already in channel')
if htlcsum(self.htlcs(LOCAL, only_pending=True)) + amount_msat > self.config[REMOTE].max_htlc_value_in_flight_msat: if htlcsum(self.htlcs(LOCAL, only_pending=True)) + amount_msat > self.config[REMOTE].max_htlc_value_in_flight_msat:
raise PaymentFailure('HTLC value sum would exceed max allowed: {} msat'.format(self.config[REMOTE].max_htlc_value_in_flight_msat)) raise PaymentFailure('HTLC value sum would exceed max allowed: {} msat'.format(self.config[REMOTE].max_htlc_value_in_flight_msat))
if amount_msat <= 0: # FIXME htlc_minimum_msat
raise PaymentFailure(f'HTLC value too small: {amount_msat} msat')
def can_pay(self, amount_msat): def can_pay(self, amount_msat):
try: try:
@ -722,8 +725,6 @@ class Channel(PrintError):
closing_tx = make_closing_tx(self.config[LOCAL].multisig_key.pubkey, closing_tx = make_closing_tx(self.config[LOCAL].multisig_key.pubkey,
self.config[REMOTE].multisig_key.pubkey, self.config[REMOTE].multisig_key.pubkey,
self.config[LOCAL].payment_basepoint.pubkey,
self.config[REMOTE].payment_basepoint.pubkey,
# TODO hardcoded we_are_initiator: # TODO hardcoded we_are_initiator:
True, *self.funding_outpoint, self.constraints.capacity, True, *self.funding_outpoint, self.constraints.capacity,
outputs) outputs)

21
electrum/lnutil.py

@ -320,10 +320,8 @@ def make_htlc_tx_with_open_channel(chan, pcp, for_us, we_receive, commit, htlc):
return script, htlc_tx return script, htlc_tx
def make_funding_input(local_funding_pubkey: bytes, remote_funding_pubkey: bytes, def make_funding_input(local_funding_pubkey: bytes, remote_funding_pubkey: bytes,
payment_basepoint: bytes, remote_payment_basepoint: bytes,
funding_pos: int, funding_txid: bytes, funding_sat: int): funding_pos: int, funding_txid: bytes, funding_sat: int):
pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)]) pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)])
payments = [payment_basepoint, remote_payment_basepoint]
# commitment tx input # commitment tx input
c_input = { c_input = {
'type': 'p2wsh', 'type': 'p2wsh',
@ -335,7 +333,7 @@ def make_funding_input(local_funding_pubkey: bytes, remote_funding_pubkey: bytes
'value': funding_sat, 'value': funding_sat,
'coinbase': False, 'coinbase': False,
} }
return c_input, payments return c_input
class HTLCOwner(IntFlag): class HTLCOwner(IntFlag):
LOCAL = 1 LOCAL = 1
@ -374,16 +372,15 @@ def calc_onchain_fees(num_htlcs, feerate, for_us, we_are_initiator):
return {LOCAL: fee if we_pay_fee else 0, REMOTE: fee if not we_pay_fee else 0} return {LOCAL: fee if we_pay_fee else 0, REMOTE: fee if not we_pay_fee else 0}
def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey,
remote_payment_pubkey, payment_basepoint, remote_payment_pubkey, funder_payment_basepoint,
remote_payment_basepoint, revocation_pubkey, fundee_payment_basepoint, revocation_pubkey,
delayed_pubkey, to_self_delay, funding_txid, delayed_pubkey, to_self_delay, funding_txid,
funding_pos, funding_sat, local_amount, remote_amount, funding_pos, funding_sat, local_amount, remote_amount,
dust_limit_sat, fees_per_participant, dust_limit_sat, fees_per_participant,
htlcs): htlcs):
c_input, payments = make_funding_input(local_funding_pubkey, remote_funding_pubkey, c_input = make_funding_input(local_funding_pubkey, remote_funding_pubkey,
payment_basepoint, remote_payment_basepoint, funding_pos, funding_pos, funding_txid, funding_sat)
funding_txid, funding_sat) obs = get_obscured_ctn(ctn, funder_payment_basepoint, fundee_payment_basepoint)
obs = get_obscured_ctn(ctn, *payments)
locktime = (0x20 << 24) + (obs & 0xffffff) locktime = (0x20 << 24) + (obs & 0xffffff)
sequence = (0x80 << 24) + (obs >> 24) sequence = (0x80 << 24) + (obs >> 24)
c_input['sequence'] = sequence c_input['sequence'] = sequence
@ -529,11 +526,9 @@ def get_compressed_pubkey_from_bech32(bech32_pubkey: str) -> bytes:
def make_closing_tx(local_funding_pubkey: bytes, remote_funding_pubkey: bytes, def make_closing_tx(local_funding_pubkey: bytes, remote_funding_pubkey: bytes,
payment_basepoint: bytes, remote_payment_basepoint: bytes,
funding_txid: bytes, funding_pos: int, funding_sat: int, outputs: List[TxOutput]): funding_txid: bytes, funding_pos: int, funding_sat: int, outputs: List[TxOutput]):
c_input, payments = make_funding_input(local_funding_pubkey, remote_funding_pubkey, c_input = make_funding_input(local_funding_pubkey, remote_funding_pubkey,
payment_basepoint, remote_payment_basepoint, funding_pos, funding_pos, funding_txid, funding_sat)
funding_txid, funding_sat)
c_input['sequence'] = 0xFFFF_FFFF c_input['sequence'] = 0xFFFF_FFFF
tx = Transaction.from_io([c_input], outputs, locktime=0, version=2) tx = Transaction.from_io([c_input], outputs, locktime=0, version=2)
return tx return tx

Loading…
Cancel
Save