X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Futxo.rs;h=e775e2628f6ca1df9e497a084506be7dd7eed6eb;hb=3a9fe209e104e048921ad50be77a80b18a98b45c;hp=8733def13d95d26dc3d9c446cb5851d39c3b2ca3;hpb=cbfff99124fbc30c73b82b37a9fd4151225b43ea;p=rust-lightning diff --git a/lightning/src/routing/utxo.rs b/lightning/src/routing/utxo.rs index 8733def1..e775e262 100644 --- a/lightning/src/routing/utxo.rs +++ b/lightning/src/routing/utxo.rs @@ -13,15 +13,16 @@ //! channel matches a UTXO on-chain, requiring at least some marginal on-chain transacting in //! order to announce a channel. This module handles that checking. -use bitcoin::{BlockHash, TxOut}; -use bitcoin::hashes::hex::ToHex; +use bitcoin::TxOut; +use bitcoin::blockdata::constants::ChainHash; + +use hex::DisplayHex; use crate::events::MessageSendEvent; use crate::ln::chan_utils::make_funding_redeemscript_from_slices; use crate::ln::msgs::{self, LightningError, ErrorAction}; use crate::routing::gossip::{NetworkGraph, NodeId, P2PGossipSync}; use crate::util::logger::{Level, Logger}; -use crate::util::ser::Writeable; use crate::prelude::*; @@ -60,11 +61,11 @@ pub enum UtxoResult { /// The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs. pub trait UtxoLookup { /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`]. - /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output - /// is unknown. + /// Returns an error if `chain_hash` is for a different chain or if such a transaction output is + /// unknown. /// /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id - fn get_utxo(&self, genesis_hash: &BlockHash, short_channel_id: u64) -> UtxoResult; + fn get_utxo(&self, chain_hash: &ChainHash, short_channel_id: u64) -> UtxoResult; } enum ChannelAnnouncement { @@ -127,7 +128,7 @@ pub struct UtxoFuture { /// once we have a concrete resolution of a request. pub(crate) struct UtxoResolver(Result); impl UtxoLookup for UtxoResolver { - fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult { + fn get_utxo(&self, _chain_hash: &ChainHash, _short_channel_id: u64) -> UtxoResult { UtxoResult::Sync(self.0.clone()) } } @@ -306,7 +307,7 @@ pub(super) struct PendingChecks { impl PendingChecks { pub(super) fn new() -> Self { PendingChecks { internal: Mutex::new(PendingChecksContext { - channels: HashMap::new(), nodes: HashMap::new(), + channels: new_hash_map(), nodes: new_hash_map(), }) } } @@ -459,11 +460,11 @@ impl PendingChecks { match res { Ok(TxOut { value, script_pubkey }) => { let expected_script = - make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_slice(), msg.bitcoin_key_2.as_slice()).to_v0_p2wsh(); + make_funding_redeemscript_from_slices(msg.bitcoin_key_1.as_array(), msg.bitcoin_key_2.as_array()).to_v0_p2wsh(); if script_pubkey != expected_script { return Err(LightningError{ err: format!("Channel announcement key ({}) didn't match on-chain script ({})", - expected_script.to_hex(), script_pubkey.to_hex()), + expected_script.to_hex_string(), script_pubkey.to_hex_string()), action: ErrorAction::IgnoreError }); } @@ -472,7 +473,7 @@ impl PendingChecks { Err(UtxoLookupError::UnknownChain) => { Err(LightningError { err: format!("Channel announced on an unknown chain ({})", - msg.chain_hash.encode().to_hex()), + msg.chain_hash.to_bytes().as_hex()), action: ErrorAction::IgnoreError }) }, @@ -562,7 +563,6 @@ mod tests { use super::*; use crate::routing::gossip::tests::*; use crate::util::test_utils::{TestChainSource, TestLogger}; - use crate::ln::msgs; use bitcoin::secp256k1::{Secp256k1, SecretKey}; @@ -577,7 +577,7 @@ mod tests { } fn get_test_objects() -> (msgs::ChannelAnnouncement, TestChainSource, - NetworkGraph>, bitcoin::Script, msgs::NodeAnnouncement, + NetworkGraph>, bitcoin::ScriptBuf, msgs::NodeAnnouncement, msgs::NodeAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate, msgs::ChannelUpdate) { let secp_ctx = Secp256k1::new(); @@ -660,7 +660,7 @@ mod tests { assert!(network_graph.read_only().channels().get(&valid_announcement.contents.short_channel_id).is_none()); future.resolve_without_forwarding(&network_graph, - Ok(TxOut { value: 1_000_000, script_pubkey: bitcoin::Script::new() })); + Ok(TxOut { value: 1_000_000, script_pubkey: bitcoin::ScriptBuf::new() })); assert!(network_graph.read_only().channels().get(&valid_announcement.contents.short_channel_id).is_none()); }