-
Notifications
You must be signed in to change notification settings - Fork 945
Update emergency.recover after every 'commitment_revocation' so that user can sweep funds by penalty transaction. #7772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update emergency.recover after every 'commitment_revocation' so that user can sweep funds by penalty transaction. #7772
Conversation
bbea1f1
to
ca3b3de
Compare
6c70397
to
eeb239f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Only one minor cleanup suggestion.
I'll rebase now...
wallet/wallet.c
Outdated
|
||
for (u32 pos = 0; pos < chain->chain.num_valid; pos++) { | ||
struct secret s; | ||
memcpy(&s, &chain->chain.known[pos].hash, sizeof(s)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a new macro for, this: CROSS_TYPE_ASSIGNMENT(&s, &chain->chain.known[pos].hash). It checks the two types are same size...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it. Thanks!!
eeb239f
to
98b6ae4
Compare
Rebased on master with simple API fixes. |
84bebbf
to
7f13d7b
Compare
7f13d7b
to
6020851
Compare
This doesn't work for old scb files (as you can tell, from the test!) It should... |
4312f07
to
51d0031
Compare
1ca3c9b
to
e20a2c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a sensible and reasonable change. the commits were very easy to read through, kudos on that!
very cool that we're basically turning peers into watchtowers for ourselves.
2a19613
to
3a967d4
Compare
3a967d4
to
814dede
Compare
573f818
to
80f83bf
Compare
19b249a
to
ad922bf
Compare
8c2718d
to
2836e9b
Compare
The dual funding test is still unhappy. It seems like the htlc and delayed_payment basepoints are still uninitialized at some point when it goes to add the channel scb in |
The dual funding tests pass now. I am working to figure out the issue with the other failing tests as well. |
61f9dc1
to
46ba180
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking fairly good, minor requests only...
common/scb_wire.csv
Outdated
subtypedata,scb_chan_with_tlvs,id,u64, | ||
subtypedata,scb_chan_with_tlvs,cid,channel_id, | ||
subtypedata,scb_chan_with_tlvs,node_id,node_id, | ||
subtypedata,scb_chan_with_tlvs,unused,u8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this field any more!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks for pointing out.
plugins/chanbackup.c
Outdated
} | ||
|
||
if (version != VERSION) { | ||
plugin_err(cmd->plugin, | ||
"Incompatible version, Contact the admin!"); | ||
"Incompatible SCB file version on disk, contact the admin!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have another commitment at the end which:
- prints the versions here!
- only gets upset if an unknown EVEN bit is set. i.e. and with "0x5555555555555555" and then check if any bits are set which aren't in VERSION.
That lets us make either incompatible or compatible changes in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Great idea to use even bits for compatibility. I’ll update the version check to use the bitmask (0x5555555555555555) and print versions in the error message. This makes future changes much cleaner.
plugins/chanbackup.c
Outdated
struct scb_chan_with_tlvs **scb_tlvs; | ||
struct scb_chan **scb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename scb_tlvs "modern_scbs" and sbc "legacy_scbs"?
plugins/chanbackup.c
Outdated
tmp_scb_tlv->type = scb[i]->type; | ||
tmp_scb_tlv->tlvs = tlv_scb_tlvs_new(cmd); | ||
towire_scb_chan_with_tlvs(&scb_hex, tmp_scb_tlv); | ||
json_add_hex(req->js, NULL, scb_hex, tal_bytelen(scb_hex)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json_add_hex_talarr() does this for you, BTW (here and elsewhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for pointing out :)
tests/test_misc.py
Outdated
@@ -2934,7 +2934,6 @@ def test_emergencyrecoverpenaltytxn(node_factory, bitcoind): | |||
l1.daemon.wait_for_log('Resolved THEIR_REVOKED_UNILATERAL/DELAYED_CHEAT_OUTPUT_TO_THEM by our proposal OUR_PENALTY_TX') | |||
|
|||
assert(l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") | |||
assert(l1.rpc.listfunds()["outputs"][0]["txid"] == txid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixup should be deleted...
plugins/chanbackup.c
Outdated
u8 *scb_hex = tal_arr(cmd, u8, 0); | ||
struct scb_chan_with_tlvs *tmp_scb_tlv = tal(cmd, struct scb_chan_with_tlvs); | ||
tmp_scb_tlv->id = scb[i]->id; | ||
tmp_scb_tlv->addr = scb[i]->addr; | ||
tmp_scb_tlv->cid = scb[i]->cid; | ||
tmp_scb_tlv->funding = scb[i]->funding; | ||
tmp_scb_tlv->funding_sats = scb[i]->funding_sats; | ||
tmp_scb_tlv->type = scb[i]->type; | ||
tmp_scb_tlv->tlvs = tlv_scb_tlvs_new(cmd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps write "convert_legacy_scb()" which does this for us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
plugins/chanbackup.c
Outdated
plugin_log(cmd->plugin, LOG_DBG, | ||
"Processing legacy emergency.recover file format. " | ||
"Please migrate to the latest file format for improved " | ||
"compatibility and fund recovery."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use "json_notify_fmt()" to send a notification to the caller (though maybe only log that once,not every time around the loop!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used plugin_notify_message.
4ba8996
to
5256cdb
Compare
This change will allow subtypes in wiregen files to have tlvstreams. Shifting tlv structs above subtypes in header_template is done to prevent forward declaration. Since generate-wire prepends 'tlv_' in tlvname, we have to modify fromwire_subtype_field and towire_subtype_field in impl_template to accommodate this. Changelog-Added: This PR would turn our peers into watchtower and enable SCB to create penalty txn.
This change allows adding a length prefix to a serialized TLV. It will be particularly useful for serializing all 'scb_chan' entries in the 'emergency.recover' file. Key Changes: - Removed the need to loop in towire_tlv and fromwire_tlv, so the if conditions have been modified accordingly. - During serialization, the length of the TLV is calculated before appending it, and it is stored in a temporary variable. - For fromwire_tlv, only a simple length adjustment is required, and no loop is needed here either.
We define a new subtype 'modern_scb_chan' and a new tlvtype 'scb_tlvs' which includes all the relevant information to create a penalty transaction when the peer tries to cheat. Key Changes: - Rename the old format to 'legacy_scb_chan' and define a new type 'modern_scb_chan' - Include TLVs to 'modern_scb_chan' - Create a new msgtype 'static_chan_backup_with_tlvs' - Modify 'struct channel' to include 'struct modern_scb_chan' - Add these two types to 'varsize_types' in generate.py
These fields enhance 'stub_chan' to make channels which are capable to create penalty transaction in case the peer broadcasts an old revoked state. Key Changes: - Added new params to stub_chan() to accomodate shachain, basepoints, opener, and remote_to_self_delay - Check if any field is NULL inside scb_chan->tlvs and assign them appropriately
This function enables direct persistence of shachain data, ensuring all relevant information is saved upon retrieval. Key Changes: - Adds 'wallet_stub_shachain_init' function to store a retrieved shachain in the database. - Saves initial metadata ('min_index' and 'num_valid') to the 'shachains' table. - Iterates through known shachain secrets, adding each entry to 'shachain_known' with position, index, and hash.
Add the latest shachain when we update the emergency.recover using staticbackup RPC.
The chanbackup plugin should update emergency.recover every time we receive a new commitment secret. Additionally, chanbackup should be able to serialize both the new SCB format and the legacy format. Key Changes: - Added a commitment_revocation plugin hook to update emergency.recover whenever a new revocation secret is received. - Implemented support for the new emergency.recover format while maintaining compatibility with the legacy format.
Key Changes: - Added encrypted_data which contains emergency.recover in the legacy format - Added assert to make sure we watch the funding txn
5256cdb
to
b9e0b15
Compare
Ack 5256cdb |
16ffe30
to
b9e0b15
Compare
Accidentally clicked 'Update branch'—brain has stopped working. 😅 |
b9e0b15
to
45697c3
Compare
Just disable the test under elements, since the tx will be completely different. |
This test would make sure that the node would publish a penalty txn when channel partner cheats.
45697c3
to
b059e88
Compare
This PR would enable nodes to create penalty transaction when the peer publishes an old revoked state using the emergency.recover.
Addresses: #7696