|
| 1 | +use std::{iter, str::FromStr, time::Duration}; |
| 2 | + |
| 3 | +use node::{account::AccountSecretKey, BlockProducerConfig}; |
| 4 | + |
| 5 | +use crate::{ |
| 6 | + node::{RustNodeBlockProducerTestingConfig, RustNodeTestingConfig}, |
| 7 | + scenario::ListenerNode, |
| 8 | + scenarios::ClusterRunner, |
| 9 | +}; |
| 10 | + |
| 11 | +/// Create and Sync up 50 nodes, one amoung them is block producer. |
| 12 | +/// |
| 13 | +/// 1. Create the nodes. |
| 14 | +/// 2. Connect them to each other. |
| 15 | +/// 3. Wait kademlia bootstrap is done, observe the connection graph. |
| 16 | +/// 4. Wait pubsub mesh construction is done, observe the mesh. |
| 17 | +/// 5. Wait block is produced and observe the propagation. |
| 18 | +#[derive(documented::Documented, Default, Clone, Copy)] |
| 19 | +pub struct MultiNodePubsubPropagateBlock; |
| 20 | + |
| 21 | +impl MultiNodePubsubPropagateBlock { |
| 22 | + const WORKERS: usize = 4; |
| 23 | + |
| 24 | + pub async fn run(self, mut runner: ClusterRunner<'_>) { |
| 25 | + // let seed_node = ListenerNode::Custom( |
| 26 | + // "/ip4/34.135.63.47/tcp/10001/p2p/12D3KooWLjs54xHzVmMmGYb7W5RVibqbwD1co7M2ZMfPgPm7iAag" |
| 27 | + // .parse() |
| 28 | + // .unwrap(), |
| 29 | + // ); |
| 30 | + |
| 31 | + let seed_config = RustNodeTestingConfig::devnet_default() |
| 32 | + .max_peers(100) |
| 33 | + .ask_initial_peers_interval(Duration::from_secs(60 * 60)); |
| 34 | + |
| 35 | + let seed_node = ListenerNode::Rust(runner.add_rust_node(seed_config)); |
| 36 | + |
| 37 | + // for account B62qrztYfPinaKqpXaYGY6QJ3SSW2NNKs7SajBLF1iFNXW9BoALN2Aq |
| 38 | + let sec_key = |
| 39 | + AccountSecretKey::from_str("EKEEpMELfQkMbJDt2fB4cFXKwSf1x4t7YD4twREy5yuJ84HBZtF9") |
| 40 | + .unwrap(); |
| 41 | + |
| 42 | + let producer_node = runner.add_rust_node(RustNodeTestingConfig { |
| 43 | + initial_time: redux::Timestamp::ZERO, |
| 44 | + genesis: node::config::DEVNET_CONFIG.clone(), |
| 45 | + max_peers: 10, |
| 46 | + ask_initial_peers_interval: Duration::from_secs(60 * 60), |
| 47 | + initial_peers: vec![seed_node.clone()], |
| 48 | + peer_id: Default::default(), |
| 49 | + block_producer: Some(RustNodeBlockProducerTestingConfig { |
| 50 | + config: BlockProducerConfig { |
| 51 | + pub_key: sec_key.public_key().into(), |
| 52 | + custom_coinbase_receiver: None, |
| 53 | + proposed_protocol_version: None, |
| 54 | + }, |
| 55 | + sec_key, |
| 56 | + }), |
| 57 | + snark_worker: None, |
| 58 | + timeouts: Default::default(), |
| 59 | + libp2p_port: None, |
| 60 | + recorder: Default::default(), |
| 61 | + }); |
| 62 | + |
| 63 | + tokio::time::sleep(Duration::from_secs(2)).await; |
| 64 | + |
| 65 | + eprintln!("Producer node connected"); |
| 66 | + |
| 67 | + let worker_config = RustNodeTestingConfig::devnet_default() |
| 68 | + .initial_peers(vec![seed_node]) |
| 69 | + .max_peers(10) |
| 70 | + .ask_initial_peers_interval(Duration::from_secs(60 * 60)); |
| 71 | + let workers = iter::repeat(worker_config) |
| 72 | + .take(Self::WORKERS) |
| 73 | + .map(|config| runner.add_rust_node(config)) |
| 74 | + .collect::<Vec<_>>(); |
| 75 | + |
| 76 | + runner |
| 77 | + .run_until_nodes_synced(Duration::from_secs(10 * 60), &workers) |
| 78 | + .await |
| 79 | + .unwrap(); |
| 80 | + |
| 81 | + let _ = producer_node; |
| 82 | + // TODO: |
| 83 | + } |
| 84 | +} |
0 commit comments