mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
rename lnhtlc->lnchan, HTLCStateMachine->Channel
This commit is contained in:
parent
e1f37a17f3
commit
12bc0a75f8
6 changed files with 19 additions and 19 deletions
|
@ -5,7 +5,7 @@ from PyQt5.QtWidgets import *
|
||||||
|
|
||||||
from electrum.util import inv_dict, bh2u, bfh
|
from electrum.util import inv_dict, bh2u, bfh
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.lnhtlc import HTLCStateMachine
|
from electrum.lnchan import Channel
|
||||||
from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError
|
from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError
|
||||||
|
|
||||||
from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton
|
from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton
|
||||||
|
@ -13,7 +13,7 @@ from .amountedit import BTCAmountEdit
|
||||||
|
|
||||||
class ChannelsList(MyTreeWidget):
|
class ChannelsList(MyTreeWidget):
|
||||||
update_rows = QtCore.pyqtSignal()
|
update_rows = QtCore.pyqtSignal()
|
||||||
update_single_row = QtCore.pyqtSignal(HTLCStateMachine)
|
update_single_row = QtCore.pyqtSignal(Channel)
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Balance'), _('Remote'), _('Status')], 0)
|
MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Balance'), _('Remote'), _('Status')], 0)
|
||||||
|
@ -43,7 +43,7 @@ class ChannelsList(MyTreeWidget):
|
||||||
menu.addAction(_("Force-close channel"), close)
|
menu.addAction(_("Force-close channel"), close)
|
||||||
menu.exec_(self.viewport().mapToGlobal(position))
|
menu.exec_(self.viewport().mapToGlobal(position))
|
||||||
|
|
||||||
@QtCore.pyqtSlot(HTLCStateMachine)
|
@QtCore.pyqtSlot(Channel)
|
||||||
def do_update_single_row(self, chan):
|
def do_update_single_row(self, chan):
|
||||||
for i in range(self.topLevelItemCount()):
|
for i in range(self.topLevelItemCount()):
|
||||||
item = self.topLevelItem(i)
|
item = self.topLevelItem(i)
|
||||||
|
|
|
@ -27,7 +27,7 @@ from .util import PrintError, bh2u, print_error, bfh, log_exceptions
|
||||||
from .transaction import Transaction, TxOutput
|
from .transaction import Transaction, TxOutput
|
||||||
from .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, OnionFailureCode
|
from .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, OnionFailureCode
|
||||||
from .lnaddr import lndecode
|
from .lnaddr import lndecode
|
||||||
from .lnhtlc import HTLCStateMachine, RevokeAndAck, htlcsum
|
from .lnchan import Channel, RevokeAndAck, htlcsum
|
||||||
from .lnutil import (Outpoint, LocalConfig, ChannelConfig,
|
from .lnutil import (Outpoint, LocalConfig, ChannelConfig,
|
||||||
RemoteConfig, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore,
|
RemoteConfig, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore,
|
||||||
funding_output_script, get_ecdh, get_per_commitment_secret_from_seed,
|
funding_output_script, get_ecdh, get_per_commitment_secret_from_seed,
|
||||||
|
@ -641,7 +641,7 @@ class Peer(PrintError):
|
||||||
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth, feerate=feerate),
|
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth, feerate=feerate),
|
||||||
"remote_commitment_to_be_revoked": None,
|
"remote_commitment_to_be_revoked": None,
|
||||||
}
|
}
|
||||||
m = HTLCStateMachine(chan)
|
m = Channel(chan)
|
||||||
m.lnwatcher = self.lnwatcher
|
m.lnwatcher = self.lnwatcher
|
||||||
m.sweep_address = self.lnworker.sweep_address
|
m.sweep_address = self.lnworker.sweep_address
|
||||||
sig_64, _ = m.sign_next_commitment()
|
sig_64, _ = m.sign_next_commitment()
|
||||||
|
@ -737,7 +737,7 @@ class Peer(PrintError):
|
||||||
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth, feerate=feerate),
|
"constraints": ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth, feerate=feerate),
|
||||||
"remote_commitment_to_be_revoked": None,
|
"remote_commitment_to_be_revoked": None,
|
||||||
}
|
}
|
||||||
m = HTLCStateMachine(chan)
|
m = Channel(chan)
|
||||||
m.lnwatcher = self.lnwatcher
|
m.lnwatcher = self.lnwatcher
|
||||||
m.sweep_address = self.lnworker.sweep_address
|
m.sweep_address = self.lnworker.sweep_address
|
||||||
remote_sig = funding_created['signature']
|
remote_sig = funding_created['signature']
|
||||||
|
|
|
@ -83,7 +83,7 @@ def decodeAll(d, local):
|
||||||
def htlcsum(htlcs):
|
def htlcsum(htlcs):
|
||||||
return sum([x.amount_msat for x in htlcs])
|
return sum([x.amount_msat for x in htlcs])
|
||||||
|
|
||||||
class HTLCStateMachine(PrintError):
|
class Channel(PrintError):
|
||||||
def diagnostic_name(self):
|
def diagnostic_name(self):
|
||||||
return str(self.name)
|
return str(self.name)
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ class HTLCStateMachine(PrintError):
|
||||||
return super(MyJsonEncoder, self)
|
return super(MyJsonEncoder, self)
|
||||||
dumped = MyJsonEncoder().encode(serialized_channel)
|
dumped = MyJsonEncoder().encode(serialized_channel)
|
||||||
roundtripped = json.loads(dumped)
|
roundtripped = json.loads(dumped)
|
||||||
reconstructed = HTLCStateMachine(roundtripped)
|
reconstructed = Channel(roundtripped)
|
||||||
if reconstructed.to_save() != self.to_save():
|
if reconstructed.to_save() != self.to_save():
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
try:
|
try:
|
|
@ -19,7 +19,7 @@ from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_ad
|
||||||
from .lnbase import Peer, aiosafe
|
from .lnbase import Peer, aiosafe
|
||||||
from .lnaddr import lnencode, LnAddr, lndecode
|
from .lnaddr import lnencode, LnAddr, lndecode
|
||||||
from .ecc import der_sig_from_sig_string
|
from .ecc import der_sig_from_sig_string
|
||||||
from .lnhtlc import HTLCStateMachine
|
from .lnchan import Channel
|
||||||
from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
|
from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
|
||||||
get_compressed_pubkey_from_bech32, extract_nodeid,
|
get_compressed_pubkey_from_bech32, extract_nodeid,
|
||||||
PaymentFailure, split_host_port, ConnStringFormatError,
|
PaymentFailure, split_host_port, ConnStringFormatError,
|
||||||
|
@ -50,7 +50,7 @@ class LNWorker(PrintError):
|
||||||
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
|
self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0)
|
||||||
self.config = network.config
|
self.config = network.config
|
||||||
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
||||||
self.channels = {x.channel_id: x for x in map(HTLCStateMachine, wallet.storage.get("channels", []))} # type: Dict[bytes, HTLCStateMachine]
|
self.channels = {x.channel_id: x for x in map(Channel, wallet.storage.get("channels", []))} # type: Dict[bytes, HTLCStateMachine]
|
||||||
for c in self.channels.values():
|
for c in self.channels.values():
|
||||||
c.lnwatcher = network.lnwatcher
|
c.lnwatcher = network.lnwatcher
|
||||||
c.sweep_address = self.sweep_address
|
c.sweep_address = self.sweep_address
|
||||||
|
@ -115,7 +115,7 @@ class LNWorker(PrintError):
|
||||||
return peer
|
return peer
|
||||||
|
|
||||||
def save_channel(self, openchannel):
|
def save_channel(self, openchannel):
|
||||||
assert type(openchannel) is HTLCStateMachine
|
assert type(openchannel) is Channel
|
||||||
if openchannel.config[REMOTE].next_per_commitment_point == openchannel.config[REMOTE].current_per_commitment_point:
|
if openchannel.config[REMOTE].next_per_commitment_point == openchannel.config[REMOTE].current_per_commitment_point:
|
||||||
raise Exception("Tried to save channel with next_point == current_point, this should not happen")
|
raise Exception("Tried to save channel with next_point == current_point, this should not happen")
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import electrum.bitcoin as bitcoin
|
import electrum.bitcoin as bitcoin
|
||||||
import electrum.lnbase as lnbase
|
import electrum.lnbase as lnbase
|
||||||
import electrum.lnhtlc as lnhtlc
|
import electrum.lnchan as lnchan
|
||||||
import electrum.lnutil as lnutil
|
import electrum.lnutil as lnutil
|
||||||
import electrum.util as util
|
import electrum.util as util
|
||||||
import os
|
import os
|
||||||
|
@ -102,9 +102,9 @@ def create_test_channels(feerate=6000, local=None, remote=None):
|
||||||
bob_next = lnutil.secret_to_pubkey(int.from_bytes(lnutil.get_per_commitment_secret_from_seed(bob_seed, lnutil.RevocationStore.START_INDEX - 1), "big"))
|
bob_next = lnutil.secret_to_pubkey(int.from_bytes(lnutil.get_per_commitment_secret_from_seed(bob_seed, lnutil.RevocationStore.START_INDEX - 1), "big"))
|
||||||
|
|
||||||
return \
|
return \
|
||||||
lnhtlc.HTLCStateMachine(
|
lnchan.Channel(
|
||||||
create_channel_state(funding_txid, funding_index, funding_sat, feerate, True, local_amount, remote_amount, alice_privkeys, bob_pubkeys, alice_seed, bob_cur, bob_next, b"\x02"*33, l_dust=200, r_dust=1300, l_csv=5, r_csv=4), "alice"), \
|
create_channel_state(funding_txid, funding_index, funding_sat, feerate, True, local_amount, remote_amount, alice_privkeys, bob_pubkeys, alice_seed, bob_cur, bob_next, b"\x02"*33, l_dust=200, r_dust=1300, l_csv=5, r_csv=4), "alice"), \
|
||||||
lnhtlc.HTLCStateMachine(
|
lnchan.Channel(
|
||||||
create_channel_state(funding_txid, funding_index, funding_sat, feerate, False, remote_amount, local_amount, bob_privkeys, alice_pubkeys, bob_seed, alice_cur, alice_next, b"\x01"*33, l_dust=1300, r_dust=200, l_csv=4, r_csv=5), "bob")
|
create_channel_state(funding_txid, funding_index, funding_sat, feerate, False, remote_amount, local_amount, bob_privkeys, alice_pubkeys, bob_seed, alice_cur, alice_next, b"\x01"*33, l_dust=1300, r_dust=200, l_csv=4, r_csv=5), "bob")
|
||||||
|
|
||||||
one_bitcoin_in_msat = bitcoin.COIN * 1000
|
one_bitcoin_in_msat = bitcoin.COIN * 1000
|
||||||
|
@ -118,7 +118,7 @@ class TestFee(unittest.TestCase):
|
||||||
alice_channel, bob_channel = create_test_channels(253, 10000000000, 5000000000)
|
alice_channel, bob_channel = create_test_channels(253, 10000000000, 5000000000)
|
||||||
self.assertIn(9999817, [x[2] for x in alice_channel.local_commitment.outputs()])
|
self.assertIn(9999817, [x[2] for x in alice_channel.local_commitment.outputs()])
|
||||||
|
|
||||||
class TestLNBaseHTLCStateMachine(unittest.TestCase):
|
class TestChannel(unittest.TestCase):
|
||||||
def assertOutputExistsByValue(self, tx, amt_sat):
|
def assertOutputExistsByValue(self, tx, amt_sat):
|
||||||
for typ, scr, val in tx.outputs():
|
for typ, scr, val in tx.outputs():
|
||||||
if val == amt_sat:
|
if val == amt_sat:
|
||||||
|
@ -320,8 +320,8 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestLNHTLCDust(unittest.TestCase):
|
class TestDust(unittest.TestCase):
|
||||||
def test_HTLCDustLimit(self):
|
def test_DustLimit(self):
|
||||||
alice_channel, bob_channel = create_test_channels()
|
alice_channel, bob_channel = create_test_channels()
|
||||||
|
|
||||||
paymentPreimage = b"\x01" * 32
|
paymentPreimage = b"\x01" * 32
|
|
@ -7,7 +7,7 @@ from electrum.lnutil import (RevocationStore, get_per_commitment_secret_from_see
|
||||||
derive_pubkey, make_htlc_tx, extract_ctn_from_tx, UnableToDeriveSecret,
|
derive_pubkey, make_htlc_tx, extract_ctn_from_tx, UnableToDeriveSecret,
|
||||||
get_compressed_pubkey_from_bech32, split_host_port, ConnStringFormatError,
|
get_compressed_pubkey_from_bech32, split_host_port, ConnStringFormatError,
|
||||||
ScriptHtlc, extract_nodeid)
|
ScriptHtlc, extract_nodeid)
|
||||||
from electrum import lnhtlc
|
from electrum import lnchan
|
||||||
from electrum.util import bh2u, bfh
|
from electrum.util import bh2u, bfh
|
||||||
from electrum.transaction import Transaction
|
from electrum.transaction import Transaction
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ class TestLNUtil(unittest.TestCase):
|
||||||
(1, 2000 * 1000),
|
(1, 2000 * 1000),
|
||||||
(3, 3000 * 1000),
|
(3, 3000 * 1000),
|
||||||
(4, 4000 * 1000)]:
|
(4, 4000 * 1000)]:
|
||||||
htlc_obj[num] = lnhtlc.UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_expiry=None, htlc_id=None)
|
htlc_obj[num] = lnchan.UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_expiry=None, htlc_id=None)
|
||||||
htlcs = [ScriptHtlc(htlc[x], htlc_obj[x]) for x in range(5)]
|
htlcs = [ScriptHtlc(htlc[x], htlc_obj[x]) for x in range(5)]
|
||||||
|
|
||||||
our_commit_tx = make_commitment(
|
our_commit_tx = make_commitment(
|
||||||
|
|
Loading…
Add table
Reference in a new issue