Skip to content

Commit 0d16296

Browse files
authored
Merge pull request #367 from TheBlueMatt/2019-07-fst-unique-channels
Make temporary channel ids unique in full_stack_target
2 parents 487452f + e5c8f05 commit 0d16296

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::collections::{HashMap, hash_map};
4949
use std::cmp;
5050
use std::hash::Hash;
5151
use std::sync::Arc;
52-
use std::sync::atomic::{AtomicU8,AtomicUsize,Ordering};
52+
use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering};
5353

5454
#[inline]
5555
pub fn slice_to_be16(v: &[u8]) -> u16 {
@@ -236,7 +236,7 @@ impl<'a> Drop for MoneyLossDetector<'a> {
236236

237237
struct KeyProvider {
238238
node_secret: SecretKey,
239-
counter: AtomicU8,
239+
counter: AtomicU64,
240240
}
241241
impl KeysInterface for KeyProvider {
242242
fn get_node_secret(&self) -> SecretKey {
@@ -256,7 +256,7 @@ impl KeysInterface for KeyProvider {
256256
}
257257

258258
fn get_channel_keys(&self, inbound: bool) -> ChannelKeys {
259-
let ctr = self.counter.fetch_add(1, Ordering::Relaxed);
259+
let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;
260260
if inbound {
261261
ChannelKeys {
262262
funding_key: SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ctr]).unwrap(),
@@ -279,13 +279,14 @@ impl KeysInterface for KeyProvider {
279279
}
280280

281281
fn get_session_key(&self) -> SecretKey {
282-
let ctr = self.counter.fetch_add(1, Ordering::Relaxed);
282+
let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;
283283
SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, ctr]).unwrap()
284284
}
285285

286286
fn get_channel_id(&self) -> [u8; 32] {
287287
let ctr = self.counter.fetch_add(1, Ordering::Relaxed);
288-
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, ctr]
288+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
289+
(ctr >> 8*7) as u8, (ctr >> 8*6) as u8, (ctr >> 8*5) as u8, (ctr >> 8*4) as u8, (ctr >> 8*3) as u8, (ctr >> 8*2) as u8, (ctr >> 8*1) as u8, 14, (ctr >> 8*0) as u8]
289290
}
290291
}
291292

@@ -326,7 +327,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
326327
let broadcast = Arc::new(TestBroadcaster{});
327328
let monitor = channelmonitor::SimpleManyChannelMonitor::new(watch.clone(), broadcast.clone(), Arc::clone(&logger), fee_est.clone());
328329

329-
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone(), counter: AtomicU8::new(0) });
330+
let keys_manager = Arc::new(KeyProvider { node_secret: our_network_key.clone(), counter: AtomicU64::new(0) });
330331
let mut config = UserConfig::new();
331332
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
332333
config.channel_options.announced_channel = get_slice!(1)[0] != 0;

0 commit comments

Comments
 (0)