diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index c2f02819f..ab656fc82 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -102,6 +102,7 @@ wallet_commit_channel(struct lightningd *ld, u64 static_remotekey_start; u32 lease_start_blockheight = 0; /* No leases on v1 */ struct short_channel_id *alias_local; + struct timeabs timestamp; /* We cannot both be the fundee *and* have a `fundchannel_start` * command running! @@ -226,6 +227,17 @@ wallet_commit_channel(struct lightningd *ld, /* Now we finally put it in the database. */ wallet_channel_insert(ld->wallet, channel); + /* Notify that channel state changed (from non existant to existant) */ + timestamp = time_now(); + notify_channel_state_changed(ld, &channel->peer->id, + &channel->cid, + channel->scid, /* NULL */ + ×tamp, + 0, /* No prior state */ + channel->state, + channel->state_change_cause, + "new channel opened"); + return channel; } diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 2e8a417b8..214dadf09 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -777,27 +777,29 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind): event1 = wait_for_event(l1) event2 = wait_for_event(l2) - if l1.config('experimental-dual-fund'): - # Dual funded channels have an extra state change - assert(event1['peer_id'] == l2_id) # we only test these IDs the first time - assert(event1['channel_id'] == cid) - assert(event1['short_channel_id'] is None) - assert(event1['old_state'] == "DUALOPEND_OPEN_INIT") - assert(event1['new_state'] == "DUALOPEND_AWAITING_LOCKIN") - assert(event1['cause'] == "user") - assert(event1['message'] == "Sigs exchanged, waiting for lock-in") - event1 = wait_for_event(l1) - assert(event2['peer_id'] == l1_id) # we only test these IDs the first time - assert(event2['channel_id'] == cid) - assert(event2['short_channel_id'] is None) - assert(event2['old_state'] == "DUALOPEND_OPEN_INIT") - assert(event2['new_state'] == "DUALOPEND_AWAITING_LOCKIN") - assert(event2['cause'] == "remote") - assert(event2['message'] == "Sigs exchanged, waiting for lock-in") - event2 = wait_for_event(l2) - assert(event1['peer_id'] == l2_id) # we only test these IDs the first time assert(event1['channel_id'] == cid) + assert(event1['short_channel_id'] is None) # None until locked in + assert(event1['cause'] == "user") + + assert(event2['peer_id'] == l1_id) # we only test these IDs the first time + assert(event2['channel_id'] == cid) + assert(event2['short_channel_id'] is None) # None until locked in + assert(event2['cause'] == "remote") + + for ev in [event1, event2]: + # Dual funded channels + if l1.config('experimental-dual-fund'): + assert(ev['old_state'] == "DUALOPEND_OPEN_INIT") + assert(ev['new_state'] == "DUALOPEND_AWAITING_LOCKIN") + assert(ev['message'] == "Sigs exchanged, waiting for lock-in") + else: + assert(ev['old_state'] == "unknown") + assert(ev['new_state'] == "CHANNELD_AWAITING_LOCKIN") + assert(ev['message'] == "new channel opened") + + event1 = wait_for_event(l1) + event2 = wait_for_event(l2) assert(event1['short_channel_id'] == scid) if l1.config('experimental-dual-fund'): assert(event1['old_state'] == "DUALOPEND_AWAITING_LOCKIN") @@ -807,8 +809,6 @@ def test_channel_state_changed_bilateral(node_factory, bitcoind): assert(event1['cause'] == "user") assert(event1['message'] == "Lockin complete") - assert(event2['peer_id'] == l1_id) - assert(event2['channel_id'] == cid) assert(event2['short_channel_id'] == scid) if l1.config('experimental-dual-fund'): assert(event2['old_state'] == "DUALOPEND_AWAITING_LOCKIN") @@ -911,18 +911,21 @@ def test_channel_state_changed_unilateral(node_factory, bitcoind): return event event2 = wait_for_event(l2) + assert(event2['peer_id'] == l1_id) + assert(event2['channel_id'] == cid) + assert(event2['short_channel_id'] is None) + assert(event2['cause'] == "remote") + if l2.config('experimental-dual-fund'): - assert(event2['peer_id'] == l1_id) - assert(event2['channel_id'] == cid) - assert(event2['short_channel_id'] is None) assert(event2['old_state'] == "DUALOPEND_OPEN_INIT") assert(event2['new_state'] == "DUALOPEND_AWAITING_LOCKIN") - assert(event2['cause'] == "remote") assert(event2['message'] == "Sigs exchanged, waiting for lock-in") - event2 = wait_for_event(l2) + else: + assert(event2['old_state'] == "unknown") + assert(event2['new_state'] == "CHANNELD_AWAITING_LOCKIN") + assert(event2['message'] == "new channel opened") - assert(event2['peer_id'] == l1_id) # we only test these IDs the first time - assert(event2['channel_id'] == cid) + event2 = wait_for_event(l2) assert(event2['short_channel_id'] == scid) if l2.config('experimental-dual-fund'): assert(event2['old_state'] == "DUALOPEND_AWAITING_LOCKIN")