-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vec Broadcaster #3448
base: main
Are you sure you want to change the base?
Vec Broadcaster #3448
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -45,6 +45,45 @@ pub trait BroadcasterInterface { | |||||
fn broadcast_transactions(&self, txs: &[&Transaction]); | ||||||
} | ||||||
|
||||||
/// Transaction broadcaster that does not broadcast transactions, but accumulates | ||||||
/// them in a Vec instead. This could be used to delay broadcasts until the system | ||||||
/// is ready. | ||||||
pub struct VecBroadcaster { | ||||||
channel_id: ChannelId, | ||||||
transactions: Mutex<Vec<Transaction>>, | ||||||
} | ||||||
|
||||||
impl VecBroadcaster { | ||||||
/// Create a new broadcaster for a channel | ||||||
pub fn new(channel_id: ChannelId) -> Self { | ||||||
Self { | ||||||
channel_id, | ||||||
transactions: Mutex::new(Vec::new()), | ||||||
} | ||||||
} | ||||||
|
||||||
/// Used to actually broadcast stored transactions to the network. | ||||||
#[instrument(skip_all, fields(channel = %self.channel_id))] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we require the |
||||||
pub fn release_transactions(&self, broadcaster: Arc<dyn BroadcasterInterface>) { | ||||||
let transactions = self.transactions.lock(); | ||||||
info!( | ||||||
"Releasing transactions for channel_id={}, len={}", | ||||||
self.channel_id, | ||||||
transactions.len() | ||||||
); | ||||||
broadcaster.broadcast_transactions(&transactions.iter().collect::<Vec<&Transaction>>()) | ||||||
} | ||||||
} | ||||||
|
||||||
impl BroadcasterInterface for VecBroadcaster { | ||||||
fn broadcast_transactions(&self, txs: &[&Transaction]) { | ||||||
let mut tx_storage = self.transactions.lock(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for tx in txs { | ||||||
tx_storage.push((*tx).to_owned()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we might want to see if we can dedup the packages before pushing, i.e., possibly only keep the latest version of a transaction, for example if we'd bump over and over again. |
||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// An enum that represents the priority at which we want a transaction to confirm used for feerate | ||||||
/// estimation. | ||||||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we'll still want to broadcast the individual packages, this might need to be a
Vec<Vec<Transaction>>