Skip to content

Migrate ChannelMonitor writing/reading to new serialization framework #191

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
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: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lightning"
version = "0.0.4"
version = "0.0.5"
authors = ["Matt Corallo"]
license = "Apache-2.0"
repository = "https://github.com/rust-bitcoin/rust-lightning/"
Expand Down Expand Up @@ -37,3 +37,6 @@ features = ["bitcoinconsensus"]

[dev-dependencies]
hex = "0.3"

[profile.dev]
opt-level = 1
23 changes: 20 additions & 3 deletions fuzz/fuzz_targets/chanmon_deser_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ extern crate lightning;

use lightning::ln::channelmonitor;
use lightning::util::reset_rng_state;
use lightning::util::ser::{Readable, Writer};

use std::io::Cursor;

struct VecWriter(Vec<u8>);
impl Writer for VecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
fn size_hint(&mut self, size: usize) {
self.0.reserve_exact(size);
}
}

#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
if let Some(monitor) = channelmonitor::ChannelMonitor::deserialize(data) {
assert!(channelmonitor::ChannelMonitor::deserialize(&monitor.serialize_for_disk()[..]).unwrap() == monitor);
monitor.serialize_for_watchtower();
if let Ok(monitor) = channelmonitor::ChannelMonitor::read(&mut Cursor::new(data)) {
let mut w = VecWriter(Vec::new());
monitor.write_for_disk(&mut w).unwrap();
assert!(channelmonitor::ChannelMonitor::read(&mut Cursor::new(&w.0)).unwrap() == monitor);
w.0.clear();
monitor.write_for_watchtower(&mut w).unwrap();
}
}

Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/router_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,12 @@ pub fn do_test(data: &[u8]) {
match <($MsgType)>::read(&mut reader) {
Ok(msg) => msg,
Err(e) => match e {
msgs::DecodeError::UnknownRealmByte => return,
msgs::DecodeError::UnknownVersion => return,
msgs::DecodeError::UnknownRequiredFeature => return,
msgs::DecodeError::BadPublicKey => return,
msgs::DecodeError::BadSignature => return,
msgs::DecodeError::BadText => return,
msgs::DecodeError::InvalidValue => return,
msgs::DecodeError::ExtraAddressesPerType => return,
msgs::DecodeError::BadLengthDescriptor => return,
msgs::DecodeError::ShortRead => panic!("We picked the length..."),
msgs::DecodeError::InvalidValue => panic!("Should not happen with p2p message decoding"),
msgs::DecodeError::Io(e) => panic!(format!("{}", e)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ impl ChannelManager {
match msgs::OnionHopData::read(&mut Cursor::new(&decoded[..])) {
Err(err) => {
let error_code = match err {
msgs::DecodeError::UnknownRealmByte => 0x4000 | 1,
msgs::DecodeError::UnknownVersion => 0x4000 | 1, // unknown realm byte
_ => 0x2000 | 2, // Should never happen
};
return_err!("Unable to decode our hop data", error_code, &[0;0]);
Expand Down
Loading