1
0

Refactor channel states:

- persisted states are saved
 - state transitions are checked
 - transient states are stored in channel.peer_state
 - new channel states: 'PREOPENING', 'FUNDED' and 'REDEEMED'
 - upgrade storage to version 21
This commit is contained in:
ThomasV
2019-10-29 08:02:14 +01:00
parent c31fa059fe
commit 61dfcba092
11 changed files with 151 additions and 79 deletions

View File

@@ -90,6 +90,10 @@ if [[ $1 == "init" ]]; then
new_blocks 1
fi
if [[ $1 == "new_block" ]]; then
new_blocks 1
fi
# start daemons. Bob is started first because he is listening
if [[ $1 == "start" ]]; then
$bob daemon -d

View File

@@ -34,6 +34,7 @@ from electrum.lnutil import SENT, LOCAL, REMOTE, RECEIVED
from electrum.lnutil import FeeUpdate
from electrum.ecc import sig_string_from_der_sig
from electrum.logging import console_stderr_handler
from electrum.lnchannel import channel_states
from . import ElectrumTestCase
@@ -94,6 +95,7 @@ def create_channel_state(funding_txid, funding_index, funding_sat, is_initiator,
),
"node_id":other_node_id,
'onion_keys': {},
'state': 'PREOPENING',
}
def bip32(sequence):
@@ -136,8 +138,8 @@ def create_test_channels(feerate=6000, local=None, remote=None):
alice.hm.log[LOCAL]['ctn'] = 0
bob.hm.log[LOCAL]['ctn'] = 0
alice.set_state('OPEN')
bob.set_state('OPEN')
alice._state = channel_states.OPEN
bob._state = channel_states.OPEN
a_out = alice.get_latest_commitment(LOCAL).outputs()
b_out = bob.get_next_commitment(REMOTE).outputs()

View File

@@ -16,6 +16,7 @@ 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
from electrum.lnchannel import channel_states
from electrum.lnrouter import LNPathFinder
from electrum.channel_db import ChannelDB
from electrum.lnworker import LNWallet, NoPathFound
@@ -202,9 +203,9 @@ class TestPeer(ElectrumTestCase):
w1.peer = p1
w2.peer = p2
# mark_open won't work if state is already OPEN.
# so set it to OPENING
self.alice_channel.set_state("OPENING")
self.bob_channel.set_state("OPENING")
# so set it to FUNDED
self.alice_channel._state = channel_states.FUNDED
self.bob_channel._state = channel_states.FUNDED
# this populates the channel graph:
p1.mark_open(self.alice_channel)
p2.mark_open(self.bob_channel)