-
Notifications
You must be signed in to change notification settings - Fork 376
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
Update Channel Monitor without broadcasting transactions #3396
Update Channel Monitor without broadcasting transactions #3396
Conversation
Allowing Channel Monitor to be updated without executing any commands outside ChannelMonitor. This allows reading Channel Monitor in MonitorUpdatingPersister without using broadcaster and fee estimator and broadcast claims when the node is ready for it.
4ef16ab
to
fb6efe4
Compare
@TheBlueMatt Replaced private |
Instead of touching all the code here, wouldn't it be simpler to just build a |
&self, | ||
updates: &ChannelMonitorUpdate, | ||
logger: &L, | ||
) ->Result<(Vec<Result<Vec<PackageTemplate>, ()>>, bool), ()> |
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.
I'm not entirely sold on returning the packages to broadcast here - if a user is running in a situation where they don't have the ability to register a Broadcaster
that can broadcast why can they broadcast a set of transactions we hand to them here? Instead, should we consider storing the packages in the ChannelMonitor
to broadcast as soon as we see the node being up (eg a block gets connected)?
Followed this advice and implemented VecBroadcaster that does not broadcast transactions immediately, but accumulates them first: /// 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))]
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();
for tx in txs {
tx_storage.push((*tx).to_owned())
}
}
} Will close this PR. |
We could still take that upstream as a part of |
@TheBlueMatt Hey, yeah, that would be useful to have. I drafted another PR with CMon that stores claims in inner and then releases them on |
Allowing Channel Monitor to be updated without executing any commands outside ChannelMonitor. This allows reading Channel Monitor in MonitorUpdatingPersister without using broadcaster and fee estimator and broadcast claims when the node is ready for it.
For example, in a multi tenant environment, a server could load channels data in one place, initialize auxiliary services and perform node configuration, then send the result to another process, that would start a node with all required background processes and one of these processes would broadcast the transactions.