testnet starting
This commit is contained in:
		
							parent
							
								
									216b08be57
								
							
						
					
					
						commit
						1804c8e00c
					
				
							
								
								
									
										95
									
								
								rewrite/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										95
									
								
								rewrite/Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -237,6 +237,21 @@ dependencies = [ | |||||||
|  "alloc-no-stdlib", |  "alloc-no-stdlib", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "android-tzdata" | ||||||
|  | version = "0.1.1" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" | ||||||
|  | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "android_system_properties" | ||||||
|  | version = "0.1.5" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" | ||||||
|  | dependencies = [ | ||||||
|  |  "libc", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "anyhow" | name = "anyhow" | ||||||
| version = "1.0.89" | version = "1.0.89" | ||||||
| @ -723,7 +738,12 @@ version = "0.4.38" | |||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" | checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  |  "android-tzdata", | ||||||
|  |  "iana-time-zone", | ||||||
|  |  "js-sys", | ||||||
|  "num-traits", |  "num-traits", | ||||||
|  |  "wasm-bindgen", | ||||||
|  |  "windows-targets", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| @ -769,6 +789,12 @@ dependencies = [ | |||||||
|  "version_check", |  "version_check", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "core-foundation-sys" | ||||||
|  | version = "0.8.7" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "cpufeatures" | name = "cpufeatures" | ||||||
| version = "0.2.14" | version = "0.2.14" | ||||||
| @ -1169,6 +1195,25 @@ dependencies = [ | |||||||
|  "tracing", |  "tracing", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "hacker-challenge" | ||||||
|  | version = "0.1.0" | ||||||
|  | dependencies = [ | ||||||
|  |  "actix-web", | ||||||
|  |  "async-stream", | ||||||
|  |  "chrono", | ||||||
|  |  "dashmap", | ||||||
|  |  "prost", | ||||||
|  |  "prost-types", | ||||||
|  |  "rand 0.8.5", | ||||||
|  |  "serde", | ||||||
|  |  "solana-sdk", | ||||||
|  |  "tokio", | ||||||
|  |  "tokio-stream", | ||||||
|  |  "tonic", | ||||||
|  |  "tonic-build", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "hashbrown" | name = "hashbrown" | ||||||
| version = "0.12.3" | version = "0.12.3" | ||||||
| @ -1343,6 +1388,29 @@ dependencies = [ | |||||||
|  "tracing", |  "tracing", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "iana-time-zone" | ||||||
|  | version = "0.1.60" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" | ||||||
|  | dependencies = [ | ||||||
|  |  "android_system_properties", | ||||||
|  |  "core-foundation-sys", | ||||||
|  |  "iana-time-zone-haiku", | ||||||
|  |  "js-sys", | ||||||
|  |  "wasm-bindgen", | ||||||
|  |  "windows-core", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "iana-time-zone-haiku" | ||||||
|  | version = "0.1.2" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" | ||||||
|  | dependencies = [ | ||||||
|  |  "cc", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "ident_case" | name = "ident_case" | ||||||
| version = "1.0.1" | version = "1.0.1" | ||||||
| @ -2045,24 +2113,6 @@ version = "0.8.4" | |||||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
| checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" | checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" | ||||||
| 
 | 
 | ||||||
| [[package]] |  | ||||||
| name = "rewrite" |  | ||||||
| version = "0.1.0" |  | ||||||
| dependencies = [ |  | ||||||
|  "actix-web", |  | ||||||
|  "async-stream", |  | ||||||
|  "dashmap", |  | ||||||
|  "prost", |  | ||||||
|  "prost-types", |  | ||||||
|  "rand 0.8.5", |  | ||||||
|  "serde", |  | ||||||
|  "solana-sdk", |  | ||||||
|  "tokio", |  | ||||||
|  "tokio-stream", |  | ||||||
|  "tonic", |  | ||||||
|  "tonic-build", |  | ||||||
| ] |  | ||||||
| 
 |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "rustc-demangle" | name = "rustc-demangle" | ||||||
| version = "0.1.24" | version = "0.1.24" | ||||||
| @ -2865,6 +2915,15 @@ dependencies = [ | |||||||
|  "wasm-bindgen", |  "wasm-bindgen", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
|  | [[package]] | ||||||
|  | name = "windows-core" | ||||||
|  | version = "0.52.0" | ||||||
|  | source = "registry+https://github.com/rust-lang/crates.io-index" | ||||||
|  | checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" | ||||||
|  | dependencies = [ | ||||||
|  |  "windows-targets", | ||||||
|  | ] | ||||||
|  | 
 | ||||||
| [[package]] | [[package]] | ||||||
| name = "windows-sys" | name = "windows-sys" | ||||||
| version = "0.52.0" | version = "0.52.0" | ||||||
|  | |||||||
| @ -1,11 +1,12 @@ | |||||||
| [package] | [package] | ||||||
| name = "rewrite" | name = "hacker-challenge" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
| edition = "2021" | edition = "2021" | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| actix-web = "4.9.0" | actix-web = "4.9.0" | ||||||
| async-stream = "0.3.5" | async-stream = "0.3.5" | ||||||
|  | chrono = "0.4.38" | ||||||
| dashmap = "6.1.0" | dashmap = "6.1.0" | ||||||
| prost = "0.13.2" | prost = "0.13.2" | ||||||
| prost-types = "0.13.2" | prost-types = "0.13.2" | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								rewrite/scripts/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										4
									
								
								rewrite/scripts/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | FROM alpine:edge | ||||||
|  | COPY start.sh /start.sh | ||||||
|  | COPY hacker-challenge /hacker-challenge | ||||||
|  | ENTRYPOINT ["/start.sh"] | ||||||
							
								
								
									
										12
									
								
								rewrite/scripts/start.sh
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										12
									
								
								rewrite/scripts/start.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | #!/bin/sh | ||||||
|  | 
 | ||||||
|  | # This script start the hacker challenge from within the docker container. | ||||||
|  | # It's only purpose is to help bootstrap a test network. | ||||||
|  | 
 | ||||||
|  | if [ -z "${INIT_NODES}" ]; then | ||||||
|  |   echo "The INIT_NODES environment variable is not set." | ||||||
|  | else | ||||||
|  |   echo $INIT_NODES | tr ' ' '\n' > /detee_challenge_nodes | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | /hacker-challenge | ||||||
							
								
								
									
										24
									
								
								rewrite/scripts/testnet.sh
									
									
									
									
									
										Executable file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										24
									
								
								rewrite/scripts/testnet.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | cd "$(dirname "$0")"/.. | ||||||
|  | set -e | ||||||
|  | cargo build --release --target x86_64-unknown-linux-musl | ||||||
|  | rm -rf build | ||||||
|  | mkdir -p build | ||||||
|  | cp ./target/x86_64-unknown-linux-musl/release/hacker-challenge build/ | ||||||
|  | cp scripts/start.sh build/ | ||||||
|  | cp scripts/Dockerfile build/ | ||||||
|  | cd build | ||||||
|  | 
 | ||||||
|  | docker build -t hacker-challenge:latest . | ||||||
|  | 
 | ||||||
|  | docker ps -a | grep 'hacker-challenge' | awk '{ print $NF }' | xargs docker rm -f || true | ||||||
|  | 
 | ||||||
|  | docker run -d --name "hacker-challenge_0" \ | ||||||
|  |   hacker-challenge:latest | ||||||
|  | 
 | ||||||
|  | for i in {1..10} | ||||||
|  | do | ||||||
|  |   docker run -d --name "hacker-challenge_$i" \ | ||||||
|  |     --env INIT_NODES="172.17.0.2 172.17.0.3 172.17.0.4" \ | ||||||
|  |     hacker-challenge:latest | ||||||
|  | done | ||||||
| @ -5,6 +5,7 @@ use dashmap::DashSet; | |||||||
| use solana_sdk::signature::keypair::Keypair; | use solana_sdk::signature::keypair::Keypair; | ||||||
| use std::time::SystemTime; | use std::time::SystemTime; | ||||||
| use std::time::{Duration, UNIX_EPOCH}; | use std::time::{Duration, UNIX_EPOCH}; | ||||||
|  | use chrono::{DateTime, Utc}; | ||||||
| 
 | 
 | ||||||
| type IP = String; | type IP = String; | ||||||
| pub const LOCALHOST: &str = "localhost"; | pub const LOCALHOST: &str = "localhost"; | ||||||
| @ -93,7 +94,9 @@ impl Store { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn increase_mint_requests(&self) { |     pub fn increase_mint_requests(&self) { | ||||||
|  |         println!("increasing localhost"); | ||||||
|         if let Some(mut localhost_info) = self.nodes.get_mut(LOCALHOST) { |         if let Some(mut localhost_info) = self.nodes.get_mut(LOCALHOST) { | ||||||
|  |             println!("increasing localhost from {}", localhost_info.mint_requests); | ||||||
|             localhost_info.mint_requests += 1; |             localhost_info.mint_requests += 1; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -155,15 +158,21 @@ impl Store { | |||||||
|     pub fn get_http_node_list(&self) -> Vec<crate::http_server::NodesResp> { |     pub fn get_http_node_list(&self) -> Vec<crate::http_server::NodesResp> { | ||||||
|         self.nodes |         self.nodes | ||||||
|             .iter() |             .iter() | ||||||
|             .map(|node| crate::http_server::NodesResp { |             .map(|node| { | ||||||
|  |                 let joined_at: DateTime<Utc> = node.value().started_at.into(); | ||||||
|  |                 let last_keepalive: DateTime<Utc> = node.value().started_at.into(); | ||||||
|  |                 let joined_at = joined_at.format("%Y-%m-%d %H:%M:%S").to_string(); | ||||||
|  |                 let last_keepalive = last_keepalive.format("%Y-%m-%d %H:%M:%S").to_string(); | ||||||
|  |                 crate::http_server::NodesResp { | ||||||
|                 ip: node.key().to_string(), |                 ip: node.key().to_string(), | ||||||
|                 joined_at: node.value().started_at, |                 joined_at, | ||||||
|                 last_keepalive: node.value().keepalive, |                 last_keepalive, | ||||||
|                 mints: node.value().mints, |                 mints: node.value().mints, | ||||||
|                 ratls_connections: node.value().ratls_conns, |                 ratls_connections: node.value().ratls_conns, | ||||||
|                 ratls_attacks: node.value().ratls_attacks, |                 ratls_attacks: node.value().ratls_attacks, | ||||||
|                 public: node.value().public, |                 public: node.value().public, | ||||||
|                 mint_requests: node.value().mint_requests, |                 mint_requests: node.value().mint_requests, | ||||||
|  |             } | ||||||
|             }) |             }) | ||||||
|             .collect() |             .collect() | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -10,10 +10,9 @@ use actix_web::{ | |||||||
|     HttpServer, |     HttpServer, | ||||||
|     Responder, |     Responder, | ||||||
| }; | }; | ||||||
|  | use chrono::{DateTime, Utc}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
| use std::time::SystemTime; |  | ||||||
| // use std::{fmt, sync::Arc};
 |  | ||||||
| 
 | 
 | ||||||
| const HOMEPAGE: &str = r#"Welcome, beloved hacker!
 | const HOMEPAGE: &str = r#"Welcome, beloved hacker!
 | ||||||
| 
 | 
 | ||||||
| @ -45,8 +44,8 @@ async fn homepage() -> impl Responder { | |||||||
| #[derive(Serialize)] | #[derive(Serialize)] | ||||||
| pub struct NodesResp { | pub struct NodesResp { | ||||||
|     pub ip: String, |     pub ip: String, | ||||||
|     pub joined_at: SystemTime, |     pub joined_at: String, | ||||||
|     pub last_keepalive: SystemTime, |     pub last_keepalive: String, | ||||||
|     pub mint_requests: u64, |     pub mint_requests: u64, | ||||||
|     pub ratls_attacks: u64, |     pub ratls_attacks: u64, | ||||||
|     pub ratls_connections: u64, |     pub ratls_connections: u64, | ||||||
| @ -66,6 +65,7 @@ struct MintReq { | |||||||
| 
 | 
 | ||||||
| #[post("/mint")] | #[post("/mint")] | ||||||
| async fn mint(ds: web::Data<Arc<Store>>, _: web::Json<MintReq>) -> impl Responder { | async fn mint(ds: web::Data<Arc<Store>>, _: web::Json<MintReq>) -> impl Responder { | ||||||
|  |     println!("wat"); | ||||||
|     ds.increase_mint_requests(); |     ds.increase_mint_requests(); | ||||||
|     HttpResponse::Ok().json({}) |     HttpResponse::Ok().json({}) | ||||||
| } | } | ||||||
| @ -84,4 +84,3 @@ pub async fn init(ds: Arc<Store>) { | |||||||
|     .await |     .await | ||||||
|     .unwrap(); |     .unwrap(); | ||||||
| } | } | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -66,13 +66,15 @@ async fn main() { | |||||||
|     long_term_tasks.spawn(http_server::init(ds.clone())); |     long_term_tasks.spawn(http_server::init(ds.clone())); | ||||||
|     long_term_tasks.spawn(grpc::server::MyServer::init(ds.clone(), tx.clone()).start()); |     long_term_tasks.spawn(grpc::server::MyServer::init(ds.clone(), tx.clone()).start()); | ||||||
| 
 | 
 | ||||||
|     let input = File::open(INIT_NODES).unwrap(); |     if let Ok(input) = File::open(INIT_NODES) { | ||||||
|         let buffered = BufReader::new(input); |         let buffered = BufReader::new(input); | ||||||
|         for line in buffered.lines() { |         for line in buffered.lines() { | ||||||
|             init_tasks.spawn( |             init_tasks.spawn( | ||||||
|             grpc::client::ConnManager::init(ds.clone(), tx.clone()).start_with_node(line.unwrap()), |                 grpc::client::ConnManager::init(ds.clone(), tx.clone()) | ||||||
|  |                     .start_with_node(line.unwrap()), | ||||||
|             ); |             ); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     let mut connection_count = 0; |     let mut connection_count = 0; | ||||||
|     while init_tasks.join_next().await.is_some() { |     while init_tasks.join_next().await.is_some() { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user