Skip to content

Commit 0cd353c

Browse files
committed
Drop unnecessary int reference in SCID conversion utilities
1 parent 2964751 commit 0cd353c

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

lightning/src/ln/monitor_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ fn do_chanmon_claim_value_coop_close(anchors: bool) {
209209
assert_eq!(shutdown_tx, nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0));
210210
assert_eq!(shutdown_tx.len(), 1);
211211

212-
let shutdown_tx_conf_height_a = block_from_scid(&mine_transaction(&nodes[0], &shutdown_tx[0]));
213-
let shutdown_tx_conf_height_b = block_from_scid(&mine_transaction(&nodes[1], &shutdown_tx[0]));
212+
let shutdown_tx_conf_height_a = block_from_scid(mine_transaction(&nodes[0], &shutdown_tx[0]));
213+
let shutdown_tx_conf_height_b = block_from_scid(mine_transaction(&nodes[1], &shutdown_tx[0]));
214214

215215
assert!(nodes[0].node.list_channels().is_empty());
216216
assert!(nodes[1].node.list_channels().is_empty());
@@ -736,7 +736,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) {
736736
check_spends!(commitment_tx, funding_tx);
737737
commitment_tx
738738
};
739-
let commitment_tx_conf_height_a = block_from_scid(&mine_transaction(&nodes[0], &commitment_tx));
739+
let commitment_tx_conf_height_a = block_from_scid(mine_transaction(&nodes[0], &commitment_tx));
740740
if nodes[0].connect_style.borrow().updates_best_block_first() {
741741
let mut txn = nodes[0].tx_broadcaster.txn_broadcast();
742742
assert_eq!(txn.len(), 1);
@@ -2674,14 +2674,14 @@ fn do_test_anchors_monitor_fixes_counterparty_payment_script_on_reload(confirm_c
26742674
// We should expect our round trip serialization check to fail as we're writing the monitor
26752675
// with the incorrect P2WPKH script but reading it with the correct P2WSH script.
26762676
*nodes[1].chain_monitor.expect_monitor_round_trip_fail.lock().unwrap() = Some(chan_id);
2677-
let commitment_tx_conf_height = block_from_scid(&mine_transaction(&nodes[1], &commitment_tx));
2677+
let commitment_tx_conf_height = block_from_scid(mine_transaction(&nodes[1], &commitment_tx));
26782678
let serialized_monitor = get_monitor!(nodes[1], chan_id).encode();
26792679
reload_node!(nodes[1], user_config, &nodes[1].node.encode(), &[&serialized_monitor], persister, chain_monitor, node_deserialized);
26802680
commitment_tx_conf_height
26812681
} else {
26822682
let serialized_monitor = get_monitor!(nodes[1], chan_id).encode();
26832683
reload_node!(nodes[1], user_config, &nodes[1].node.encode(), &[&serialized_monitor], persister, chain_monitor, node_deserialized);
2684-
let commitment_tx_conf_height = block_from_scid(&mine_transaction(&nodes[1], &commitment_tx));
2684+
let commitment_tx_conf_height = block_from_scid(mine_transaction(&nodes[1], &commitment_tx));
26852685
check_added_monitors(&nodes[1], 1);
26862686
check_closed_broadcast(&nodes[1], 1, true);
26872687
commitment_tx_conf_height

lightning/src/routing/gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ where U::Target: UtxoLookup, L::Target: Logger
698698
// Prior replies should use the number of blocks that fit into the reply. Overflow
699699
// safe since first_blocknum is always <= last SCID's block.
700700
else {
701-
(false, block_from_scid(batch.last().unwrap()) - first_blocknum)
701+
(false, block_from_scid(*batch.last().unwrap()) - first_blocknum)
702702
};
703703

704704
prev_batch_endblock = first_blocknum + number_of_blocks;

lightning/src/util/scid_utils.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ pub enum ShortChannelIdError {
3333
}
3434

3535
/// Extracts the block height (most significant 3-bytes) from the `short_channel_id`
36-
pub fn block_from_scid(short_channel_id: &u64) -> u32 {
36+
pub fn block_from_scid(short_channel_id: u64) -> u32 {
3737
return (short_channel_id >> 40) as u32;
3838
}
3939

4040
/// Extracts the tx index (bytes [2..4]) from the `short_channel_id`
41-
pub fn tx_index_from_scid(short_channel_id: &u64) -> u32 {
41+
pub fn tx_index_from_scid(short_channel_id: u64) -> u32 {
4242
return ((short_channel_id >> 16) & MAX_SCID_TX_INDEX) as u32;
4343
}
4444

4545
/// Extracts the vout (bytes [0..2]) from the `short_channel_id`
46-
pub fn vout_from_scid(short_channel_id: &u64) -> u16 {
46+
pub fn vout_from_scid(short_channel_id: u64) -> u16 {
4747
return ((short_channel_id) & MAX_SCID_VOUT_INDEX) as u16;
4848
}
4949

@@ -162,22 +162,22 @@ pub(crate) mod fake_scid {
162162

163163
/// Returns whether the given fake scid falls into the phantom namespace.
164164
pub fn is_valid_phantom(fake_scid_rand_bytes: &[u8; 32], scid: u64, chain_hash: &ChainHash) -> bool {
165-
let block_height = scid_utils::block_from_scid(&scid);
166-
let tx_index = scid_utils::tx_index_from_scid(&scid);
165+
let block_height = scid_utils::block_from_scid(scid);
166+
let tx_index = scid_utils::tx_index_from_scid(scid);
167167
let namespace = Namespace::Phantom;
168168
let valid_vout = namespace.get_encrypted_vout(block_height, tx_index, fake_scid_rand_bytes);
169169
block_height >= segwit_activation_height(chain_hash)
170-
&& valid_vout == scid_utils::vout_from_scid(&scid) as u8
170+
&& valid_vout == scid_utils::vout_from_scid(scid) as u8
171171
}
172172

173173
/// Returns whether the given fake scid falls into the intercept namespace.
174174
pub fn is_valid_intercept(fake_scid_rand_bytes: &[u8; 32], scid: u64, chain_hash: &ChainHash) -> bool {
175-
let block_height = scid_utils::block_from_scid(&scid);
176-
let tx_index = scid_utils::tx_index_from_scid(&scid);
175+
let block_height = scid_utils::block_from_scid(scid);
176+
let tx_index = scid_utils::tx_index_from_scid(scid);
177177
let namespace = Namespace::Intercept;
178178
let valid_vout = namespace.get_encrypted_vout(block_height, tx_index, fake_scid_rand_bytes);
179179
block_height >= segwit_activation_height(chain_hash)
180-
&& valid_vout == scid_utils::vout_from_scid(&scid) as u8
180+
&& valid_vout == scid_utils::vout_from_scid(scid) as u8
181181
}
182182

183183
#[cfg(test)]
@@ -248,14 +248,14 @@ pub(crate) mod fake_scid {
248248
let namespace = Namespace::Phantom;
249249
let fake_scid = namespace.get_fake_scid(500_000, &mainnet_genesis, &fake_scid_rand_bytes, &keys_manager);
250250

251-
let fake_height = scid_utils::block_from_scid(&fake_scid);
251+
let fake_height = scid_utils::block_from_scid(fake_scid);
252252
assert!(fake_height >= MAINNET_SEGWIT_ACTIVATION_HEIGHT);
253253
assert!(fake_height <= 500_000);
254254

255-
let fake_tx_index = scid_utils::tx_index_from_scid(&fake_scid);
255+
let fake_tx_index = scid_utils::tx_index_from_scid(fake_scid);
256256
assert!(fake_tx_index <= MAX_TX_INDEX);
257257

258-
let fake_vout = scid_utils::vout_from_scid(&fake_scid);
258+
let fake_vout = scid_utils::vout_from_scid(fake_scid);
259259
assert!(fake_vout < MAX_NAMESPACES as u16);
260260
}
261261
}
@@ -267,29 +267,29 @@ mod tests {
267267

268268
#[test]
269269
fn test_block_from_scid() {
270-
assert_eq!(block_from_scid(&0x000000_000000_0000), 0);
271-
assert_eq!(block_from_scid(&0x000001_000000_0000), 1);
272-
assert_eq!(block_from_scid(&0x000001_ffffff_ffff), 1);
273-
assert_eq!(block_from_scid(&0x800000_ffffff_ffff), 0x800000);
274-
assert_eq!(block_from_scid(&0xffffff_ffffff_ffff), 0xffffff);
270+
assert_eq!(block_from_scid(0x000000_000000_0000), 0);
271+
assert_eq!(block_from_scid(0x000001_000000_0000), 1);
272+
assert_eq!(block_from_scid(0x000001_ffffff_ffff), 1);
273+
assert_eq!(block_from_scid(0x800000_ffffff_ffff), 0x800000);
274+
assert_eq!(block_from_scid(0xffffff_ffffff_ffff), 0xffffff);
275275
}
276276

277277
#[test]
278278
fn test_tx_index_from_scid() {
279-
assert_eq!(tx_index_from_scid(&0x000000_000000_0000), 0);
280-
assert_eq!(tx_index_from_scid(&0x000000_000001_0000), 1);
281-
assert_eq!(tx_index_from_scid(&0xffffff_000001_ffff), 1);
282-
assert_eq!(tx_index_from_scid(&0xffffff_800000_ffff), 0x800000);
283-
assert_eq!(tx_index_from_scid(&0xffffff_ffffff_ffff), 0xffffff);
279+
assert_eq!(tx_index_from_scid(0x000000_000000_0000), 0);
280+
assert_eq!(tx_index_from_scid(0x000000_000001_0000), 1);
281+
assert_eq!(tx_index_from_scid(0xffffff_000001_ffff), 1);
282+
assert_eq!(tx_index_from_scid(0xffffff_800000_ffff), 0x800000);
283+
assert_eq!(tx_index_from_scid(0xffffff_ffffff_ffff), 0xffffff);
284284
}
285285

286286
#[test]
287287
fn test_vout_from_scid() {
288-
assert_eq!(vout_from_scid(&0x000000_000000_0000), 0);
289-
assert_eq!(vout_from_scid(&0x000000_000000_0001), 1);
290-
assert_eq!(vout_from_scid(&0xffffff_ffffff_0001), 1);
291-
assert_eq!(vout_from_scid(&0xffffff_ffffff_8000), 0x8000);
292-
assert_eq!(vout_from_scid(&0xffffff_ffffff_ffff), 0xffff);
288+
assert_eq!(vout_from_scid(0x000000_000000_0000), 0);
289+
assert_eq!(vout_from_scid(0x000000_000000_0001), 1);
290+
assert_eq!(vout_from_scid(0xffffff_ffffff_0001), 1);
291+
assert_eq!(vout_from_scid(0xffffff_ffffff_8000), 0x8000);
292+
assert_eq!(vout_from_scid(0xffffff_ffffff_ffff), 0xffff);
293293
}
294294

295295
#[test]

0 commit comments

Comments
 (0)