testnet upgrade

Signed-off-by: Valentyn Faychuk <valy@detee.ltd>
This commit is contained in:
Valentyn Faychuk 2024-12-22 20:19:32 +02:00
parent 780c1e54a3
commit 5da08f59c3
Signed by: valy
GPG Key ID: F1AB995E20FEADC5
4 changed files with 49 additions and 20 deletions

@ -42,3 +42,6 @@ tonic-build = "0.12"
[patch.crates-io.curve25519-dalek]
git = "https://github.com/anza-xyz/curve25519-dalek.git"
rev = "b500cdc2a920cd5bff9e2dd974d7b97349d61464"
[features]
test = []

@ -34,42 +34,61 @@ function build_mint_sol_tool() {
source "${script_dir}/build-container.sh"
build_mint_sol_tool
# Cleanup old containers and run the network root
docker ps -a | grep 'hacker-challenge' | awk '{ print $NF }' | xargs docker rm -f || true
# Cleanup old containers and the network
echo "Creating the network and the root node"
docker ps -a | grep 'dthc' | awk '{ print $NF }' | xargs docker rm -f || true
docker network inspect dthc > /dev/null 2>&1 \
|| docker network create --subnet=172.18.0.0/16 dthc \
|| true
echo "Waiting for the network root to start"
docker run --device /dev/sgx/enclave \
function run_node() {
custom_flags=$1
docker run --network dthc -d "${custom_flags}" \
--device /dev/sgx/provision \
--name "hacker-challenge" \
-d detee/hacker-challenge:latest
--device /dev/sgx/enclave \
detee/hacker-challenge:latest
}
root_ip="172.18.0.1"
echo "Waiting for the root node to start"
run_node "--name dthc-root --ip ${root_ip}"
while true; do
echo -n "." && sleep 1
docker logs hacker-challenge | grep -q "SOL" && echo && break
docker logs dthc-root | grep -q "SOL" && echo && break
done
echo "Sending SOL to the root and waiting for the mint"
address=$(docker logs hacker-challenge | grep 'SOL' | awk '{ print $NF }')
address=$(docker logs dthc-root | grep 'SOL' | awk '{ print $NF }')
"${script_dir}"/mint_sol "${address}"
while true; do
echo -n "." && sleep 1
docker logs hacker-challenge | grep -q "Mint created" && echo && break
docker logs dthc-root | grep -q "Mint created" && echo && break
done
echo "Creating the cluster"
for p in {31311..31320}; do
docker run --device /dev/sgx/enclave \
--device /dev/sgx/provision \
--env INIT_NODES="172.17.0.2 172.17.0.3 172.17.0.4" \
-v "/tmp/hacker-challenge${p}:/challenge/main" \
--name "hacker-challenge${p}" -p "${p}:31372" \
-d detee/hacker-challenge:latest
for n in {2..20}; do
#init_nodes=$(docker inspect dthc-root --format '{{ .NetworkSettings.Networks.dthc.IPAddress }}')
node_ip="172.18.0.${n}"
node_port=$((31300 + n))
node_volume="/tmp/dthc${node_port}"
run_node "--env INIT_NODES='${root_ip}' \
--env NODE_IP='${node_ip}' \
--name dthc-${n} --ip ${node_ip} \
-v ${node_volume}:/challenge/main \
-p ${node_port}:31372"
done
sleep 15 # Wait for the cluster to start
echo "Running the test mint"
for p in {31311..31320}; do
curl -X POST "127.0.0.1:${p}/mint" \
for n in {2..20}; do
node_port=$((31300 + n))
curl -X POST "127.0.0.1:${node_port}/mint" \
--json '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' \
--connect-timeout 5 2> /dev/null
echo ""
done
# curl <ip>/metrics
# curl -X POST <ip>/mint -d '{"wallet": "EZT16iP1SQVUFf1AJN6oiE5BZPnyBUqaKDkZ4oZRsvhR"}' -H 'Content-Type: application/json'

@ -26,7 +26,7 @@ pub struct NodeInfo {
impl NodeInfo {
pub fn is_newer_than(&self, older_self: &Self) -> bool {
self.keepalive >= older_self.keepalive
self.keepalive > older_self.keepalive
}
pub fn to_json(&self) -> String {

@ -26,6 +26,13 @@ const INIT_NODES_FILE: &str = "/host/detee_challenge_nodes";
const KEYS_FILE: &str = "/host/main/TRY_TO_HACK_THIS";
const MAX_CONNECTIONS: usize = 3;
#[cfg(feature = "test")]
async fn resolve_my_ip() -> Result<String, Error> {
let ip = std::env::var("NODE_IP").unwrap_or_else(|_| "127.0.0.1".to_string());
Ok(ip)
}
#[cfg(not(feature = "test"))]
async fn resolve_my_ip() -> Result<String, Error> {
let err = "Can't resolve my external IP, try again";
let ip = public_ip::addr_v4().await.ok_or(Error::new(ErrorKind::Other, err))?;