1
0

ln: merge OpenChannel and HTLCStateMachine

This commit is contained in:
Janus
2018-06-27 20:23:03 +02:00
committed by ThomasV
parent 42a56df996
commit 7a3551b5df
6 changed files with 248 additions and 245 deletions

View File

@@ -36,13 +36,13 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
max_accepted_htlcs=5
)
return lnbase.OpenChannel(
channel_id=channel_id,
short_channel_id=channel_id[:8],
funding_outpoint=lnbase.Outpoint(funding_txid, funding_index),
local_config=local_config,
remote_config=remote_config,
remote_state=lnbase.RemoteState(
return {
"channel_id":channel_id,
"short_channel_id":channel_id[:8],
"funding_outpoint":lnbase.Outpoint(funding_txid, funding_index),
"local_config":local_config,
"remote_config":remote_config,
"remote_state":lnbase.RemoteState(
ctn = 0,
next_per_commitment_point=nex,
current_per_commitment_point=cur,
@@ -50,7 +50,7 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
revocation_store=their_revocation_store,
next_htlc_id = 0
),
local_state=lnbase.LocalState(
"local_state":lnbase.LocalState(
ctn = 0,
per_commitment_secret_seed=seed,
amount_msat=local_amount,
@@ -59,9 +59,9 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
was_announced=False,
current_commitment_signature=None
),
constraints=lnbase.ChannelConstraints(capacity=funding_sat, feerate=local_feerate, is_initiator=is_initiator, funding_txn_minimum_depth=3),
node_id=other_node_id
)
"constraints":lnbase.ChannelConstraints(capacity=funding_sat, feerate=local_feerate, is_initiator=is_initiator, funding_txn_minimum_depth=3),
"node_id":other_node_id
}
def bip32(sequence):
xprv, xpub = bitcoin.bip32_root(b"9dk", 'standard')
@@ -184,8 +184,8 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase):
self.assertEqual(alice_channel.total_msat_received, bobSent, "alice has incorrect milli-satoshis received")
self.assertEqual(bob_channel.total_msat_sent, bobSent, "bob has incorrect milli-satoshis sent")
self.assertEqual(bob_channel.total_msat_received, aliceSent, "bob has incorrect milli-satoshis received")
self.assertEqual(bob_channel.state.local_state.ctn, 1, "bob has incorrect commitment height")
self.assertEqual(alice_channel.state.local_state.ctn, 1, "alice has incorrect commitment height")
self.assertEqual(bob_channel.local_state.ctn, 1, "bob has incorrect commitment height")
self.assertEqual(alice_channel.local_state.ctn, 1, "alice has incorrect commitment height")
# Both commitment transactions should have three outputs, and one of
# them should be exactly the amount of the HTLC.
@@ -238,7 +238,7 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase):
paymentPreimage = b"\x01" * 32
paymentHash = bitcoin.sha256(paymentPreimage)
fee_per_kw = alice_channel.state.constraints.feerate
fee_per_kw = alice_channel.constraints.feerate
self.assertEqual(fee_per_kw, 6000)
htlcAmt = 500 + lnbase.HTLC_TIMEOUT_WEIGHT * (fee_per_kw // 1000)
self.assertEqual(htlcAmt, 4478)
@@ -283,9 +283,9 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase):
alice_sig, alice_htlc_sigs = alice_channel.sign_next_commitment()
bob_channel.receive_new_commitment(alice_sig, alice_htlc_sigs)
self.assertNotEqual(fee, alice_channel.state.constraints.feerate)
self.assertNotEqual(fee, alice_channel.constraints.feerate)
rev, _ = alice_channel.revoke_current_commitment()
self.assertEqual(fee, alice_channel.state.constraints.feerate)
self.assertEqual(fee, alice_channel.constraints.feerate)
bob_channel.receive_revocation(rev)
def force_state_transition(chanA, chanB):