Skip to content

Commit b619dc0

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 90bec4a + 05266da commit b619dc0

7 files changed

+295
-300
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ task:
135135
task:
136136
name: "check submodules"
137137
container:
138-
image: python:3.8
138+
image: python:3.9
139139
cpu: 1
140140
memory: 1G
141141
fetch_script:

electrum_grs/lnchannel.py

+37-21
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,21 @@
4444
from .transaction import Transaction, PartialTransaction, TxInput, Sighash
4545
from .logging import Logger
4646
from .lntransport import LNPeerAddr
47-
from .lnonion import OnionFailureCode, OnionRoutingFailure
47+
from .lnonion import OnionRoutingFailure
4848
from . import lnutil
4949
from .lnutil import (Outpoint, LocalConfig, RemoteConfig, Keypair, OnlyPubkeyKeypair, ChannelConstraints,
5050
get_per_commitment_secret_from_seed, secret_to_pubkey, derive_privkey, make_closing_tx,
5151
sign_and_get_sig_string, RevocationStore, derive_blinded_pubkey, Direction, derive_pubkey,
52-
make_htlc_tx_with_open_channel, make_commitment, make_received_htlc, make_offered_htlc,
53-
HTLC_TIMEOUT_WEIGHT, HTLC_SUCCESS_WEIGHT, extract_ctn_from_tx_and_chan, UpdateAddHtlc,
52+
make_htlc_tx_with_open_channel, make_commitment, UpdateAddHtlc,
5453
funding_output_script, SENT, RECEIVED, LOCAL, REMOTE, HTLCOwner, make_commitment_outputs,
5554
ScriptHtlc, PaymentFailure, calc_fees_for_commitment_tx, RemoteMisbehaving, make_htlc_output_witness_script,
5655
ShortChannelID, map_htlcs_to_ctx_output_idxs,
5756
fee_for_htlc_output, offered_htlc_trim_threshold_sat,
5857
received_htlc_trim_threshold_sat, make_commitment_output_to_remote_address, FIXED_ANCHOR_SAT,
59-
ChannelType, LNProtocolWarning, ctx_has_anchors)
60-
from .lnsweep import txs_our_ctx, txs_their_ctx
61-
from .lnsweep import txs_their_htlctx_justice, SweepInfo
62-
from .lnsweep import tx_their_ctx_to_remote_backup
58+
ChannelType, LNProtocolWarning)
59+
from .lnsweep import sweep_our_ctx, sweep_their_ctx
60+
from .lnsweep import sweep_their_htlctx_justice, sweep_our_htlctx, SweepInfo
61+
from .lnsweep import sweep_their_ctx_to_remote_backup
6362
from .lnhtlc import HTLCManager
6463
from .lnmsg import encode_msg, decode_msg
6564
from .address_synchronizer import TX_HEIGHT_LOCAL
@@ -284,11 +283,11 @@ def get_closing_height(self) -> Optional[Tuple[str, int, Optional[int]]]:
284283
def delete_closing_height(self):
285284
self.storage.pop('closing_height', None)
286285

287-
def create_sweeptxs_for_our_ctx(self, ctx: Transaction) -> Optional[Dict[str, SweepInfo]]:
288-
return txs_our_ctx(chan=self, ctx=ctx, sweep_address=self.get_sweep_address())
286+
def create_sweeptxs_for_our_ctx(self, ctx: Transaction) -> Dict[str, SweepInfo]:
287+
return sweep_our_ctx(chan=self, ctx=ctx)
289288

290-
def create_sweeptxs_for_their_ctx(self, ctx: Transaction) -> Optional[Dict[str, SweepInfo]]:
291-
return txs_their_ctx(chan=self, ctx=ctx, sweep_address=self.get_sweep_address())
289+
def create_sweeptxs_for_their_ctx(self, ctx: Transaction) -> Dict[str, SweepInfo]:
290+
return sweep_their_ctx(chan=self, ctx=ctx)
292291

293292
def is_backup(self) -> bool:
294293
return False
@@ -315,8 +314,8 @@ def sweep_ctx(self, ctx: Transaction) -> Dict[str, SweepInfo]:
315314
self.logger.info(f'not sure who closed.')
316315
return self._sweep_info[txid]
317316

318-
def maybe_sweep_revoked_htlc(self, ctx: Transaction, htlc_tx: Transaction) -> Optional[SweepInfo]:
319-
return None
317+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[str, SweepInfo]:
318+
return {}
320319

321320
def extract_preimage_from_htlc_txin(self, txin: TxInput) -> None:
322321
return
@@ -595,15 +594,15 @@ def is_backup(self):
595594
return True
596595

597596
def create_sweeptxs_for_their_ctx(self, ctx):
598-
return tx_their_ctx_to_remote_backup(chan=self, ctx=ctx, sweep_address=self.get_sweep_address())
597+
return sweep_their_ctx_to_remote_backup(chan=self, ctx=ctx)
599598

600599
def create_sweeptxs_for_our_ctx(self, ctx):
601600
if self.is_imported:
602-
return txs_our_ctx(chan=self, ctx=ctx, sweep_address=self.get_sweep_address())
601+
return sweep_our_ctx(chan=self, ctx=ctx)
603602
else:
604-
return
603+
return {}
605604

606-
def maybe_sweep_revoked_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
605+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[str, SweepInfo]:
607606
return {}
608607

609608
def extract_preimage_from_htlc_txin(self, txin: TxInput) -> None:
@@ -1491,9 +1490,23 @@ def get_oldest_unrevoked_commitment(self, subject: HTLCOwner) -> PartialTransact
14911490
return self.get_commitment(subject, ctn=ctn)
14921491

14931492
def create_sweeptxs_for_watchtower(self, ctn: int) -> List[Transaction]:
1494-
from .lnsweep import txs_their_ctx_watchtower
1493+
from .lnsweep import sweep_their_ctx_watchtower
1494+
from .transaction import PartialTxOutput, PartialTransaction
14951495
secret, ctx = self.get_secret_and_commitment(REMOTE, ctn=ctn)
1496-
return txs_their_ctx_watchtower(self, ctx, secret, self.get_sweep_address())
1496+
txs = []
1497+
txins = sweep_their_ctx_watchtower(self, ctx, secret)
1498+
for txin in txins:
1499+
output_idx = txin.prevout.out_idx
1500+
value = ctx.outputs()[output_idx].value
1501+
tx_size_bytes = 121
1502+
fee = self.lnworker.config.estimate_fee(tx_size_bytes, allow_fallback_to_static_rates=True)
1503+
outvalue = value - fee
1504+
sweep_outputs = [PartialTxOutput.from_address_and_value(self.get_sweep_address(), outvalue)]
1505+
sweep_tx = PartialTransaction.from_io([txin], sweep_outputs, version=2)
1506+
sig = sweep_tx.sign_txin(0, txin.privkey)
1507+
txin.witness = txin.make_witness(sig)
1508+
txs.append(sweep_tx)
1509+
return txs
14971510

14981511
def get_oldest_unrevoked_ctn(self, subject: HTLCOwner) -> int:
14991512
return self.hm.ctn_oldest_unrevoked(subject)
@@ -1726,9 +1739,12 @@ def get_close_options(self) -> Sequence[ChanCloseOption]:
17261739
assert not (self.get_state() == ChannelState.WE_ARE_TOXIC and ChanCloseOption.LOCAL_FCLOSE in ret), "local force-close unsafe if we are toxic"
17271740
return ret
17281741

1729-
def maybe_sweep_revoked_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[int, SweepInfo]:
1742+
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[str, SweepInfo]:
17301743
# look at the output address, check if it matches
1731-
return txs_their_htlctx_justice(self, ctx, htlc_tx, self.get_sweep_address())
1744+
d = sweep_their_htlctx_justice(self, ctx, htlc_tx)
1745+
d2 = sweep_our_htlctx(self, ctx, htlc_tx)
1746+
d.update(d2)
1747+
return d
17321748

17331749
def has_pending_changes(self, subject: HTLCOwner) -> bool:
17341750
next_htlcs = self.hm.get_htlcs_in_next_ctx(subject)

0 commit comments

Comments
 (0)