Skip to content

Commit c47acd7

Browse files
committed
Drop the Writeable::encode_with_len method in non-test buidls
There's not a lot of reason to keep it given its used in one place outside of tests, and this lets us clean up some of the byte_utils calls that are still lying around.
1 parent d225630 commit c47acd7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,21 +2475,22 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
24752475
break None;
24762476
}
24772477
{
2478-
let mut res = Vec::with_capacity(8 + 128);
2478+
let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 8 + 2));
24792479
if let Some(chan_update) = chan_update {
24802480
if code == 0x1000 | 11 || code == 0x1000 | 12 {
2481-
res.extend_from_slice(&byte_utils::be64_to_array(msg.amount_msat));
2481+
msg.amount_msat.write(&mut res).expect("Writes cannot fail");
24822482
}
24832483
else if code == 0x1000 | 13 {
2484-
res.extend_from_slice(&byte_utils::be32_to_array(msg.cltv_expiry));
2484+
msg.cltv_expiry.write(&mut res).expect("Writes cannot fail");
24852485
}
24862486
else if code == 0x1000 | 20 {
24872487
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
2488-
res.extend_from_slice(&byte_utils::be16_to_array(0));
2488+
0u16.write(&mut res).expect("Writes cannot fail");
24892489
}
2490-
res.extend_from_slice(&chan_update.encode_with_len()[..]);
2490+
(chan_update.serialized_length() as u16).write(&mut res).expect("Writes cannot fail");
2491+
chan_update.write(&mut res).expect("Writes cannot fail");
24912492
}
2492-
return_err!(err, code, &res[..]);
2493+
return_err!(err, code, &res.0[..]);
24932494
}
24942495
}
24952496
}

lightning/src/util/ser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub trait Writeable {
174174
}
175175

176176
/// Writes self out to a Vec<u8>
177+
#[cfg(test)]
177178
fn encode_with_len(&self) -> Vec<u8> {
178179
let mut msg = VecWriter(Vec::new());
179180
0u16.write(&mut msg).unwrap();

0 commit comments

Comments
 (0)