-
Notifications
You must be signed in to change notification settings - Fork 414
Disconnect announcement_signatures sending from funding_locked #1179
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
Merged
TheBlueMatt
merged 7 commits into
lightningdevkit:main
from
TheBlueMatt:2021-11-fix-announce-sigs-broadcast-time
Jan 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d62edd5
Move node_id signing of ChannelAnnouncement into Signer
TheBlueMatt a6ddb97
Return struct, not long tuple, from `Channel::channel_reestablish`
TheBlueMatt 0243f21
Do not Send FundingLocked messages while disconnected
TheBlueMatt e7facb1
Unset `Channel::is_usable` if mon update is blocking funding_locked
TheBlueMatt a265fc2
Disconect `announcement_signatures` sending from `funding_locked`
TheBlueMatt ee7cfa5
Swap loop and condition order to avoid looping unnecessarily
TheBlueMatt ed1163a
Make `Channel::get_announcement_sigs` return an Option and log
TheBlueMatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4596,17 +4596,19 @@ impl<Signer: Sign> Channel<Signer> { | |
}) | ||
} | ||
|
||
/// Gets an UnsignedChannelAnnouncement, as well as a signature covering it using our | ||
/// bitcoin_key, if available, for this channel. The channel must be publicly announceable and | ||
/// available for use (have exchanged FundingLocked messages in both directions). Should be used | ||
/// for both loose and in response to an AnnouncementSignatures message from the remote peer. | ||
/// Gets an UnsignedChannelAnnouncement for this channel. The channel must be publicly | ||
/// announceable and available for use (have exchanged FundingLocked messages in both | ||
/// directions). Should be used for both loose and in response to an AnnouncementSignatures | ||
/// message from the remote peer. | ||
/// | ||
/// Will only fail if we're not in a state where channel_announcement may be sent (including | ||
/// closing). | ||
/// | ||
/// Note that the "channel must be funded" requirement is stricter than BOLT 7 requires - see | ||
/// https://github.com/lightningnetwork/lightning-rfc/issues/468 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue is closed, does this need updating? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in a followup PR, since this has two acks. |
||
/// | ||
/// This will only return ChannelError::Ignore upon failure. | ||
pub fn get_channel_announcement(&self, node_id: PublicKey, chain_hash: BlockHash) -> Result<(msgs::UnsignedChannelAnnouncement, Signature), ChannelError> { | ||
TheBlueMatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn get_channel_announcement(&self, node_id: PublicKey, chain_hash: BlockHash) -> Result<msgs::UnsignedChannelAnnouncement, ChannelError> { | ||
if !self.config.announced_channel { | ||
return Err(ChannelError::Ignore("Channel is not available for public announcements".to_owned())); | ||
} | ||
|
@@ -4630,19 +4632,30 @@ impl<Signer: Sign> Channel<Signer> { | |
excess_data: Vec::new(), | ||
}; | ||
|
||
let sig = self.holder_signer.sign_channel_announcement(&msg, &self.secp_ctx) | ||
Ok(msg) | ||
} | ||
|
||
pub fn get_announcement_sigs(&self, node_pk: PublicKey, genesis_block_hash: BlockHash) -> Result<msgs::AnnouncementSignatures, ChannelError> { | ||
let announcement = self.get_channel_announcement(node_pk, genesis_block_hash)?; | ||
let (our_node_sig, our_bitcoin_sig) = self.holder_signer.sign_channel_announcement(&announcement, &self.secp_ctx) | ||
.map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?; | ||
|
||
Ok((msg, sig)) | ||
Ok(msgs::AnnouncementSignatures { | ||
channel_id: self.channel_id(), | ||
short_channel_id: self.get_short_channel_id().unwrap(), | ||
node_signature: our_node_sig, | ||
bitcoin_signature: our_bitcoin_sig, | ||
}) | ||
} | ||
|
||
/// Signs the given channel announcement, returning a ChannelError::Ignore if no keys are | ||
/// available. | ||
fn sign_channel_announcement(&self, our_node_secret: &SecretKey, our_node_id: PublicKey, msghash: secp256k1::Message, announcement: msgs::UnsignedChannelAnnouncement, our_bitcoin_sig: Signature) -> Result<msgs::ChannelAnnouncement, ChannelError> { | ||
fn sign_channel_announcement(&self, our_node_id: PublicKey, announcement: msgs::UnsignedChannelAnnouncement) -> Result<msgs::ChannelAnnouncement, ChannelError> { | ||
if let Some((their_node_sig, their_bitcoin_sig)) = self.announcement_sigs { | ||
let were_node_one = announcement.node_id_1 == our_node_id; | ||
|
||
let our_node_sig = self.secp_ctx.sign(&msghash, our_node_secret); | ||
let (our_node_sig, our_bitcoin_sig) = self.holder_signer.sign_channel_announcement(&announcement, &self.secp_ctx) | ||
.map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?; | ||
Ok(msgs::ChannelAnnouncement { | ||
node_signature_1: if were_node_one { our_node_sig } else { their_node_sig }, | ||
node_signature_2: if were_node_one { their_node_sig } else { our_node_sig }, | ||
|
@@ -4658,8 +4671,8 @@ impl<Signer: Sign> Channel<Signer> { | |
/// Processes an incoming announcement_signatures message, providing a fully-signed | ||
/// channel_announcement message which we can broadcast and storing our counterparty's | ||
/// signatures for later reconstruction/rebroadcast of the channel_announcement. | ||
pub fn announcement_signatures(&mut self, our_node_secret: &SecretKey, our_node_id: PublicKey, chain_hash: BlockHash, msg: &msgs::AnnouncementSignatures) -> Result<msgs::ChannelAnnouncement, ChannelError> { | ||
let (announcement, our_bitcoin_sig) = self.get_channel_announcement(our_node_id.clone(), chain_hash)?; | ||
pub fn announcement_signatures(&mut self, our_node_id: PublicKey, chain_hash: BlockHash, msg: &msgs::AnnouncementSignatures) -> Result<msgs::ChannelAnnouncement, ChannelError> { | ||
let announcement = self.get_channel_announcement(our_node_id.clone(), chain_hash)?; | ||
|
||
let msghash = hash_to_message!(&Sha256d::hash(&announcement.encode()[..])[..]); | ||
|
||
|
@@ -4676,18 +4689,17 @@ impl<Signer: Sign> Channel<Signer> { | |
|
||
self.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature)); | ||
|
||
self.sign_channel_announcement(our_node_secret, our_node_id, msghash, announcement, our_bitcoin_sig) | ||
self.sign_channel_announcement(our_node_id, announcement) | ||
} | ||
|
||
/// Gets a signed channel_announcement for this channel, if we previously received an | ||
/// announcement_signatures from our counterparty. | ||
pub fn get_signed_channel_announcement(&self, our_node_secret: &SecretKey, our_node_id: PublicKey, chain_hash: BlockHash) -> Option<msgs::ChannelAnnouncement> { | ||
let (announcement, our_bitcoin_sig) = match self.get_channel_announcement(our_node_id.clone(), chain_hash) { | ||
pub fn get_signed_channel_announcement(&self, our_node_id: PublicKey, chain_hash: BlockHash) -> Option<msgs::ChannelAnnouncement> { | ||
let announcement = match self.get_channel_announcement(our_node_id.clone(), chain_hash) { | ||
Ok(res) => res, | ||
Err(_) => return None, | ||
}; | ||
let msghash = hash_to_message!(&Sha256d::hash(&announcement.encode()[..])[..]); | ||
match self.sign_channel_announcement(our_node_secret, our_node_id, msghash, announcement, our_bitcoin_sig) { | ||
match self.sign_channel_announcement(our_node_id, announcement) { | ||
Ok(res) => Some(res), | ||
Err(_) => None, | ||
} | ||
|
@@ -6270,6 +6282,7 @@ mod tests { | |
|
||
let mut signer = InMemorySigner::new( | ||
&secp_ctx, | ||
SecretKey::from_slice(&hex::decode("4242424242424242424242424242424242424242424242424242424242424242").unwrap()[..]).unwrap(), | ||
SecretKey::from_slice(&hex::decode("30ff4956bbdd3222d44cc5e8a1261dab1e07957bdac5ae88fe3261ef321f3749").unwrap()[..]).unwrap(), | ||
SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(), | ||
SecretKey::from_slice(&hex::decode("1111111111111111111111111111111111111111111111111111111111111111").unwrap()[..]).unwrap(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
what does "should be used for loose" mean?
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.
Was this resolved...?
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.
I reworked the documentation to no longer say "loose".
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.
Ah, it looks like the updated comment was put in ed1163a