Skip to content

Commit f14593b

Browse files
committed
Refactor setting unborn channel signer unavailability
For opening and accepting a channel, to test an asynchronous per commitment point call, we need to set the test signer to return Err(()) for a channel signer that hasn't been created until the middle of the create_channel or handle_open_channel call. To do this, we simply just push a mask to a queue in the keys manager, and the next channel signer it creates, it'll set that mask to be unavailable.
1 parent ff549c5 commit f14593b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
558558
});
559559
}
560560
}
561+
562+
#[cfg(test)]
563+
pub fn set_unborn_channel_signer_ops_unavailable(&self, mask: u32) {
564+
self.keys_manager.unavailable_signers.lock().unwrap().push_back(mask);
565+
}
561566
}
562567

563568
/// If we need an unsafe pointer to a `Node` (ie to reference it in a thread

lightning/src/util/test_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ pub struct TestKeysInterface {
12141214
pub disable_revocation_policy_check: bool,
12151215
enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
12161216
expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
1217-
pub unavailable_signers: Mutex<HashSet<[u8; 32]>>,
1217+
pub unavailable_signers: Mutex<VecDeque<u32>>,
12181218
}
12191219

12201220
impl EntropySource for TestKeysInterface {
@@ -1274,8 +1274,9 @@ impl SignerProvider for TestKeysInterface {
12741274
let keys = self.backing.derive_channel_signer(channel_value_satoshis, channel_keys_id);
12751275
let state = self.make_enforcement_state_cell(keys.commitment_seed);
12761276
let signer = TestChannelSigner::new_with_revoked(keys, state, self.disable_revocation_policy_check);
1277-
if self.unavailable_signers.lock().unwrap().contains(&channel_keys_id) {
1278-
signer.set_available(false);
1277+
#[cfg(test)]
1278+
if let Some(mask) = self.unavailable_signers.lock().unwrap().pop_front() {
1279+
signer.set_ops_available(mask, false)
12791280
}
12801281
signer
12811282
}
@@ -1315,7 +1316,7 @@ impl TestKeysInterface {
13151316
disable_revocation_policy_check: false,
13161317
enforcement_states: Mutex::new(new_hash_map()),
13171318
expectations: Mutex::new(None),
1318-
unavailable_signers: Mutex::new(new_hash_set()),
1319+
unavailable_signers: Mutex::new(VecDeque::new()),
13191320
}
13201321
}
13211322

0 commit comments

Comments
 (0)