mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-13 14:52:21 +01:00
Stop relying on builder pattern for clearing feature bits
We have a handful of methods to clear features from `*Features` objects, but have ended up with two different API semantics for them. In the next commit we'll make them all consistent, opting against the builder pattern as it turns out all of these lines utilizing it are too long for rustfmt to be happy, so best to clean them up now so that rustfmt doesn't make a mockery of our code later.
This commit is contained in:
parent
4c43a5b3df
commit
6836fc4cd8
4 changed files with 21 additions and 13 deletions
|
@ -1040,25 +1040,22 @@ impl<T: sealed::Context> Features<T> {
|
|||
|
||||
impl<T: sealed::UpfrontShutdownScript> Features<T> {
|
||||
/// Unsets the `upfront_shutdown_script` feature
|
||||
pub fn clear_upfront_shutdown_script(mut self) -> Self {
|
||||
pub fn clear_upfront_shutdown_script(&mut self) {
|
||||
<T as sealed::UpfrontShutdownScript>::clear_bits(&mut self.flags);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::ShutdownAnySegwit> Features<T> {
|
||||
/// Unsets the `shutdown_anysegwit` feature
|
||||
pub fn clear_shutdown_anysegwit(mut self) -> Self {
|
||||
pub fn clear_shutdown_anysegwit(&mut self) {
|
||||
<T as sealed::ShutdownAnySegwit>::clear_bits(&mut self.flags);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::Wumbo> Features<T> {
|
||||
/// Unsets the `wumbo` feature
|
||||
pub fn clear_wumbo(mut self) -> Self {
|
||||
pub fn clear_wumbo(&mut self) {
|
||||
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11241,7 +11241,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn upfront_shutdown_script_incompatibility() {
|
||||
let features = channelmanager::provided_init_features(&UserConfig::default()).clear_shutdown_anysegwit();
|
||||
let mut features = channelmanager::provided_init_features(&UserConfig::default());
|
||||
features.clear_shutdown_anysegwit();
|
||||
let non_v0_segwit_shutdown_script = ShutdownScript::new_witness_program(
|
||||
&WitnessProgram::new(WitnessVersion::V16, &[0, 40]).unwrap(),
|
||||
).unwrap();
|
||||
|
|
|
@ -165,7 +165,9 @@ pub fn test_funding_exceeds_no_wumbo_limit() {
|
|||
use crate::ln::channel::MAX_FUNDING_SATOSHIS_NO_WUMBO;
|
||||
let chanmon_cfgs = create_chanmon_cfgs(2);
|
||||
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(channelmanager::provided_init_features(&test_default_channel_config()).clear_wumbo());
|
||||
let mut features = channelmanager::provided_init_features(&test_default_channel_config());
|
||||
features.clear_wumbo();
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(features);
|
||||
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
|
||||
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
|
||||
|
||||
|
|
|
@ -772,7 +772,9 @@ fn test_upfront_shutdown_script() {
|
|||
}
|
||||
|
||||
// We test that if case of peer non-signaling we don't enforce committed script at channel opening
|
||||
*nodes[0].override_init_features.borrow_mut() = Some(nodes[0].node.init_features().clear_upfront_shutdown_script());
|
||||
let mut features = nodes[0].node.init_features();
|
||||
features.clear_upfront_shutdown_script();
|
||||
*nodes[0].override_init_features.borrow_mut() = Some(features);
|
||||
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000);
|
||||
nodes[0].node.close_channel(&chan.2, &nodes[1].node.get_our_node_id()).unwrap();
|
||||
let node_1_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id());
|
||||
|
@ -824,7 +826,9 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
|
|||
let chanmon_cfgs = create_chanmon_cfgs(2);
|
||||
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
|
||||
// Clear shutdown_anysegwit on initiator
|
||||
*node_cfgs[0].override_init_features.borrow_mut() = Some(channelmanager::provided_init_features(&test_default_channel_config()).clear_shutdown_anysegwit());
|
||||
let mut features = channelmanager::provided_init_features(&test_default_channel_config());
|
||||
features.clear_shutdown_anysegwit();
|
||||
*node_cfgs[0].override_init_features.borrow_mut() = Some(features);
|
||||
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
|
||||
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
|
||||
|
||||
|
@ -853,7 +857,9 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() {
|
|||
let chanmon_cfgs = create_chanmon_cfgs(2);
|
||||
let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
|
||||
// Clear shutdown_anysegwit on responder
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(channelmanager::provided_init_features(&test_default_channel_config()).clear_shutdown_anysegwit());
|
||||
let mut features = channelmanager::provided_init_features(&test_default_channel_config());
|
||||
features.clear_shutdown_anysegwit();
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(features);
|
||||
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
|
||||
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
|
||||
|
||||
|
@ -984,8 +990,10 @@ fn test_unsupported_anysegwit_shutdown_script() {
|
|||
let user_cfgs = [None, Some(config), None];
|
||||
let chanmon_cfgs = create_chanmon_cfgs(3);
|
||||
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
|
||||
*node_cfgs[0].override_init_features.borrow_mut() = Some(channelmanager::provided_init_features(&config).clear_shutdown_anysegwit());
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(channelmanager::provided_init_features(&config).clear_shutdown_anysegwit());
|
||||
let mut features = channelmanager::provided_init_features(&config);
|
||||
features.clear_shutdown_anysegwit();
|
||||
*node_cfgs[0].override_init_features.borrow_mut() = Some(features.clone());
|
||||
*node_cfgs[1].override_init_features.borrow_mut() = Some(features);
|
||||
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &user_cfgs);
|
||||
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue