added scripts to start a test network

This commit is contained in:
ghe0 2024-08-19 22:53:32 +03:00
parent 0a711b7917
commit 5da4ec3785
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
6 changed files with 38 additions and 1 deletions

1
.gitignore vendored

@ -1,2 +1,3 @@
/target
build
detee_challenge_nodes

4
scripts/Dockerfile Normal file

@ -0,0 +1,4 @@
FROM alpine:edge
COPY start.sh /start.sh
COPY hacker-challenge /hacker-challenge
ENTRYPOINT ["/start.sh"]

8
scripts/start.sh Executable file

@ -0,0 +1,8 @@
#!/bin/sh
# This script start the hacker challenge from within the docker container.
# It's only purpose is to help bootstrap a test network.
echo $INIT_NODES > /detee_challenge_nodes
/hacker-challenge

21
scripts/testnet.sh Executable file

@ -0,0 +1,21 @@
#!/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
for i in {0..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

@ -250,6 +250,9 @@ impl Store {
use rand::RngCore;
let nodes = self.nodes.lock().await;
let len = nodes.len();
if len == 0 {
return Vec::new();
}
let skip = OsRng.next_u64().try_into().unwrap_or(0) % len;
let mut iter = nodes.iter().cycle().skip(skip);
let mut random_nodes = vec![];

@ -27,7 +27,7 @@ impl ConnManager {
}
async fn connect(self, node_ip: String) {
let mut client = UpdateClient::connect(format!("http://{node_ip}:50051"))
let mut client = UpdateClient::connect(format!("{node_ip}:31373"))
.await
.unwrap();