Skip to content

Commit 17d6644

Browse files
committed
Clean up full_stack_target InMemorySigner builder
The code was a bit too long to begin with, and rustfmt made a total mess of it, so instead we should be building with more intermediate variables.
1 parent ec6fb50 commit 17d6644

File tree

1 file changed

+21
-81
lines changed

1 file changed

+21
-81
lines changed

fuzz/src/full_stack.rs

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -440,89 +440,29 @@ impl SignerProvider for KeyProvider {
440440
[ctr; 32]
441441
}
442442

443-
fn derive_channel_signer(
444-
&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32],
445-
) -> Self::EcdsaSigner {
443+
fn derive_channel_signer(&self, value: u64, keys_id: [u8; 32]) -> Self::EcdsaSigner {
446444
let secp_ctx = Secp256k1::signing_only();
447-
let ctr = channel_keys_id[0];
445+
let ctr = keys_id[0];
448446
let (inbound, state) = self.signer_state.borrow().get(&ctr).unwrap().clone();
449-
TestChannelSigner::new_with_revoked(
450-
if inbound {
451-
InMemorySigner::new(
452-
&secp_ctx,
453-
SecretKey::from_slice(&[
454-
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,
455-
0, 0, 0, 0, 0, 1, ctr,
456-
])
457-
.unwrap(),
458-
SecretKey::from_slice(&[
459-
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,
460-
0, 0, 0, 0, 0, 2, ctr,
461-
])
462-
.unwrap(),
463-
SecretKey::from_slice(&[
464-
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,
465-
0, 0, 0, 0, 0, 3, ctr,
466-
])
467-
.unwrap(),
468-
SecretKey::from_slice(&[
469-
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,
470-
0, 0, 0, 0, 0, 4, ctr,
471-
])
472-
.unwrap(),
473-
SecretKey::from_slice(&[
474-
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,
475-
0, 0, 0, 0, 0, 5, ctr,
476-
])
477-
.unwrap(),
478-
[
479-
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,
480-
0, 0, 0, 0, 0, 6, ctr,
481-
],
482-
channel_value_satoshis,
483-
channel_keys_id,
484-
channel_keys_id,
485-
)
486-
} else {
487-
InMemorySigner::new(
488-
&secp_ctx,
489-
SecretKey::from_slice(&[
490-
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,
491-
0, 0, 0, 0, 0, 7, ctr,
492-
])
493-
.unwrap(),
494-
SecretKey::from_slice(&[
495-
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,
496-
0, 0, 0, 0, 0, 8, ctr,
497-
])
498-
.unwrap(),
499-
SecretKey::from_slice(&[
500-
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,
501-
0, 0, 0, 0, 0, 9, ctr,
502-
])
503-
.unwrap(),
504-
SecretKey::from_slice(&[
505-
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,
506-
0, 0, 0, 0, 0, 10, ctr,
507-
])
508-
.unwrap(),
509-
SecretKey::from_slice(&[
510-
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,
511-
0, 0, 0, 0, 0, 11, ctr,
512-
])
513-
.unwrap(),
514-
[
515-
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,
516-
0, 0, 0, 0, 0, 12, ctr,
517-
],
518-
channel_value_satoshis,
519-
channel_keys_id,
520-
channel_keys_id,
521-
)
522-
},
523-
state,
524-
false,
525-
)
447+
448+
let (a, b, c, d, e, f);
449+
let mut key = [0; 32];
450+
key[31] = ctr;
451+
key[30] = 1 + if inbound { 0 } else { 6 };
452+
a = SecretKey::from_slice(&key).unwrap();
453+
key[30] = 2 + if inbound { 0 } else { 6 };
454+
b = SecretKey::from_slice(&key).unwrap();
455+
key[30] = 3 + if inbound { 0 } else { 6 };
456+
c = SecretKey::from_slice(&key).unwrap();
457+
key[30] = 4 + if inbound { 0 } else { 6 };
458+
d = SecretKey::from_slice(&key).unwrap();
459+
key[30] = 5 + if inbound { 0 } else { 6 };
460+
e = SecretKey::from_slice(&key).unwrap();
461+
key[30] = 6 + if inbound { 0 } else { 6 };
462+
f = key;
463+
let signer = InMemorySigner::new(&secp_ctx, a, b, c, d, e, f, value, keys_id, keys_id);
464+
465+
TestChannelSigner::new_with_revoked(signer, state, false)
526466
}
527467

528468
fn read_chan_signer(&self, mut data: &[u8]) -> Result<TestChannelSigner, DecodeError> {

0 commit comments

Comments
 (0)