83fee4d674d1611e82dccee1e1c674e8fb94f9aa
[rust-lightning] / lightning / src / chain / chaininterface.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 //! Traits and utility impls which allow other parts of rust-lightning to interact with the
11 //! blockchain.
12 //!
13 //! Includes traits for monitoring and receiving notifications of new blocks and block
14 //! disconnections, transaction broadcasting, and feerate information requests.
15
16 use bitcoin::blockdata::transaction::Transaction;
17
18 /// An interface to send a transaction to the Bitcoin network.
19 pub trait BroadcasterInterface {
20         /// Sends a transaction out to (hopefully) be mined.
21         fn broadcast_transaction(&self, tx: &Transaction);
22 }
23
24 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
25 /// estimation.
26 pub enum ConfirmationTarget {
27         /// We are happy with this transaction confirming slowly when feerate drops some.
28         Background,
29         /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
30         Normal,
31         /// We'd like this transaction to confirm in the next few blocks.
32         HighPriority,
33 }
34
35 /// A trait which should be implemented to provide feerate information on a number of time
36 /// horizons.
37 ///
38 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
39 /// called from inside the library in response to chain events, P2P events, or timer events).
40 pub trait FeeEstimator {
41         /// Gets estimated satoshis of fee required per 1000 Weight-Units.
42         ///
43         /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
44         /// don't put us below 1 satoshi-per-byte).
45         ///
46         /// This translates to:
47         ///  * satoshis-per-byte * 250
48         ///  * ceil(satoshis-per-kbyte / 4)
49         fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
50 }
51
52 /// Minimum relay fee as required by bitcoin network mempool policy.
53 pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;