Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor commitments 2024 #9264

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added electrum/gui/icons/anchor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions electrum/gui/qt/channels_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ def icon(self) -> QIcon:
return read_QIcon("cloud_no")


class ChanFeatAnchors(ChannelFeature):
def tooltip(self) -> str:
return _("This channel uses anchor outputs.")
def icon(self) -> QIcon:
return read_QIcon("anchor")


class ChannelFeatureIcons:

def __init__(self, features: Sequence['ChannelFeature']):
Expand All @@ -458,6 +465,8 @@ def from_channel(cls, chan: AbstractChannel) -> 'ChannelFeatureIcons':
feats.append(ChanFeatTrampoline())
if not chan.has_onchain_backup():
feats.append(ChanFeatNoOnchainBackup())
if chan.has_anchors():
feats.append(ChanFeatAnchors())
return ChannelFeatureIcons(feats)

def paint(self, painter: QPainter, rect: QRect) -> None:
Expand Down
144 changes: 100 additions & 44 deletions electrum/lnchannel.py

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions electrum/lnpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,9 @@ def accepts_zeroconf(self):
def is_upfront_shutdown_script(self):
return self.features.supports(LnFeatures.OPTION_UPFRONT_SHUTDOWN_SCRIPT_OPT)

def use_anchors(self) -> bool:
return self.features.supports(LnFeatures.OPTION_ANCHORS_ZERO_FEE_HTLC_OPT)

def upfront_shutdown_script_from_payload(self, payload, msg_identifier: str) -> Optional[bytes]:
if msg_identifier not in ['accept', 'open']:
raise ValueError("msg_identifier must be either 'accept' or 'open'")
Expand All @@ -675,11 +678,16 @@ def make_local_config(self, funding_sat: int, push_msat: int, initiator: HTLCOwn
# flexibility to decide an address at closing time
upfront_shutdown_script = b''

assert channel_type & channel_type.OPTION_STATIC_REMOTEKEY
wallet = self.lnworker.wallet
assert wallet.txin_type == 'p2wpkh'
addr = wallet.get_new_sweep_address_for_channel()
static_remotekey = bytes.fromhex(wallet.get_public_key(addr))
if self.use_anchors():
static_payment_key = self.lnworker.static_payment_key
static_remotekey = None
else:
assert channel_type & channel_type.OPTION_STATIC_REMOTEKEY
wallet = self.lnworker.wallet
assert wallet.txin_type == 'p2wpkh'
addr = wallet.get_new_sweep_address_for_channel()
static_payment_key = None
static_remotekey = bytes.fromhex(wallet.get_public_key(addr))

dust_limit_sat = bitcoin.DUST_LIMIT_P2PKH
reserve_sat = max(funding_sat // 100, dust_limit_sat)
Expand All @@ -690,6 +698,7 @@ def make_local_config(self, funding_sat: int, push_msat: int, initiator: HTLCOwn
local_config = LocalConfig.from_seed(
channel_seed=channel_seed,
static_remotekey=static_remotekey,
static_payment_key=static_payment_key,
upfront_shutdown_script=upfront_shutdown_script,
to_self_delay=self.network.config.LIGHTNING_TO_SELF_DELAY_CSV,
dust_limit_sat=dust_limit_sat,
Expand Down Expand Up @@ -866,6 +875,7 @@ async def channel_establishment_flow(
initial_feerate_per_kw=feerate,
config=self.network.config,
peer_features=self.features,
has_anchors=self.use_anchors(),
)

# -> funding created
Expand Down Expand Up @@ -1036,6 +1046,7 @@ async def on_open_channel(self, payload):
initial_feerate_per_kw=feerate,
config=self.network.config,
peer_features=self.features,
has_anchors=self.use_anchors(),
)

channel_flags = ord(payload['channel_flags'])
Expand Down
Loading