Move `chain::Access` to `routing` and rename it `UtxoLookup`
[rust-lightning] / lightning / src / routing / utxo.rs
1 // This file is Copyright its original authors, visible in version control
2 // history.
3 //
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
8 // licenses.
9
10 //! This module contains traits for LDK to access UTXOs to check gossip data is correct.
11 //!
12 //! When lightning nodes gossip channel information, they resist DoS attacks by checking that each
13 //! channel matches a UTXO on-chain, requiring at least some marginal on-chain transacting in
14 //! order to announce a channel. This module handles that checking.
15
16 use bitcoin::{BlockHash, TxOut};
17
18 /// An error when accessing the chain via [`UtxoLookup`].
19 #[derive(Clone, Debug)]
20 pub enum UtxoLookupError {
21         /// The requested chain is unknown.
22         UnknownChain,
23
24         /// The requested transaction doesn't exist or hasn't confirmed.
25         UnknownTx,
26 }
27
28 /// The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
29 pub trait UtxoLookup {
30         /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
31         /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
32         /// is unknown.
33         ///
34         /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
35         fn get_utxo(&self, genesis_hash: &BlockHash, short_channel_id: u64) -> Result<TxOut, UtxoLookupError>;
36 }