testnet starting

This commit is contained in:
ghe0 2024-09-19 04:54:21 +03:00
parent 216b08be57
commit 1804c8e00c
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
8 changed files with 143 additions and 33 deletions

95
rewrite/Cargo.lock generated

@ -237,6 +237,21 @@ dependencies = [
"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]]
name = "anyhow"
version = "1.0.89"
@ -723,7 +738,12 @@ version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets",
]
[[package]]
@ -769,6 +789,12 @@ dependencies = [
"version_check",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.14"
@ -1169,6 +1195,25 @@ dependencies = [
"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]]
name = "hashbrown"
version = "0.12.3"
@ -1343,6 +1388,29 @@ dependencies = [
"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]]
name = "ident_case"
version = "1.0.1"
@ -2045,24 +2113,6 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "rustc-demangle"
version = "0.1.24"
@ -2865,6 +2915,15 @@ dependencies = [
"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]]
name = "windows-sys"
version = "0.52.0"

@ -1,11 +1,12 @@
[package]
name = "rewrite"
name = "hacker-challenge"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4.9.0"
async-stream = "0.3.5"
chrono = "0.4.38"
dashmap = "6.1.0"
prost = "0.13.2"
prost-types = "0.13.2"

@ -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

@ -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

@ -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 std::time::SystemTime;
use std::time::{Duration, UNIX_EPOCH};
use chrono::{DateTime, Utc};
type IP = String;
pub const LOCALHOST: &str = "localhost";
@ -93,7 +94,9 @@ impl Store {
}
pub fn increase_mint_requests(&self) {
println!("increasing 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;
}
}
@ -155,15 +158,21 @@ impl Store {
pub fn get_http_node_list(&self) -> Vec<crate::http_server::NodesResp> {
self.nodes
.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(),
joined_at: node.value().started_at,
last_keepalive: node.value().keepalive,
joined_at,
last_keepalive,
mints: node.value().mints,
ratls_connections: node.value().ratls_conns,
ratls_attacks: node.value().ratls_attacks,
public: node.value().public,
mint_requests: node.value().mint_requests,
}
})
.collect()
}

@ -10,10 +10,9 @@ use actix_web::{
HttpServer,
Responder,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::SystemTime;
// use std::{fmt, sync::Arc};
const HOMEPAGE: &str = r#"Welcome, beloved hacker!
@ -45,8 +44,8 @@ async fn homepage() -> impl Responder {
#[derive(Serialize)]
pub struct NodesResp {
pub ip: String,
pub joined_at: SystemTime,
pub last_keepalive: SystemTime,
pub joined_at: String,
pub last_keepalive: String,
pub mint_requests: u64,
pub ratls_attacks: u64,
pub ratls_connections: u64,
@ -66,6 +65,7 @@ struct MintReq {
#[post("/mint")]
async fn mint(ds: web::Data<Arc<Store>>, _: web::Json<MintReq>) -> impl Responder {
println!("wat");
ds.increase_mint_requests();
HttpResponse::Ok().json({})
}
@ -84,4 +84,3 @@ pub async fn init(ds: Arc<Store>) {
.await
.unwrap();
}

@ -66,12 +66,14 @@ async fn main() {
long_term_tasks.spawn(http_server::init(ds.clone()));
long_term_tasks.spawn(grpc::server::MyServer::init(ds.clone(), tx.clone()).start());
let input = File::open(INIT_NODES).unwrap();
let buffered = BufReader::new(input);
for line in buffered.lines() {
init_tasks.spawn(
grpc::client::ConnManager::init(ds.clone(), tx.clone()).start_with_node(line.unwrap()),
);
if let Ok(input) = File::open(INIT_NODES) {
let buffered = BufReader::new(input);
for line in buffered.lines() {
init_tasks.spawn(
grpc::client::ConnManager::init(ds.clone(), tx.clone())
.start_with_node(line.unwrap()),
);
}
}
let mut connection_count = 0;