Fix: Store remote channel announcement information into wallet DB #2466
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR draft tries to fix issue #2409.
We don't store the announcement signatures before, so when restart we may waste much time on waiting for remote announcement reply. So this PR tries to store the remote announcement signatures into DB like what @SimonVrouwe proposed (we don't store local announcement signatures because we can drive sigs locally).
Instead of adding a new wire type between Channeld and MASTER, I change the
wire_channel_got_funding_locked
and ask it not only tell MASTER remote funding locked, but also send remote announcement sigs to MASTER and store sigs.There are 4 changes:
1. Rename
wire_channel_got_funding_locked
towire_channel_got_locked_and_announced
, and add announcement data into the message of this type.Now the message will be like this:
WIRE_CHANNEL_GOT_LOCKED_AND_ANNOUNCEMENT
+got_remote_announcement(bool)
+next_per_commit_point(pubkey)
+remote_announcement_node_sigs(signature)
+remote_announcement_bitcoin_sigs(signature)
The bool type above means if the message is to tell MASTER announcement or not(instead, to tell MASTER remote funding locked).
There 2 situations that this message will be sent:
msg:
WIRE_CHANNEL_GOT_LOCKED_AND_ANNOUNCEMENT
+false
+next_per_commit_point(pubkey)
+NULL
+NULL
In this case, the msg equals the original
wire_channel_got_funding_locked
.msg:
WIRE_CHANNEL_GOT_LOCKED_AND_ANNOUNCEMENT
+true
+NULL
+remote_announcement_node_sigs
+remote_announcement_bitcoin_sigs
Channeld will check if we received the same announcement before and ignore the same announcement.
Channeld only send
wire_channel_got_locked_and_announced
for announcement when it receives announcement for the first time.2. Add announcement struct in channel struct (in lightningd/channeld.h).
When MASTER receive announcement signatures, we will put signatures in this struct and store it into DB.
3. Add announcement table in DB, and add wallet_announcement_save() and
wallet_announcement_load() function.
announcement table
:The announcement table store data with the type like:
(channelid, remote_node_sigs, remote_bitcoin_sigs)
.When we create a new channel and insert channel into DB, the announcement data will be set. If channel doesn't set ANNOUNCEMENT flag or hasn't received remote announcement message, we will set
(channelid, NULL, NULL)
for this channel.wallet_announcement_save()
:This function will only be called when MASTER receive
wire_channel_got_locked_and_announced
with flag setting true and resolve announcement signatures into announcement struct.wallet_announcement_load()
:This function will only be called when we initial a channel from DB (this will happen when restart).
4. Add announcement save and load test in
wallet/test/run_wallet.c
.Compared to adding a new announcement wire type between Channeld and Lightningd, this way isn't so direct.
Anyway, it's just a try. What do you think about?