From 608d187373b6015cc3d020481027e987c83e159f Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 15 Feb 2024 09:30:35 +0100 Subject: [PATCH 1/8] update dockerfile to remove update --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 010ef38..fb22ac5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,3 @@ FROM rust:1.70.0 as build-env 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 -- GitLab From a3b291a97dcbf59f77b786d2b1f506a2a047117b Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 15 Feb 2024 12:01:09 +0100 Subject: [PATCH 2/8] Changed scripts so they are kept and able to be executed. Image size reduced --- Dockerfile | 5 +++++ scripts/t0-1mine-2sync.sh | 6 +++--- scripts/t1-1mine-with-simulation-2sync.sh | 6 +++--- scripts/t2-n-miners-m-sync.sh | 4 ++-- scripts/t2.sh | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb22ac5..8eaadee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,3 +2,8 @@ FROM rust:1.70.0 as build-env WORKDIR /app COPY . /app RUN cargo build --release + +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/t0-1mine-2sync.sh b/scripts/t0-1mine-2sync.sh index 3dd826e..6245340 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 c8d6321..4160c47 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 f213094..aef8317 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 e62ef7a..d70512f 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'; -- GitLab From 3e9c802c8cad75df172e10bd7deb65846115a966 Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 15 Feb 2024 15:33:22 +0100 Subject: [PATCH 3/8] created new parameterizable script for simulation on docker compose --- scripts/run_simulation_2_nodes.sh | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/run_simulation_2_nodes.sh diff --git a/scripts/run_simulation_2_nodes.sh b/scripts/run_simulation_2_nodes.sh new file mode 100755 index 0000000..21e7cbf --- /dev/null +++ b/scripts/run_simulation_2_nodes.sh @@ -0,0 +1,35 @@ +#!/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 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/dataset-extract.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 + + -- GitLab From 6db1fe6803dce4e168c137aecb63644d924a8f6e Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 15 Feb 2024 17:19:16 +0100 Subject: [PATCH 4/8] Update simulation data read --- scripts/run_simulation_2_nodes.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/run_simulation_2_nodes.sh b/scripts/run_simulation_2_nodes.sh index 21e7cbf..d7b7218 100755 --- a/scripts/run_simulation_2_nodes.sh +++ b/scripts/run_simulation_2_nodes.sh @@ -9,12 +9,13 @@ export MNEMONIC='before exclude interest push zone jealous boat ice chimney juic # 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/dataset-extract.csv $TOTAL_SIMULATION_TIME & +./target/release/testnet-injector simulate-bx-from-csv ./data/anonymized_june-to-august-2023_mulhouse_dataset.csv $TOTAL_SIMULATION_TIME & echo "TOTAL_SIMULATION_TIME = $TOTAL_SIMULATION_TIME and block time = $BLOCK_TIME" # Mine -- GitLab From 11c339a80a38f471bc590d283fa754ce78db12bd Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Tue, 27 Feb 2024 10:17:30 +0100 Subject: [PATCH 5/8] update file path, using france dataset and not mulhouse only --- scripts/run_simulation_2_nodes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_simulation_2_nodes.sh b/scripts/run_simulation_2_nodes.sh index d7b7218..1ddcf35 100755 --- a/scripts/run_simulation_2_nodes.sh +++ b/scripts/run_simulation_2_nodes.sh @@ -15,7 +15,7 @@ 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-august-2023_mulhouse_dataset.csv $TOTAL_SIMULATION_TIME & +./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 -- GitLab From c5beff300b2cb14d6beb5091a1b805f4587527f0 Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 29 Feb 2024 09:38:51 +0100 Subject: [PATCH 6/8] Fix behaviors sent in simulation, now recover sender matches the wallet used for signing --- src/utils/miner.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/miner.rs b/src/utils/miner.rs index 4afe052..483057f 100644 --- a/src/utils/miner.rs +++ b/src/utils/miner.rs @@ -10,6 +10,7 @@ use ethers::{ TransactionRequest, }, }; +use ethers::utils::keccak256; use ethnum::U256; /// Get a RPC Behavior for miner with default values, ready to send. @@ -52,7 +53,7 @@ pub fn get_miner_behavior( // let behavior = wallet. let tr = TransactionRequest::new() .to(to) - .value(primitive_types::U256::zero()) + .value(primitive_types::U256::from(quantity.as_u128())) .chain_id(chain_id) .data(behavior_msg.input.0.clone()); @@ -60,17 +61,20 @@ pub fn get_miner_behavior( // wallet.sig let signature = wallet .sign_transaction_sync( - ðers::types::transaction::eip2718::TypedTransaction::EcoMobiCoinBehavior(bx), + ðers::types::transaction::eip2718::TypedTransaction::EcoMobiCoinBehavior(bx.clone()), ) .unwrap(); + let behavior_rlp = bx.rlp(); + let bx_hash: primitive_types::H256 = keccak256(behavior_rlp.as_ref()).into(); + let hash = primitive_types::H256::from(bx_hash); Behavior { message: behavior_msg, v: signature.v.into(), r: H256::from(signature.r).into(), s: H256::from(signature.s).into(), from: wallet.address(), - hash: H256::default().into(), + hash, behavior_index: None, block_number: None, block_hash: None, -- GitLab From 326a159f9df76380d93dbac3230dbf34ccfb213c Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Thu, 29 Feb 2024 11:45:38 +0100 Subject: [PATCH 7/8] Revert commit, will do it directly on main --- src/utils/miner.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/utils/miner.rs b/src/utils/miner.rs index 483057f..4afe052 100644 --- a/src/utils/miner.rs +++ b/src/utils/miner.rs @@ -10,7 +10,6 @@ use ethers::{ TransactionRequest, }, }; -use ethers::utils::keccak256; use ethnum::U256; /// Get a RPC Behavior for miner with default values, ready to send. @@ -53,7 +52,7 @@ pub fn get_miner_behavior( // let behavior = wallet. let tr = TransactionRequest::new() .to(to) - .value(primitive_types::U256::from(quantity.as_u128())) + .value(primitive_types::U256::zero()) .chain_id(chain_id) .data(behavior_msg.input.0.clone()); @@ -61,20 +60,17 @@ pub fn get_miner_behavior( // wallet.sig let signature = wallet .sign_transaction_sync( - ðers::types::transaction::eip2718::TypedTransaction::EcoMobiCoinBehavior(bx.clone()), + ðers::types::transaction::eip2718::TypedTransaction::EcoMobiCoinBehavior(bx), ) .unwrap(); - let behavior_rlp = bx.rlp(); - let bx_hash: primitive_types::H256 = keccak256(behavior_rlp.as_ref()).into(); - let hash = primitive_types::H256::from(bx_hash); Behavior { message: behavior_msg, v: signature.v.into(), r: H256::from(signature.r).into(), s: H256::from(signature.s).into(), from: wallet.address(), - hash, + hash: H256::default().into(), behavior_index: None, block_number: None, block_hash: None, -- GitLab From a663a973c2485bc2a5579891cfe3dd2d332ed084 Mon Sep 17 00:00:00 2001 From: JeromeDeschamps <jerome.deschamps@uca.fr> Date: Fri, 1 Mar 2024 11:45:48 +0100 Subject: [PATCH 8/8] Changes to how data is handled, threads sleeps, csv times assignments --- src/main.rs | 7 +++++-- src/utils/mobility_data.rs | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ccfe39d..a965670 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 051c0b5..0bf444c 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 -- GitLab