[dependencies]
bitcoin = "0.18"
bitcoin_hashes = "0.3"
-rand = "0.4"
secp256k1 = "0.12"
[dev-dependencies.bitcoin]
[dev-dependencies]
hex = "0.3"
+rand = "0.4"
[profile.dev]
opt-level = 1
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use lightning::ln::channelmonitor;
-use lightning::util::reset_rng_state;
use lightning::util::ser::{ReadableArgs, Writer};
mod utils;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
let logger = Arc::new(test_logger::TestLogger::new("".to_owned()));
if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) {
let mut w = VecWriter(Vec::new());
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage};
use lightning::ln::router::{Route, RouteHop};
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, HandleError, UpdateAddHTLC, LocalFeatures};
-use lightning::util::{reset_rng_state, events};
+use lightning::util::events;
use lightning::util::logger::Logger;
use lightning::util::config::UserConfig;
use lightning::util::events::{EventsProvider, MessageSendEventsProvider};
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
-
let fee_est = Arc::new(FuzzEstimator{});
let broadcast = Arc::new(TestBroadcaster{});
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
use lightning::ln::router::Router;
use lightning::util::events::{EventsProvider,Event};
-use lightning::util::reset_rng_state;
use lightning::util::logger::Logger;
use lightning::util::config::UserConfig;
#[inline]
pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
- reset_rng_state();
-
let input = Arc::new(InputData {
data: data.to_vec(),
read_pos: AtomicUsize::new(0),
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::AcceptChannel, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::AnnouncementSignatures, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_exact!(msgs::ChannelAnnouncement, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::ChannelReestablish, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_exact!(msgs::ChannelUpdate, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::ClosingSigned, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::CommitmentSigned, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::DecodedOnionErrorPacket, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_hole!(msgs::ErrorMessage, data, 32, 2);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::FundingCreated, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::FundingLocked, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::FundingSigned, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::Init, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_exact!(msgs::NodeAnnouncement, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_hole!(msgs::OnionHopData, data, 1+8+8+4, 12);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::OpenChannel, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_simple!(msgs::Ping, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_simple!(msgs::Pong, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::RevokeAndACK, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::Shutdown, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
TEST_MSG!(msgs::MSG_TARGET, dataEXTRA_ARGS);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg_hole!(msgs::UpdateAddHTLC, data, 85, 33);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::UpdateFailHTLC, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::UpdateFailMalformedHTLC, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::UpdateFee, data);
}
extern crate lightning;
use lightning::ln::msgs;
-use lightning::util::reset_rng_state;
mod utils;
use utils::VecWriter;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
test_msg!(msgs::UpdateFulfillHTLC, data);
}
extern crate secp256k1;
use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;
-use lightning::util::reset_rng_state;
use secp256k1::key::{PublicKey,SecretKey};
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
-
let mut read_pos = 0;
macro_rules! get_slice {
($len: expr) => {
use lightning::ln::msgs;
use lightning::ln::msgs::{RoutingMessageHandler};
use lightning::ln::router::{Router, RouteHint};
-use lightning::util::reset_rng_state;
use lightning::util::logger::Logger;
use lightning::util::ser::Readable;
#[inline]
pub fn do_test(data: &[u8]) {
- reset_rng_state();
-
let input = Arc::new(InputData {
data: data.to_vec(),
read_pos: AtomicUsize::new(0),
extern crate bitcoin;
extern crate bitcoin_hashes;
-extern crate rand;
extern crate secp256k1;
+#[cfg(test)] extern crate rand;
#[cfg(test)] extern crate hex;
#[macro_use]
use ln::msgs::{ChannelMessageHandler, DecodeError, HandleError};
use chain::keysinterface::KeysInterface;
use util::config::UserConfig;
-use util::{byte_utils, events, rng};
+use util::{byte_utils, events};
use util::ser::{Readable, ReadableArgs, Writeable, Writer};
use util::chacha20::ChaCha20;
use util::logger::Logger;
}
}
-/// We hold back HTLCs we intend to relay for a random interval in the range (this, 5*this). This
-/// provides some limited amount of privacy. Ideally this would range from somewhere like 1 second
-/// to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly. We could
-/// probably increase this significantly.
-const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS: u32 = 50;
+/// We hold back HTLCs we intend to relay for a random interval greater than this (see
+/// Event::PendingHTLCsForwardable for the API guidelines indicating how long should be waited).
+/// This provides some limited amount of privacy. Ideally this would range from somewhere like one
+/// second to 30 seconds, but people expect lightning to be, you know, kinda fast, sadly.
+const MIN_HTLC_RELAY_HOLDING_CELL_MILLIS: u64 = 100;
pub(super) enum HTLCForwardInfo {
AddHTLC {
let mut forward_event = None;
if channel_state_lock.forward_htlcs.is_empty() {
- forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
+ forward_event = Some(Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS));
}
match channel_state_lock.forward_htlcs.entry(short_channel_id) {
hash_map::Entry::Occupied(mut entry) => {
if !pending_forwards.is_empty() {
let mut channel_state = self.channel_state.lock().unwrap();
if channel_state.forward_htlcs.is_empty() {
- forward_event = Some(Duration::from_millis(((rng::rand_f32() * 4.0 + 1.0) * MIN_HTLC_RELAY_HOLDING_CELL_MILLIS as f32) as u64));
+ forward_event = Some(Duration::from_millis(MIN_HTLC_RELAY_HOLDING_CELL_MILLIS))
}
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
match channel_state.forward_htlcs.entry(forward_info.short_channel_id) {
/// Used to indicate that ChannelManager::process_pending_htlc_forwards should be called at a
/// time in the future.
PendingHTLCsForwardable {
- /// The amount of time that should be waited prior to calling process_pending_htlc_forwards
+ /// The minimum amount of time that should be waited prior to calling
+ /// process_pending_htlc_forwards. To increase the effort required to correlate payments,
+ /// you should wait a random amount of time in roughly the range (now + time_forwardable,
+ /// now + 5*time_forwardable).
time_forwardable: Duration,
},
/// Used to indicate that an output was generated on-chain which you should know how to spend.
pub(crate) mod poly1305;
pub(crate) mod chacha20poly1305rfc;
pub(crate) mod internal_traits;
-pub(crate) mod rng;
pub(crate) mod transaction_utils;
#[macro_use]
pub mod logger;
pub mod config;
-#[cfg(feature = "fuzztarget")]
-pub use self::rng::{reset_rng_state, fill_bytes};
-
#[cfg(test)]
pub(crate) mod test_utils;
+++ /dev/null
-#[cfg(not(feature = "fuzztarget"))]
-mod real_rng {
- use rand::{thread_rng,Rng};
-
- pub fn fill_bytes(data: &mut [u8]) {
- let mut rng = thread_rng();
- rng.fill_bytes(data);
- }
-
- pub fn rand_f32() -> f32 {
- let mut rng = thread_rng();
- rng.next_f32()
- }
-}
-#[cfg(not(feature = "fuzztarget"))]
-pub use self::real_rng::*;
-
-#[cfg(feature = "fuzztarget")]
-mod fuzzy_rng {
- use util::byte_utils;
-
- static mut RNG_ITER: u64 = 0;
-
- pub fn fill_bytes(data: &mut [u8]) {
- let rng = unsafe { RNG_ITER += 1; RNG_ITER -1 };
- for i in 0..data.len() / 8 {
- data[i*8..(i+1)*8].copy_from_slice(&byte_utils::be64_to_array(rng));
- }
- let rem = data.len() % 8;
- let off = data.len() - rem;
- data[off..].copy_from_slice(&byte_utils::be64_to_array(rng)[0..rem]);
- }
-
- pub fn rand_f32() -> f32 {
- let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
- f64::from_bits(rng) as f32
- }
-
- pub fn reset_rng_state() {
- unsafe { RNG_ITER = 0; }
- }
-}
-#[cfg(feature = "fuzztarget")]
-pub use self::fuzzy_rng::*;