Skip to content

Fix what bolt2_open_channel_sending_node_checks_part1 tests #1317

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

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6001,7 +6001,7 @@ fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on i
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
//Force duplicate channel ids
for node in nodes.iter() {
*node.keys_manager.override_channel_id_priv.lock().unwrap() = Some([0; 32]);
*node.keys_manager.override_random_bytes.lock().unwrap() = Some([0; 32]);
}

// BOLT #2 spec: Sending node must ensure temporary_channel_id is unique from any other channel ID with the same peer.
Expand All @@ -6010,9 +6010,10 @@ fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on i
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).unwrap();
let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &node0_to_1_send_open_channel);
get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());

//Create a second channel with a channel_id collision
assert!(nodes[0].node.create_channel(nodes[0].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).is_err());
assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).is_err());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fn test_onion_failure() {
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config), Some(config), Some(node_2_cfg)]);
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
for node in nodes.iter() {
*node.keys_manager.override_session_priv.lock().unwrap() = Some([3; 32]);
*node.keys_manager.override_random_bytes.lock().unwrap() = Some([3; 32]);
}
let channels = [create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()), create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known())];
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 40000);
Expand Down Expand Up @@ -693,7 +693,7 @@ fn test_phantom_invalid_onion_payload() {

// We'll use the session priv later when constructing an invalid onion packet.
let session_priv = [3; 32];
*nodes[0].keys_manager.override_session_priv.lock().unwrap() = Some(session_priv);
*nodes[0].keys_manager.override_random_bytes.lock().unwrap() = Some(session_priv);
nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret)).unwrap();
check_added_monitors!(nodes[0], 1);
let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
Expand Down
19 changes: 5 additions & 14 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ impl Logger for TestLogger {

pub struct TestKeysInterface {
pub backing: keysinterface::PhantomKeysManager,
pub override_session_priv: Mutex<Option<[u8; 32]>>,
pub override_channel_id_priv: Mutex<Option<[u8; 32]>>,
pub override_random_bytes: Mutex<Option<[u8; 32]>>,
pub disable_revocation_policy_check: bool,
enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
Expand Down Expand Up @@ -506,16 +505,9 @@ impl keysinterface::KeysInterface for TestKeysInterface {
}

fn get_secure_random_bytes(&self) -> [u8; 32] {
let override_channel_id = self.override_channel_id_priv.lock().unwrap();
let override_session_key = self.override_session_priv.lock().unwrap();
if override_channel_id.is_some() && override_session_key.is_some() {
panic!("We don't know which override key to use!");
}
if let Some(key) = &*override_channel_id {
return *key;
}
if let Some(key) = &*override_session_key {
return *key;
let override_random_bytes = self.override_random_bytes.lock().unwrap();
if let Some(bytes) = &*override_random_bytes {
return *bytes;
}
self.backing.get_secure_random_bytes()
}
Expand Down Expand Up @@ -543,8 +535,7 @@ impl TestKeysInterface {
let now = Duration::from_secs(genesis_block(network).header.time as u64);
Self {
backing: keysinterface::PhantomKeysManager::new(seed, now.as_secs(), now.subsec_nanos(), seed),
override_session_priv: Mutex::new(None),
override_channel_id_priv: Mutex::new(None),
override_random_bytes: Mutex::new(None),
disable_revocation_policy_check: false,
enforcement_states: Mutex::new(HashMap::new()),
expectations: Mutex::new(None),
Expand Down