diff --git a/Dockerfile b/Dockerfile index 010ef386df3961b1d641a0efc51369e42f908054..8eaadee5f0193f8da8902cf50022ebd97148febc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ WORKDIR /app COPY . /app RUN cargo build --release -FROM gcr.io/distroless/cc -COPY --from=build-env /app/target/release/testnet-injector / -CMD ["./testnet-injector"] \ No newline at end of file +FROM fedora:36 +COPY --from=build-env /app/target/release/testnet-injector /target/release/ +COPY --from=build-env /app/scripts /scripts/ +RUN chmod +x /scripts/*.sh diff --git a/scripts/run_simulation_2_nodes.sh b/scripts/run_simulation_2_nodes.sh new file mode 100755 index 0000000000000000000000000000000000000000..1ddcf35d56d070f9b02dcc57f62c0943610c13ec --- /dev/null +++ b/scripts/run_simulation_2_nodes.sh @@ -0,0 +1,36 @@ +#!/bin/sh +export MINER_SIGNING_KEY=4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318; +export MNEMONIC='before exclude interest push zone jealous boat ice chimney juice young side diagram silent pipe'; + +# MINER_SIGNING_KEY & MNEMONIC env vars are set on workstation. +# 30 mins +#TOTAL_SIMULATION_TIME=1800; +# 12 sec + +# export RPC_URL=http://ecomobicoin-1.cri.local.isima.fr:8545; +# export CHAIN_ID=6363; +export RPC_URL=http://127.0.0.1:8545; +export CHAIN_ID=636363; + + +# ./target/release/testnet-injector simulate-bx-from-csv ../movement-data/public-transport/MF_user_mobility_june-to-august-2023_mulhouse_dataset/anonymized_june-to-august-2023_mulhouse_dataset.csv $TOTAL_SIMULATION_TIME & +# Send BX +./target/release/testnet-injector simulate-bx-from-csv ./data/anonymized_june-to-november-2023_france_dataset.csv $TOTAL_SIMULATION_TIME & + +echo "TOTAL_SIMULATION_TIME = $TOTAL_SIMULATION_TIME and block time = $BLOCK_TIME" +# Mine +for ((i=1; i<=100; i++)) +do + echo "MINE $i/100"; + if ((i % 2 == 0)); then + export RPC_URL=$RPC_URL_MINER_1; ./target/release/testnet-injector mine + else + export RPC_URL=$RPC_URL_MINER_2; ./target/release/testnet-injector mine + fi + + if [ $i -ne 100 ]; then + sleep $BLOCK_TIME + fi +done + + diff --git a/scripts/t0-1mine-2sync.sh b/scripts/t0-1mine-2sync.sh index 3dd826e1e6fc7b7ece167c431b12c1a341865073..624534078178683252439d1cf0d262065bc3c01d 100755 --- a/scripts/t0-1mine-2sync.sh +++ b/scripts/t0-1mine-2sync.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh export MINER_SIGNING_KEY=4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318; # MINER_SIGNING_KEY & MNEMONIC env vars are set on workstation. @@ -11,12 +11,12 @@ export RPC_URL=http://127.0.0.1:8545; export CHAIN_ID=636363; # Mine on eco1 with `--max-block 0` -# +# # rm -rf /home/angraign/.local/share/truite/chaindata/ # ./truite --chain-spec-file clermont-bootnode.ron --no-dns-discovery --cidr 192.168.0.0/16 --rpc-listen-address 0.0.0.0:8545 --max-block 0 # export RPC_URL=http://ecomobicoin-1.cri.local.isima.fr:8545; export CHAIN_ID=6363; ./target/release/testnet-injector mine # ./truite --chain-spec-file clermont-bootnode.ron --no-dns-discovery --cidr 192.168.0.0/16 --rpc-listen-address 0.0.0.0:8545 -# +# # Mine for ((i=1; i<=100; i++)) diff --git a/scripts/t1-1mine-with-simulation-2sync.sh b/scripts/t1-1mine-with-simulation-2sync.sh index c8d6321c68e5c4fb1ca9672419db84bbe2e9d1c8..4160c476f3c1894568ca87bdbbade9e19cb8183f 100755 --- a/scripts/t1-1mine-with-simulation-2sync.sh +++ b/scripts/t1-1mine-with-simulation-2sync.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh export MINER_SIGNING_KEY=4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318; export MNEMONIC='before exclude interest push zone jealous boat ice chimney juice young side diagram silent pipe'; @@ -14,12 +14,12 @@ export RPC_URL=http://127.0.0.1:8545; export CHAIN_ID=636363; # Mine on eco1 with `--max-block 0` -# +# # rm -rf /home/angraign/.local/share/truite/chaindata/ # ./truite --chain-spec-file clermont-bootnode.ron --no-dns-discovery --cidr 192.168.0.0/16 --rpc-listen-address 0.0.0.0:8545 --max-block 0 # export RPC_URL=http://ecomobicoin-1.cri.local.isima.fr:8545; export CHAIN_ID=6363; ./target/release/testnet-injector mine # ./truite --chain-spec-file clermont-bootnode.ron --no-dns-discovery --cidr 192.168.0.0/16 --rpc-listen-address 0.0.0.0:8545 -# +# # ./target/release/testnet-injector simulate-bx-from-csv ../movement-data/public-transport/MF_user_mobility_june-to-august-2023_mulhouse_dataset/anonymized_june-to-august-2023_mulhouse_dataset.csv $TOTAL_SIMULATION_TIME & ./target/release/testnet-injector simulate-bx-from-csv ./data/dataset-extract.csv $TOTAL_SIMULATION_TIME & diff --git a/scripts/t2-n-miners-m-sync.sh b/scripts/t2-n-miners-m-sync.sh index f2130941420dfff7eaeb0d90a20f3dc593148142..aef83177d085d346527a52af0cd29f9478f3a4ab 100755 --- a/scripts/t2-n-miners-m-sync.sh +++ b/scripts/t2-n-miners-m-sync.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh export MINER_SIGNING_KEY=4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318; export MNEMONIC='before exclude interest push zone jealous boat ice chimney juice young side diagram silent pipe'; @@ -29,7 +29,7 @@ do else export RPC_URL=$RPC_URL_MINER_2; ./target/release/testnet-injector mine fi - + if [ $i -ne 100 ]; then sleep $BLOCK_TIME fi diff --git a/scripts/t2.sh b/scripts/t2.sh index e62ef7ab487f4251083a4b521f23cbe2b452819d..d70512f563027bf7b54185d38b5554a2b3534ac2 100755 --- a/scripts/t2.sh +++ b/scripts/t2.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh export MINER_SIGNING_KEY=4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318; export MNEMONIC='before exclude interest push zone jealous boat ice chimney juice young side diagram silent pipe'; diff --git a/src/main.rs b/src/main.rs index ccfe39dad5862cce133bd5b815a0317a9e273526..a96567058cc0bf71f6bf57cba51508e21df19642 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,14 +270,17 @@ async fn main() -> Result<(), anyhow::Error> { .unwrap() .as_secs(); let simulation_behavior = mobility_records[i].clone(); - let relative_start_duration = mobility_records_times[i]; + let relative_start_duration = if i == 0 { + Duration::from_secs(0) + } + else { mobility_records_times[i] - mobility_records_times[i - 1] }; let rpc_url = rpc_url.clone(); let chain_id = chain_id; let mut time_since_beginning = now; + tokio::time::sleep(relative_start_duration).await; handles.push(tokio::spawn({ async move { - tokio::time::sleep(relative_start_duration).await; time_since_beginning += relative_start_duration.as_secs(); let provider = Provider::<Http>::try_from(rpc_url.clone()).unwrap(); diff --git a/src/utils/mobility_data.rs b/src/utils/mobility_data.rs index 051c0b5c6226fb31afa36e7c37a1e48739117bbd..0bf444c3d90cf4b513d64979828b2f6b8733533f 100644 --- a/src/utils/mobility_data.rs +++ b/src/utils/mobility_data.rs @@ -99,6 +99,8 @@ pub fn generate_behaviors_from_records(records: Vec<MobilityRecord>) -> Vec<Mobi let earliest_datetime = find_earliest_mobility_record(&records); // let dataset_id = thread_rng().gen::<u64>(); + let mut start_times:Vec<i128> = records.iter().map(|r| r.created_at.sub(earliest_datetime).whole_milliseconds()).collect(); + start_times.sort_unstable(); records .iter() @@ -106,11 +108,11 @@ pub fn generate_behaviors_from_records(records: Vec<MobilityRecord>) -> Vec<Mobi .map(|(i, r)| MobilityBehavior { id: i as u64, // dataset_id, - relative_start_time: r.created_at.sub(earliest_datetime).whole_milliseconds(), + relative_start_time: start_times[i], quantity: quantify_mobility(r.service.clone()), mobility_record: r.clone(), }) - .collect() + .collect::<Vec<MobilityBehavior>>() } /// Strech behavior start time for simulation