1pub use crate::{
13 discovery::DEFAULT_KADEMLIA_REPLICATION_FACTOR,
14 peer_store::PeerStoreProvider,
15 protocol::{notification_service, NotificationsSink, ProtocolHandlePair},
16 request_responses::{
17 IncomingRequest, OutgoingResponse, ProtocolConfig as RequestResponseConfig,
18 },
19 service::{
20 metrics::NotificationMetrics,
21 traits::{NotificationConfig, NotificationService, PeerStore},
22 },
23 types::ProtocolName,
24};
25
26use crate::types::{
27 multiaddr::{self, Multiaddr},
28 PeerId,
29};
30pub use crate::{build_multiaddr, types::ed25519};
31
32use crate::service::{ensure_addresses_consistent_with_transport, traits::NetworkBackend};
33use codec::Encode;
34use soil_prometheus::Registry;
35use zeroize::Zeroize;
36
37pub use crate::common::{
38 role::{Role, Roles},
39 sync::SyncMode,
40 ExHashT,
41};
42
43use subsoil::runtime::traits::Block as BlockT;
44
45use std::{
46 error::Error,
47 fmt, fs,
48 future::Future,
49 io::{self, Write},
50 iter,
51 net::Ipv4Addr,
52 num::NonZeroUsize,
53 path::{Path, PathBuf},
54 pin::Pin,
55 str::{self, FromStr},
56 sync::Arc,
57 time::Duration,
58};
59
60pub const DEFAULT_IDLE_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
64
65pub const KADEMLIA_MAX_PROVIDER_KEYS: usize = 10000;
69
70pub const KADEMLIA_PROVIDER_RECORD_TTL: Duration = Duration::from_secs(10 * 3600);
74
75pub const KADEMLIA_PROVIDER_REPUBLISH_INTERVAL: Duration = Duration::from_secs(12600);
79
80#[derive(Clone, PartialEq, Eq, Hash)]
84pub struct ProtocolId(smallvec::SmallVec<[u8; 6]>);
85
86impl<'a> From<&'a str> for ProtocolId {
87 fn from(bytes: &'a str) -> ProtocolId {
88 Self(bytes.as_bytes().into())
89 }
90}
91
92impl AsRef<str> for ProtocolId {
93 fn as_ref(&self) -> &str {
94 str::from_utf8(&self.0[..])
95 .expect("the only way to build a ProtocolId is through a UTF-8 String; qed")
96 }
97}
98
99impl fmt::Debug for ProtocolId {
100 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101 fmt::Debug::fmt(self.as_ref(), f)
102 }
103}
104
105pub fn parse_str_addr(addr_str: &str) -> Result<(PeerId, Multiaddr), ParseErr> {
120 let addr: Multiaddr = addr_str.parse()?;
121 parse_addr(addr)
122}
123
124pub fn parse_addr(mut addr: Multiaddr) -> Result<(PeerId, Multiaddr), ParseErr> {
126 let multihash = match addr.pop() {
127 Some(multiaddr::Protocol::P2p(multihash)) => multihash,
128 _ => return Err(ParseErr::PeerIdMissing),
129 };
130 let peer_id = PeerId::from_multihash(multihash).map_err(|_| ParseErr::InvalidPeerId)?;
131
132 Ok((peer_id, addr))
133}
134
135#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
150#[serde(try_from = "String", into = "String")]
151pub struct MultiaddrWithPeerId {
152 pub multiaddr: Multiaddr,
154 pub peer_id: PeerId,
156}
157
158impl MultiaddrWithPeerId {
159 pub fn concat(&self) -> Multiaddr {
161 let mut addr = self.multiaddr.clone();
162 if matches!(addr.iter().last(), Some(multiaddr::Protocol::P2p(_))) {
164 addr.pop();
165 }
166 addr.with(multiaddr::Protocol::P2p(From::from(self.peer_id)))
167 }
168}
169
170impl fmt::Display for MultiaddrWithPeerId {
171 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
172 fmt::Display::fmt(&self.concat(), f)
173 }
174}
175
176impl FromStr for MultiaddrWithPeerId {
177 type Err = ParseErr;
178
179 fn from_str(s: &str) -> Result<Self, Self::Err> {
180 let (peer_id, multiaddr) = parse_str_addr(s)?;
181 Ok(Self { peer_id, multiaddr })
182 }
183}
184
185impl From<MultiaddrWithPeerId> for String {
186 fn from(ma: MultiaddrWithPeerId) -> String {
187 format!("{}", ma)
188 }
189}
190
191impl TryFrom<String> for MultiaddrWithPeerId {
192 type Error = ParseErr;
193 fn try_from(string: String) -> Result<Self, Self::Error> {
194 string.parse()
195 }
196}
197
198#[derive(Debug)]
200pub enum ParseErr {
201 MultiaddrParse(multiaddr::ParseError),
203 InvalidPeerId,
205 PeerIdMissing,
207}
208
209impl fmt::Display for ParseErr {
210 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
211 match self {
212 Self::MultiaddrParse(err) => write!(f, "{}", err),
213 Self::InvalidPeerId => write!(f, "Peer id at the end of the address is invalid"),
214 Self::PeerIdMissing => write!(f, "Peer id is missing from the address"),
215 }
216 }
217}
218
219impl std::error::Error for ParseErr {
220 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
221 match self {
222 Self::MultiaddrParse(err) => Some(err),
223 Self::InvalidPeerId => None,
224 Self::PeerIdMissing => None,
225 }
226 }
227}
228
229impl From<multiaddr::ParseError> for ParseErr {
230 fn from(err: multiaddr::ParseError) -> ParseErr {
231 Self::MultiaddrParse(err)
232 }
233}
234
235#[derive(Debug, Clone)]
237pub struct NotificationHandshake(Vec<u8>);
238
239impl NotificationHandshake {
240 pub fn new<H: Encode>(handshake: H) -> Self {
242 Self(handshake.encode())
243 }
244
245 pub fn from_bytes(bytes: Vec<u8>) -> Self {
247 Self(bytes)
248 }
249}
250
251impl std::ops::Deref for NotificationHandshake {
252 type Target = Vec<u8>;
253
254 fn deref(&self) -> &Self::Target {
255 &self.0
256 }
257}
258
259#[derive(Clone, Debug)]
261pub enum TransportConfig {
262 Normal {
264 enable_mdns: bool,
267
268 allow_private_ip: bool,
272 },
273
274 MemoryOnly,
277}
278
279#[derive(Clone, Debug, PartialEq, Eq)]
281pub enum NonReservedPeerMode {
282 Accept,
284 Deny,
286}
287
288impl NonReservedPeerMode {
289 pub fn parse(s: &str) -> Option<Self> {
291 match s {
292 "accept" => Some(Self::Accept),
293 "deny" => Some(Self::Deny),
294 _ => None,
295 }
296 }
297
298 pub fn is_reserved_only(&self) -> bool {
300 matches!(self, NonReservedPeerMode::Deny)
301 }
302}
303
304#[derive(Clone, Debug)]
308pub enum NodeKeyConfig {
309 Ed25519(Secret<ed25519::SecretKey>),
311}
312
313impl Default for NodeKeyConfig {
314 fn default() -> NodeKeyConfig {
315 Self::Ed25519(Secret::New)
316 }
317}
318
319pub type Ed25519Secret = Secret<ed25519::SecretKey>;
321
322#[derive(Clone)]
324pub enum Secret<K> {
325 Input(K),
327 File(PathBuf),
333 New,
335}
336
337impl<K> fmt::Debug for Secret<K> {
338 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
339 match self {
340 Self::Input(_) => f.debug_tuple("Secret::Input").finish(),
341 Self::File(path) => f.debug_tuple("Secret::File").field(path).finish(),
342 Self::New => f.debug_tuple("Secret::New").finish(),
343 }
344 }
345}
346
347impl NodeKeyConfig {
348 pub fn into_keypair(self) -> io::Result<ed25519::Keypair> {
359 use NodeKeyConfig::*;
360 match self {
361 Ed25519(Secret::New) => Ok(ed25519::Keypair::generate()),
362
363 Ed25519(Secret::Input(k)) => Ok(ed25519::Keypair::from(k).into()),
364
365 Ed25519(Secret::File(f)) => get_secret(
366 f,
367 |mut b| match String::from_utf8(b.to_vec()).ok().and_then(|s| {
368 if s.len() == 64 {
369 array_bytes::hex2bytes(&s).ok()
370 } else {
371 None
372 }
373 }) {
374 Some(s) => ed25519::SecretKey::try_from_bytes(s),
375 _ => ed25519::SecretKey::try_from_bytes(&mut b),
376 },
377 ed25519::SecretKey::generate,
378 |b| b.as_ref().to_vec(),
379 )
380 .map(ed25519::Keypair::from),
381 }
382 }
383}
384
385fn get_secret<P, F, G, E, W, K>(file: P, parse: F, generate: G, serialize: W) -> io::Result<K>
389where
390 P: AsRef<Path>,
391 F: for<'r> FnOnce(&'r mut [u8]) -> Result<K, E>,
392 G: FnOnce() -> K,
393 E: Error + Send + Sync + 'static,
394 W: Fn(&K) -> Vec<u8>,
395{
396 std::fs::read(&file)
397 .and_then(|mut sk_bytes| {
398 parse(&mut sk_bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
399 })
400 .or_else(|e| {
401 if e.kind() == io::ErrorKind::NotFound {
402 file.as_ref().parent().map_or(Ok(()), fs::create_dir_all)?;
403 let sk = generate();
404 let mut sk_vec = serialize(&sk);
405 write_secret_file(file, &sk_vec)?;
406 sk_vec.zeroize();
407 Ok(sk)
408 } else {
409 Err(e)
410 }
411 })
412}
413
414fn write_secret_file<P>(path: P, sk_bytes: &[u8]) -> io::Result<()>
416where
417 P: AsRef<Path>,
418{
419 let mut file = open_secret_file(&path)?;
420 file.write_all(sk_bytes)
421}
422
423#[cfg(unix)]
425fn open_secret_file<P>(path: P) -> io::Result<fs::File>
426where
427 P: AsRef<Path>,
428{
429 use std::os::unix::fs::OpenOptionsExt;
430 fs::OpenOptions::new().write(true).create_new(true).mode(0o600).open(path)
431}
432
433#[cfg(not(unix))]
435fn open_secret_file<P>(path: P) -> Result<fs::File, io::Error>
436where
437 P: AsRef<Path>,
438{
439 fs::OpenOptions::new().write(true).create_new(true).open(path)
440}
441
442#[derive(Clone, Debug)]
444pub struct SetConfig {
445 pub in_peers: u32,
447
448 pub out_peers: u32,
450
451 pub reserved_nodes: Vec<MultiaddrWithPeerId>,
453
454 pub non_reserved_mode: NonReservedPeerMode,
457}
458
459impl Default for SetConfig {
460 fn default() -> Self {
461 Self {
462 in_peers: 25,
463 out_peers: 75,
464 reserved_nodes: Vec::new(),
465 non_reserved_mode: NonReservedPeerMode::Accept,
466 }
467 }
468}
469
470#[derive(Debug)]
475pub struct NonDefaultSetConfig {
476 protocol_name: ProtocolName,
482
483 fallback_names: Vec<ProtocolName>,
490
491 handshake: Option<NotificationHandshake>,
497
498 max_notification_size: u64,
500
501 set_config: SetConfig,
503
504 protocol_handle_pair: ProtocolHandlePair,
512}
513
514impl NonDefaultSetConfig {
515 pub fn new(
518 protocol_name: ProtocolName,
519 fallback_names: Vec<ProtocolName>,
520 max_notification_size: u64,
521 handshake: Option<NotificationHandshake>,
522 set_config: SetConfig,
523 ) -> (Self, Box<dyn NotificationService>) {
524 let (protocol_handle_pair, notification_service) =
525 notification_service(protocol_name.clone());
526 (
527 Self {
528 protocol_name,
529 max_notification_size,
530 fallback_names,
531 handshake,
532 set_config,
533 protocol_handle_pair,
534 },
535 notification_service,
536 )
537 }
538
539 pub fn protocol_name(&self) -> &ProtocolName {
541 &self.protocol_name
542 }
543
544 pub fn fallback_names(&self) -> impl Iterator<Item = &ProtocolName> {
546 self.fallback_names.iter()
547 }
548
549 pub fn handshake(&self) -> &Option<NotificationHandshake> {
551 &self.handshake
552 }
553
554 pub fn max_notification_size(&self) -> u64 {
556 self.max_notification_size
557 }
558
559 pub fn set_config(&self) -> &SetConfig {
561 &self.set_config
562 }
563
564 pub fn take_protocol_handle(self) -> ProtocolHandlePair {
566 self.protocol_handle_pair
567 }
568
569 pub fn allow_non_reserved(&mut self, in_peers: u32, out_peers: u32) {
571 self.set_config.in_peers = in_peers;
572 self.set_config.out_peers = out_peers;
573 self.set_config.non_reserved_mode = NonReservedPeerMode::Accept;
574 }
575
576 pub fn add_reserved(&mut self, peer: MultiaddrWithPeerId) {
578 self.set_config.reserved_nodes.push(peer);
579 }
580
581 pub fn add_fallback_names(&mut self, fallback_names: Vec<ProtocolName>) {
585 self.fallback_names.extend(fallback_names);
586 }
587}
588
589impl NotificationConfig for NonDefaultSetConfig {
590 fn set_config(&self) -> &SetConfig {
591 &self.set_config
592 }
593
594 fn protocol_name(&self) -> &ProtocolName {
596 &self.protocol_name
597 }
598}
599
600#[derive(Clone, Debug)]
602pub struct NetworkConfiguration {
603 pub net_config_path: Option<PathBuf>,
605
606 pub listen_addresses: Vec<Multiaddr>,
608
609 pub public_addresses: Vec<Multiaddr>,
611
612 pub boot_nodes: Vec<MultiaddrWithPeerId>,
614
615 pub node_key: NodeKeyConfig,
617
618 pub default_peers_set: SetConfig,
620
621 pub default_peers_set_num_full: u32,
626
627 pub client_version: String,
629
630 pub node_name: String,
632
633 pub transport: TransportConfig,
635
636 pub idle_connection_timeout: Duration,
640
641 pub max_parallel_downloads: u32,
643
644 pub max_blocks_per_request: u32,
646
647 pub min_peers_to_start_warp_sync: Option<usize>,
649
650 pub sync_mode: SyncMode,
652
653 pub enable_dht_random_walk: bool,
657
658 pub allow_non_globals_in_dht: bool,
660
661 pub kademlia_disjoint_query_paths: bool,
664
665 pub kademlia_replication_factor: NonZeroUsize,
670
671 pub ipfs_server: bool,
673
674 pub network_backend: NetworkBackendType,
676}
677
678impl NetworkConfiguration {
679 pub fn new<SN: Into<String>, SV: Into<String>>(
681 node_name: SN,
682 client_version: SV,
683 node_key: NodeKeyConfig,
684 net_config_path: Option<PathBuf>,
685 ) -> Self {
686 let default_peers_set = SetConfig::default();
687 Self {
688 net_config_path,
689 listen_addresses: Vec::new(),
690 public_addresses: Vec::new(),
691 boot_nodes: Vec::new(),
692 node_key,
693 default_peers_set_num_full: default_peers_set.in_peers + default_peers_set.out_peers,
694 default_peers_set,
695 client_version: client_version.into(),
696 node_name: node_name.into(),
697 transport: TransportConfig::Normal { enable_mdns: false, allow_private_ip: true },
698 idle_connection_timeout: DEFAULT_IDLE_CONNECTION_TIMEOUT,
699 max_parallel_downloads: 5,
700 max_blocks_per_request: 64,
701 min_peers_to_start_warp_sync: None,
702 sync_mode: SyncMode::Full,
703 enable_dht_random_walk: true,
704 allow_non_globals_in_dht: false,
705 kademlia_disjoint_query_paths: false,
706 kademlia_replication_factor: NonZeroUsize::new(DEFAULT_KADEMLIA_REPLICATION_FACTOR)
707 .expect("value is a constant; constant is non-zero; qed."),
708 ipfs_server: false,
709 network_backend: NetworkBackendType::Litep2p,
710 }
711 }
712
713 pub fn new_local() -> NetworkConfiguration {
716 let mut config =
717 NetworkConfiguration::new("test-node", "test-client", Default::default(), None);
718
719 config.listen_addresses =
720 vec![iter::once(multiaddr::Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)))
721 .chain(iter::once(multiaddr::Protocol::Tcp(0)))
722 .collect()];
723
724 config.allow_non_globals_in_dht = true;
725 config
726 }
727
728 pub fn new_memory() -> NetworkConfiguration {
731 let mut config =
732 NetworkConfiguration::new("test-node", "test-client", Default::default(), None);
733
734 config.listen_addresses =
735 vec![iter::once(multiaddr::Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)))
736 .chain(iter::once(multiaddr::Protocol::Tcp(0)))
737 .collect()];
738
739 config.allow_non_globals_in_dht = true;
740 config
741 }
742}
743
744pub struct Params<Block: BlockT, H: ExHashT, N: NetworkBackend<Block, H>> {
746 pub role: Role,
748
749 pub executor: Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send>>) + Send + Sync>,
751
752 pub network_config: FullNetworkConfiguration<Block, H, N>,
754
755 pub protocol_id: ProtocolId,
757
758 pub genesis_hash: Block::Hash,
760
761 pub fork_id: Option<String>,
764
765 pub metrics_registry: Option<Registry>,
767
768 pub block_announce_config: N::NotificationProtocolConfig,
770
771 pub bitswap_config: Option<N::BitswapConfig>,
773
774 pub notification_metrics: NotificationMetrics,
776}
777
778pub struct FullNetworkConfiguration<B: BlockT + 'static, H: ExHashT, N: NetworkBackend<B, H>> {
780 pub(crate) notification_protocols: Vec<N::NotificationProtocolConfig>,
782
783 pub(crate) request_response_protocols: Vec<N::RequestResponseProtocolConfig>,
785
786 pub network_config: NetworkConfiguration,
788
789 peer_store: Option<N::PeerStore>,
791
792 peer_store_handle: Arc<dyn PeerStoreProvider>,
794
795 pub metrics_registry: Option<Registry>,
797}
798
799impl<B: BlockT + 'static, H: ExHashT, N: NetworkBackend<B, H>> FullNetworkConfiguration<B, H, N> {
800 pub fn new(network_config: &NetworkConfiguration, metrics_registry: Option<Registry>) -> Self {
802 let bootnodes = network_config.boot_nodes.iter().map(|bootnode| bootnode.peer_id).collect();
803 let peer_store = N::peer_store(bootnodes, metrics_registry.clone());
804 let peer_store_handle = peer_store.handle();
805
806 Self {
807 peer_store: Some(peer_store),
808 peer_store_handle,
809 notification_protocols: Vec::new(),
810 request_response_protocols: Vec::new(),
811 network_config: network_config.clone(),
812 metrics_registry,
813 }
814 }
815
816 pub fn add_notification_protocol(&mut self, config: N::NotificationProtocolConfig) {
818 self.notification_protocols.push(config);
819 }
820
821 pub fn notification_protocols(&self) -> &Vec<N::NotificationProtocolConfig> {
823 &self.notification_protocols
824 }
825
826 pub fn add_request_response_protocol(&mut self, config: N::RequestResponseProtocolConfig) {
828 self.request_response_protocols.push(config);
829 }
830
831 pub fn peer_store_handle(&self) -> Arc<dyn PeerStoreProvider> {
833 Arc::clone(&self.peer_store_handle)
834 }
835
836 pub fn take_peer_store(&mut self) -> N::PeerStore {
844 self.peer_store
845 .take()
846 .expect("`PeerStore` can only be taken once when it's started; qed")
847 }
848
849 pub fn sanity_check_addresses(&self) -> Result<(), crate::error::Error> {
851 ensure_addresses_consistent_with_transport(
852 self.network_config.listen_addresses.iter(),
853 &self.network_config.transport,
854 )?;
855 ensure_addresses_consistent_with_transport(
856 self.network_config.boot_nodes.iter().map(|x| &x.multiaddr),
857 &self.network_config.transport,
858 )?;
859 ensure_addresses_consistent_with_transport(
860 self.network_config
861 .default_peers_set
862 .reserved_nodes
863 .iter()
864 .map(|x| &x.multiaddr),
865 &self.network_config.transport,
866 )?;
867
868 for notification_protocol in &self.notification_protocols {
869 ensure_addresses_consistent_with_transport(
870 notification_protocol.set_config().reserved_nodes.iter().map(|x| &x.multiaddr),
871 &self.network_config.transport,
872 )?;
873 }
874 ensure_addresses_consistent_with_transport(
875 self.network_config.public_addresses.iter(),
876 &self.network_config.transport,
877 )?;
878
879 Ok(())
880 }
881
882 pub fn sanity_check_bootnodes(&self) -> Result<(), crate::error::Error> {
884 self.network_config.boot_nodes.iter().try_for_each(|bootnode| {
885 if let Some(other) = self
886 .network_config
887 .boot_nodes
888 .iter()
889 .filter(|o| o.multiaddr == bootnode.multiaddr)
890 .find(|o| o.peer_id != bootnode.peer_id)
891 {
892 Err(crate::error::Error::DuplicateBootnode {
893 address: bootnode.multiaddr.clone().into(),
894 first_id: bootnode.peer_id.into(),
895 second_id: other.peer_id.into(),
896 })
897 } else {
898 Ok(())
899 }
900 })
901 }
902
903 pub fn known_addresses(&self) -> Vec<(PeerId, Multiaddr)> {
905 let mut addresses: Vec<_> = self
906 .network_config
907 .default_peers_set
908 .reserved_nodes
909 .iter()
910 .map(|reserved| (reserved.peer_id, reserved.multiaddr.clone()))
911 .chain(self.notification_protocols.iter().flat_map(|protocol| {
912 protocol
913 .set_config()
914 .reserved_nodes
915 .iter()
916 .map(|reserved| (reserved.peer_id, reserved.multiaddr.clone()))
917 }))
918 .chain(
919 self.network_config
920 .boot_nodes
921 .iter()
922 .map(|bootnode| (bootnode.peer_id, bootnode.multiaddr.clone())),
923 )
924 .collect();
925
926 addresses.sort();
928 addresses.dedup();
929
930 addresses
931 }
932}
933
934#[derive(Debug, Clone, Default, Copy)]
936pub enum NetworkBackendType {
937 #[default]
941 Litep2p,
942
943 Libp2p,
950}
951
952#[cfg(test)]
953mod tests {
954 use super::*;
955 use tempfile::TempDir;
956
957 fn tempdir_with_prefix(prefix: &str) -> TempDir {
958 tempfile::Builder::new().prefix(prefix).tempdir().unwrap()
959 }
960
961 fn secret_bytes(kp: ed25519::Keypair) -> Vec<u8> {
962 kp.secret().to_bytes().into()
963 }
964
965 #[test]
966 fn test_secret_file() {
967 let tmp = tempdir_with_prefix("x");
968 std::fs::remove_dir(tmp.path()).unwrap(); let file = tmp.path().join("x").to_path_buf();
970 let kp1 = NodeKeyConfig::Ed25519(Secret::File(file.clone())).into_keypair().unwrap();
971 let kp2 = NodeKeyConfig::Ed25519(Secret::File(file.clone())).into_keypair().unwrap();
972 assert!(file.is_file() && secret_bytes(kp1) == secret_bytes(kp2))
973 }
974
975 #[test]
976 fn test_secret_input() {
977 let sk = ed25519::SecretKey::generate();
978 let kp1 = NodeKeyConfig::Ed25519(Secret::Input(sk.clone())).into_keypair().unwrap();
979 let kp2 = NodeKeyConfig::Ed25519(Secret::Input(sk)).into_keypair().unwrap();
980 assert!(secret_bytes(kp1) == secret_bytes(kp2));
981 }
982
983 #[test]
984 fn test_secret_new() {
985 let kp1 = NodeKeyConfig::Ed25519(Secret::New).into_keypair().unwrap();
986 let kp2 = NodeKeyConfig::Ed25519(Secret::New).into_keypair().unwrap();
987 assert!(secret_bytes(kp1) != secret_bytes(kp2));
988 }
989}