ln feature bits: flatten namespaces, and impl feature deps and ctxs
This implements: - flat feature bits https://github.com/lightningnetwork/lightning-rfc/pull/666 - feature bit dependencies https://github.com/lightningnetwork/lightning-rfc/pull/719
This commit is contained in:
@@ -5,7 +5,7 @@ from electrum.lnmsg import (read_bigsize_int, write_bigsize_int, FieldEncodingNo
|
||||
MalformedMsg, MsgTrailingGarbage, MsgInvalidFieldOrder, encode_msg,
|
||||
decode_msg, UnexpectedFieldSizeForEncoder)
|
||||
from electrum.util import bfh
|
||||
from electrum.lnutil import ShortChannelID, LnLocalFeatures
|
||||
from electrum.lnutil import ShortChannelID, LnFeatures
|
||||
from electrum import constants
|
||||
|
||||
from . import TestCaseForTestnet
|
||||
@@ -344,10 +344,10 @@ class TestLNMsg(TestCaseForTestnet):
|
||||
"init",
|
||||
gflen=0,
|
||||
flen=2,
|
||||
features=(LnLocalFeatures.OPTION_STATIC_REMOTEKEY_OPT |
|
||||
LnLocalFeatures.GOSSIP_QUERIES_OPT |
|
||||
LnLocalFeatures.GOSSIP_QUERIES_REQ |
|
||||
LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT),
|
||||
features=(LnFeatures.OPTION_STATIC_REMOTEKEY_OPT |
|
||||
LnFeatures.GOSSIP_QUERIES_OPT |
|
||||
LnFeatures.GOSSIP_QUERIES_REQ |
|
||||
LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT),
|
||||
))
|
||||
self.assertEqual(bfh("00100000000220c2"),
|
||||
encode_msg("init", gflen=0, flen=2, features=bfh("20c2")))
|
||||
@@ -356,10 +356,10 @@ class TestLNMsg(TestCaseForTestnet):
|
||||
"init",
|
||||
gflen=0,
|
||||
flen=2,
|
||||
features=(LnLocalFeatures.OPTION_STATIC_REMOTEKEY_OPT |
|
||||
LnLocalFeatures.GOSSIP_QUERIES_OPT |
|
||||
LnLocalFeatures.GOSSIP_QUERIES_REQ |
|
||||
LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT),
|
||||
features=(LnFeatures.OPTION_STATIC_REMOTEKEY_OPT |
|
||||
LnFeatures.GOSSIP_QUERIES_OPT |
|
||||
LnFeatures.GOSSIP_QUERIES_REQ |
|
||||
LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT),
|
||||
init_tlvs={
|
||||
'networks':
|
||||
{'chains': b'CI\x7f\xd7\xf8&\x95q\x08\xf4\xa3\x0f\xd9\xce\xc3\xae\xbay\x97 \x84\xe9\x0e\xad\x01\xea3\t\x00\x00\x00\x00'}
|
||||
|
||||
@@ -21,7 +21,7 @@ from electrum.util import bh2u, create_and_start_event_loop
|
||||
from electrum.lnpeer import Peer
|
||||
from electrum.lnutil import LNPeerAddr, Keypair, privkey_to_pubkey
|
||||
from electrum.lnutil import LightningPeerConnectionClosed, RemoteMisbehaving
|
||||
from electrum.lnutil import PaymentFailure, LnLocalFeatures, HTLCOwner
|
||||
from electrum.lnutil import PaymentFailure, LnFeatures, HTLCOwner
|
||||
from electrum.lnchannel import channel_states, peer_states, Channel
|
||||
from electrum.lnrouter import LNPathFinder
|
||||
from electrum.channel_db import ChannelDB
|
||||
@@ -95,8 +95,8 @@ class MockLNWallet(Logger):
|
||||
self.payments = {}
|
||||
self.logs = defaultdict(list)
|
||||
self.wallet = MockWallet()
|
||||
self.localfeatures = LnLocalFeatures(0)
|
||||
self.localfeatures |= LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
|
||||
self.features = LnFeatures(0)
|
||||
self.features |= LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT
|
||||
self.pending_payments = defaultdict(asyncio.Future)
|
||||
chan.lnworker = self
|
||||
chan.node_id = remote_keypair.pubkey
|
||||
|
||||
@@ -8,7 +8,7 @@ from electrum.lnutil import (RevocationStore, get_per_commitment_secret_from_see
|
||||
make_htlc_tx_inputs, secret_to_pubkey, derive_blinded_pubkey, derive_privkey,
|
||||
derive_pubkey, make_htlc_tx, extract_ctn_from_tx, UnableToDeriveSecret,
|
||||
get_compressed_pubkey_from_bech32, split_host_port, ConnStringFormatError,
|
||||
ScriptHtlc, extract_nodeid, calc_fees_for_commitment_tx, UpdateAddHtlc)
|
||||
ScriptHtlc, extract_nodeid, calc_fees_for_commitment_tx, UpdateAddHtlc, LnFeatures)
|
||||
from electrum.util import bh2u, bfh, MyEncoder
|
||||
from electrum.transaction import Transaction, PartialTransaction
|
||||
|
||||
@@ -755,3 +755,53 @@ class TestLNUtil(ElectrumTestCase):
|
||||
with self.assertRaises(ConnStringFormatError):
|
||||
extract_nodeid("00" * 33 + "@")
|
||||
self.assertEqual(extract_nodeid("00" * 33 + "@localhost"), (b"\x00" * 33, "localhost"))
|
||||
|
||||
def test_ln_features_validate_transitive_dependecies(self):
|
||||
features = LnFeatures.OPTION_DATA_LOSS_PROTECT_REQ
|
||||
self.assertTrue(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.PAYMENT_SECRET_OPT
|
||||
self.assertFalse(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ
|
||||
self.assertFalse(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertTrue(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ
|
||||
self.assertFalse(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_OPT
|
||||
self.assertTrue(features.validate_transitive_dependecies())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertTrue(features.validate_transitive_dependecies())
|
||||
|
||||
def test_ln_features_for_init_message(self):
|
||||
features = LnFeatures.OPTION_DATA_LOSS_PROTECT_REQ
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.PAYMENT_SECRET_OPT
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_OPT
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertEqual(features, features.for_init_message())
|
||||
|
||||
def test_ln_features_for_invoice(self):
|
||||
features = LnFeatures.OPTION_DATA_LOSS_PROTECT_REQ
|
||||
self.assertEqual(LnFeatures(0), features.for_invoice())
|
||||
features = LnFeatures.PAYMENT_SECRET_OPT
|
||||
self.assertEqual(features, features.for_invoice())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ
|
||||
self.assertEqual(features, features.for_invoice())
|
||||
features = LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertEqual(features, features.for_invoice())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.OPTION_DATA_LOSS_PROTECT_REQ
|
||||
self.assertEqual(LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ,
|
||||
features.for_invoice())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_OPT | LnFeatures.OPTION_DATA_LOSS_PROTECT_REQ
|
||||
self.assertEqual(LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_OPT,
|
||||
features.for_invoice())
|
||||
features = LnFeatures.BASIC_MPP_OPT | LnFeatures.PAYMENT_SECRET_REQ | LnFeatures.VAR_ONION_REQ
|
||||
self.assertEqual(features, features.for_invoice())
|
||||
|
||||
Reference in New Issue
Block a user