Skip to content

Commit 40f7aa8

Browse files
smite-scenarios: use Features for feature bits in setup
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
1 parent 61e5b67 commit 40f7aa8

1 file changed

Lines changed: 23 additions & 38 deletions

File tree

‎smite-scenarios/src/scenarios/setup.rs‎

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::time::Duration;
44

5-
use smite::bolt::{Init, InitTlvs, Message};
5+
use smite::bolt::{FeatureBit, Features, Init, InitTlvs, Message};
66
use smite::noise::NoiseConnection;
77
use smite::scenarios::ScenarioError;
88

@@ -30,49 +30,34 @@ pub trait SnapshotSetup<T: Target> {
3030
fn setup(target: &T) -> Result<(NoiseConnection, ProgramContext), ScenarioError>;
3131
}
3232

33-
/// Clears a feature bit from a feature vector.
34-
///
35-
/// Feature vectors are encoded as big-endian byte arrays where bit N lives in
36-
/// byte `features[len - 1 - N/8]` at position `N % 8`.
37-
fn clear_feature_bit(features: &mut [u8], bit: usize) {
38-
let byte_index = features.len().checked_sub(1 + bit / 8);
39-
if let Some(i) = byte_index {
40-
features[i] &= !(1 << (bit % 8));
41-
}
42-
}
43-
44-
/// Gossip-related feature bits (BOLT 9): `gossip_queries` (6/7),
45-
/// `gossip_queries_ex` (10/11). Stripped so the target doesn't send
46-
/// `gossip_timestamp_filter` or other gossip noise during execution.
47-
const GOSSIP_FEATURE_BITS: &[usize] = &[6, 7, 10, 11];
48-
49-
/// Feature bits that force a dual-funded flow when both peers support them:
50-
/// `option_dual_fund` (28/29). Eclair in particular will not allow
51-
/// single-funded flows if either of these feature bits is set, so we strip them
52-
/// when fuzzing the single-funded flow.
53-
const DUAL_FUNDING_FEATURE_BITS: &[usize] = &[28, 29];
54-
55-
/// Peer storage feature bits: `option_provide_storage` (42/43). When enabled,
56-
/// peers may send `peer_storage` and `peer_storage_retrieval` messages at
57-
/// arbitrary times. Disabling these bits eliminates peer storage noise.
58-
const PEER_STORAGE_FEATURE_BITS: &[usize] = &[42, 43];
33+
/// Features stripped from our echoed `init` so the target stays on the single
34+
/// funded flow and doesn't emit unrelated noise:
35+
/// - `gossip_queries` (6/7), `gossip_queries_ex` (10/11): Stripped so the
36+
/// target doesn't send `gossip_timestamp_filter` or other gossip noise during
37+
/// execution.
38+
/// - `option_dual_fund` (28/29): Eclair in particular will not allow
39+
/// single-funded flows if either of these feature bits is set.
40+
/// - `option_provide_storage` (42/43): When enabled, peers may send
41+
/// `peer_storage` and `peer_storage_retrieval` messages at arbitrary times.
42+
const STRIPPED_FEATURES: &[FeatureBit] = &[
43+
Features::GOSSIP_QUERIES,
44+
Features::GOSSIP_QUERIES_EX,
45+
Features::OPTION_DUAL_FUND,
46+
Features::OPTION_PROVIDE_STORAGE,
47+
];
5948

6049
/// Creates an `init` that echoes the received features with bits stripped that
6150
/// would steer the target away from the single-funded `open_channel` flow.
6251
fn init_for_single_funded(received: &Init) -> Init {
63-
let mut globalfeatures = received.globalfeatures.clone();
64-
let mut features = received.features.clone();
65-
for &bit in GOSSIP_FEATURE_BITS
66-
.iter()
67-
.chain(DUAL_FUNDING_FEATURE_BITS)
68-
.chain(PEER_STORAGE_FEATURE_BITS)
69-
{
70-
clear_feature_bit(&mut globalfeatures, bit);
71-
clear_feature_bit(&mut features, bit);
52+
let mut globalfeatures = Features::from(received.globalfeatures.clone());
53+
let mut features = Features::from(received.features.clone());
54+
for &bit in STRIPPED_FEATURES {
55+
globalfeatures.clear_feature(bit);
56+
features.clear_feature(bit);
7257
}
7358
Init {
74-
globalfeatures,
75-
features,
59+
globalfeatures: globalfeatures.into_bytes(),
60+
features: features.into_bytes(),
7661
tlvs: InitTlvs::default(),
7762
}
7863
}

0 commit comments

Comments
 (0)