- /// For a new or already known (from previous announcement) channel, store or update channel info.
- /// Also store nodes (if not stored yet) the channel is between, and make node aware of this channel.
- /// Checking utxo on-chain is useful if we receive an update for already known channel id,
- /// which is probably result of a reorg. In that case, we update channel info only if the
- /// utxo was checked, otherwise stick to the existing update, to prevent DoS risks.
- /// Announcement signatures are checked here only if Secp256k1 object is provided.
- fn update_channel_from_announcement(&mut self, msg: &msgs::ChannelAnnouncement, checked_utxo: bool, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {
- if let Some(sig_verifier) = secp_ctx {
- let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
- secp_verify_sig!(sig_verifier, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
- secp_verify_sig!(sig_verifier, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);
- secp_verify_sig!(sig_verifier, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1);
- secp_verify_sig!(sig_verifier, &msg_hash, &msg.bitcoin_signature_2, &msg.contents.bitcoin_key_2);
+ /// Store or update channel info from a channel announcement.
+ ///
+ /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
+ /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
+ /// routing messages from a source using a protocol other than the lightning P2P protocol.
+ ///
+ /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
+ /// the corresponding UTXO exists on chain and is correctly-formatted.
+ pub fn update_channel_from_announcement<T: secp256k1::Verification, C: Deref>
+ (&mut self, msg: &msgs::ChannelAnnouncement, chain_access: &Option<C>, secp_ctx: &Secp256k1<T>)
+ -> Result<(), LightningError>
+ where C::Target: chain::Access {
+ let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
+ secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
+ secp_verify_sig!(secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);
+ secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1);
+ secp_verify_sig!(secp_ctx, &msg_hash, &msg.bitcoin_signature_2, &msg.contents.bitcoin_key_2);
+ self.update_channel_from_unsigned_announcement_intern(&msg.contents, Some(msg), chain_access)
+ }
+
+ /// Store or update channel info from a channel announcement without verifying the associated
+ /// signatures. Because we aren't given the associated signatures here we cannot relay the
+ /// channel announcement to any of our peers.
+ ///
+ /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
+ /// the corresponding UTXO exists on chain and is correctly-formatted.
+ pub fn update_channel_from_unsigned_announcement<C: Deref>
+ (&mut self, msg: &msgs::UnsignedChannelAnnouncement, chain_access: &Option<C>)
+ -> Result<(), LightningError>
+ where C::Target: chain::Access {
+ self.update_channel_from_unsigned_announcement_intern(msg, None, chain_access)
+ }
+
+ fn update_channel_from_unsigned_announcement_intern<C: Deref>
+ (&mut self, msg: &msgs::UnsignedChannelAnnouncement, full_msg: Option<&msgs::ChannelAnnouncement>, chain_access: &Option<C>)
+ -> Result<(), LightningError>
+ where C::Target: chain::Access {
+ if msg.node_id_1 == msg.node_id_2 || msg.bitcoin_key_1 == msg.bitcoin_key_2 {
+ return Err(LightningError{err: "Channel announcement node had a channel with itself".to_owned(), action: ErrorAction::IgnoreError});