1 // This file is Copyright its original authors, visible in version control
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
10 //! Traits and utility impls which allow other parts of rust-lightning to interact with the
13 //! Includes traits for monitoring and receiving notifications of new blocks and block
14 //! disconnections, transaction broadcasting, and feerate information requests.
16 use bitcoin::blockdata::transaction::Transaction;
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);
24 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
26 #[derive(Clone, Copy, PartialEq, Eq)]
27 pub enum ConfirmationTarget {
28 /// We are happy with this transaction confirming slowly when feerate drops some.
30 /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
32 /// We'd like this transaction to confirm in the next few blocks.
36 /// A trait which should be implemented to provide feerate information on a number of time
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.
44 /// Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later
45 /// round-downs don't put us below 1 satoshi-per-byte).
47 /// This method can be implemented with the following unit conversions:
48 /// * max(satoshis-per-byte * 250, 253)
49 /// * max(satoshis-per-kbyte / 4, 253)
50 fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32;
53 /// Minimum relay fee as required by bitcoin network mempool policy.
54 pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000;