Skip to content

Commit af14a71

Browse files
committed
f Revert the fallback logic
.. instead we just move 50 ms up to first position
1 parent 31c0576 commit af14a71

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

lightning-background-processor/src/fwd_batch.rs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,12 @@ impl BatchDelay {
3232

3333
fn rand_batch_delay_millis() -> u16 {
3434
const FALLBACK_DELAY: u16 = 50;
35-
let delay;
35+
const USIZE_LEN: usize = core::mem::size_of::<usize>();
36+
let mut random_bytes = [0u8; USIZE_LEN];
37+
possiblyrandom::getpossiblyrandom(&mut random_bytes);
3638

37-
#[cfg(feature = "std")]
38-
{
39-
const USIZE_LEN: usize = core::mem::size_of::<usize>();
40-
let mut random_bytes = [0u8; USIZE_LEN];
41-
possiblyrandom::getpossiblyrandom(&mut random_bytes);
42-
43-
let index = usize::from_be_bytes(random_bytes) % FWD_DELAYS_MILLIS.len();
44-
delay = *FWD_DELAYS_MILLIS.get(index).unwrap_or(&FALLBACK_DELAY)
45-
}
46-
#[cfg(not(feature = "std"))]
47-
{
48-
// On no-std, `getpossiblyrandom` will return 0 values, having us always pick the first
49-
// element of `FWD_DELAYS_MILLIS`. Here, we opt to instead default to `FALLBACK_DELAY` in
50-
// this case.
51-
delay = FALLBACK_DELAY
52-
}
53-
54-
delay
39+
let index = usize::from_be_bytes(random_bytes) % FWD_DELAYS_MILLIS.len();
40+
*FWD_DELAYS_MILLIS.get(index).unwrap_or(&FALLBACK_DELAY)
5541
}
5642

5743
// An array of potential forwarding delays (log-normal distribution, 10000 samples, mean = 50, sd = 0.5), generated via the following R-script:
@@ -63,25 +49,24 @@ fn rand_batch_delay_millis() -> u16 {
6349
// log_normal_data <- round(rlnorm(n, meanlog = meanlog, sdlog = sdlog))
6450
// cat(log_normal_data, file = "log_normal_data.txt", sep = ", ")
6551
// ```
66-
#[cfg(feature = "std")]
6752
static FWD_DELAYS_MILLIS: [u16; 10000] = [
68-
38, 45, 109, 52, 53, 118, 63, 27, 35, 40, 92, 60, 61, 53, 38, 122, 64, 19, 71, 39, 29, 45, 30,
69-
35, 37, 22, 76, 54, 28, 94, 62, 43, 78, 78, 75, 71, 66, 48, 43, 41, 35, 45, 27, 148, 91, 29,
70-
41, 40, 74, 48, 57, 49, 49, 99, 45, 107, 23, 67, 53, 56, 60, 39, 42, 30, 29, 58, 63, 51, 79,
71-
139, 39, 16, 83, 35, 35, 83, 43, 27, 55, 47, 50, 61, 42, 69, 45, 59, 87, 62, 42, 89, 82, 66,
72-
56, 37, 99, 37, 149, 108, 44, 30, 35, 57, 44, 42, 31, 49, 34, 22, 41, 79, 38, 68, 22, 49, 65,
73-
58, 53, 36, 33, 30, 53, 31, 39, 44, 126, 36, 56, 52, 31, 48, 103, 63, 51, 40, 18, 88, 24, 72,
74-
130, 24, 71, 44, 23, 23, 22, 38, 24, 71, 143, 26, 74, 73, 59, 30, 47, 43, 66, 42, 81, 41, 85,
75-
30, 27, 253, 41, 58, 69, 39, 65, 60, 45, 52, 49, 145, 35, 29, 51, 58, 62, 40, 29, 94, 42, 32,
76-
44, 45, 87, 52, 73, 39, 56, 43, 52, 32, 26, 136, 68, 27, 37, 28, 150, 96, 44, 66, 41, 39, 34,
77-
37, 114, 49, 53, 56, 93, 39, 30, 116, 40, 35, 27, 26, 38, 68, 87, 71, 42, 52, 35, 35, 78, 30,
78-
133, 48, 56, 35, 38, 26, 46, 62, 59, 34, 34, 39, 106, 28, 46, 129, 48, 25, 36, 64, 41, 38, 42,
79-
52, 111, 48, 86, 69, 47, 23, 39, 39, 51, 96, 157, 108, 47, 21, 41, 52, 76, 81, 70, 25, 76, 40,
80-
55, 52, 62, 51, 22, 72, 61, 44, 53, 53, 56, 114, 45, 54, 90, 85, 89, 37, 136, 52, 127, 25, 51,
81-
93, 35, 34, 31, 30, 40, 59, 18, 56, 93, 138, 96, 73, 21, 37, 42, 71, 47, 27, 116, 79, 56, 92,
82-
26, 70, 38, 70, 49, 69, 97, 50, 83, 28, 35, 107, 60, 18, 25, 45, 77, 48, 68, 81, 115, 51, 49,
83-
21, 53, 38, 31, 46, 83, 18, 40, 53, 32, 59, 61, 49, 15, 181, 45, 69, 57, 83, 75, 45, 60, 31,
84-
77, 40, 167, 22, 40, 76, 65, 37, 30, 54, 50, 20, 51, 55, 55, 30, 63, 100, 63, 28, 40, 59, 36,
53+
50, 38, 45, 109, 52, 53, 118, 63, 27, 35, 40, 92, 60, 61, 53, 38, 122, 64, 19, 71, 39, 29, 45,
54+
30, 35, 37, 22, 76, 54, 28, 94, 62, 43, 78, 78, 75, 71, 66, 48, 43, 41, 35, 45, 27, 148, 91,
55+
29, 41, 40, 74, 48, 57, 49, 49, 99, 45, 107, 23, 67, 53, 56, 60, 39, 42, 30, 29, 58, 63, 51,
56+
79, 139, 39, 16, 83, 35, 35, 83, 43, 27, 55, 47, 50, 61, 42, 69, 45, 59, 87, 62, 42, 89, 82,
57+
66, 56, 37, 99, 37, 149, 108, 44, 30, 35, 57, 44, 42, 31, 49, 34, 22, 41, 79, 38, 68, 22, 49,
58+
65, 58, 53, 36, 33, 30, 53, 31, 39, 44, 126, 36, 56, 52, 31, 48, 103, 63, 51, 40, 18, 88, 24,
59+
72, 130, 24, 71, 44, 23, 23, 22, 38, 24, 71, 143, 26, 74, 73, 59, 30, 47, 43, 66, 42, 81, 41,
60+
85, 30, 27, 253, 41, 58, 69, 39, 65, 60, 45, 52, 49, 145, 35, 29, 51, 58, 62, 40, 29, 94, 42,
61+
32, 44, 45, 87, 52, 73, 39, 56, 43, 52, 32, 26, 136, 68, 27, 37, 28, 150, 96, 44, 66, 41, 39,
62+
34, 37, 114, 49, 53, 56, 93, 39, 30, 116, 40, 35, 27, 26, 38, 68, 87, 71, 42, 52, 35, 35, 78,
63+
30, 133, 48, 56, 35, 38, 26, 46, 62, 59, 34, 34, 39, 106, 28, 46, 129, 48, 25, 36, 64, 41, 38,
64+
42, 52, 111, 48, 86, 69, 47, 23, 39, 39, 51, 96, 157, 108, 47, 21, 41, 52, 76, 81, 70, 25, 76,
65+
40, 55, 52, 62, 51, 22, 72, 61, 44, 53, 53, 56, 114, 45, 54, 90, 85, 89, 37, 136, 52, 127, 25,
66+
51, 93, 35, 34, 31, 30, 40, 59, 18, 56, 93, 138, 96, 73, 21, 37, 42, 71, 47, 27, 116, 79, 56,
67+
92, 26, 70, 38, 70, 49, 69, 97, 50, 83, 28, 35, 107, 60, 18, 25, 45, 77, 48, 68, 81, 115, 51,
68+
49, 21, 53, 38, 31, 46, 83, 18, 40, 53, 32, 59, 61, 49, 15, 181, 45, 69, 57, 83, 75, 45, 60,
69+
31, 77, 40, 167, 22, 40, 76, 65, 37, 30, 54, 20, 51, 55, 55, 30, 63, 100, 63, 28, 40, 59, 36,
8570
17, 78, 33, 38, 106, 34, 76, 27, 42, 48, 28, 36, 49, 70, 22, 42, 73, 38, 56, 64, 57, 69, 47,
8671
41, 13, 48, 62, 65, 38, 122, 58, 53, 94, 35, 40, 166, 50, 113, 24, 45, 60, 58, 30, 50, 29, 71,
8772
86, 16, 93, 27, 63, 70, 45, 36, 54, 62, 78, 18, 22, 102, 84, 62, 71, 79, 13, 87, 39, 56, 43,

0 commit comments

Comments
 (0)