Add standard derives for ConfirmationTarget
[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 #[derive(Clone, Copy, PartialEq, Eq)]
27 pub enum ConfirmationTarget {
28         /// We are happy with this transaction confirming slowly when feerate drops some.
29         Background,
30         /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
31         Normal,
32         /// We'd like this transaction to confirm in the next few blocks.
33         HighPriority,
34 }
35
36 /// A trait which should be implemented to provide feerate information on a number of time
37 /// horizons.
38 ///
39 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
40 /// called from inside the library in response to chain events, P2P events, or timer events).
41 pub trait FeeEstimator {
42         /// Gets estimated satoshis of fee required per 1000 Weight-Units.
43         ///
44         /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
45         /// don't put us below 1 satoshi-per-byte).
46         ///
47         /// This translates to:
48         ///  * satoshis-per-byte * 250
49         ///  * ceil(satoshis-per-kbyte / 4)
50         fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
51 }
52
53 /// Minimum relay fee as required by bitcoin network mempool policy.
54 pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;