diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..787fae8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__/ +*.py[cod] +*$py.class +*.so +simulation diff --git a/scripts/build_cases.py b/scripts/build_cases.py new file mode 100644 index 0000000..368490c --- /dev/null +++ b/scripts/build_cases.py @@ -0,0 +1,34 @@ +import csv +import shutil +from build_config import build_config + +def build_case(overlay, committees, nodes, config_name, max_view=1, network='default'): + build_config(overlay, committees, nodes, config_name, max_view, network) + shutil.move(f"{config_name}.json", "../configs/") + +def build_cases(csv_path): + with open(csv_path, 'r') as csv_file: + reader = csv.reader(csv_file) + + for row in reader: + overlay_type, node_count, committees = row + + if overlay_type == "overlay": + continue + + config_name = f"{overlay_type}_{node_count}_{committees}" + + build_case(overlay_type, committees, node_count, f"{config_name}_view_1_default") + build_case(overlay_type, committees, node_count, f"{config_name}_view_10_default", max_view="10") + build_case(overlay_type, committees, node_count, f"{config_name}_view_10_optimistic", max_view="10", network="optimistic") + build_case(overlay_type, committees, node_count, f"{config_name}_view_10_pessimistic", max_view="10", network="pessimistic") + +if __name__ == "__main__": + import sys + if len(sys.argv) != 2: + print("Usage: python generate_configs.py ") + sys.exit(1) + + csv_path = sys.argv[1] + build_cases(csv_path) + diff --git a/scripts/build_cases.sh b/scripts/build_cases.sh deleted file mode 100755 index bee77dd..0000000 --- a/scripts/build_cases.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# Check if the input file is provided -if [ "$#" -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -# Read the CSV file line by line -while IFS=, read -r overlay_type node_count committees; do - if [[ "$overlay_type" == "overlay" ]]; then - continue - fi - - CONFIG_NAME="${overlay_type}_${node_count}_${committees}" - ./build_config.sh "$overlay_type" "$committees" "$node_count" $CONFIG_NAME"_view_1_default" - ./build_config.sh "$overlay_type" "$committees" "$node_count" $CONFIG_NAME"_view_10_default" 10 - ./build_config.sh "$overlay_type" "$committees" "$node_count" $CONFIG_NAME"_view_10_optimistic" 10 optimistic - ./build_config.sh "$overlay_type" "$committees" "$node_count" $CONFIG_NAME"_view_10_pessimistic" 10 pessimistic - mv *.json ../configs/ -done < $1 - diff --git a/scripts/build_config.py b/scripts/build_config.py new file mode 100644 index 0000000..c803878 --- /dev/null +++ b/scripts/build_config.py @@ -0,0 +1,54 @@ +import sys +import os +import json + +TEMPLATE_PATH = "config_builder/template.json" +TEMPORARY_PATH = "config_builder/temp.json" +NETWORK_UPDATE_PATH = "config_builder/network" +RECORD_UPDATE_PATH = "config_builder/record.json" + +def build_config(overlay_type, number_of_committees, node_count, config_name, max_view=1, network='default'): + + with open(TEMPLATE_PATH, 'r') as f: + data = json.load(f) + + network_file = f"{NETWORK_UPDATE_PATH}/network_{network}.json" + with open(network_file, 'r') as f: + network_update = json.load(f) + data["network_settings"] = network_update["network_settings"] + + with open(RECORD_UPDATE_PATH, 'r') as f: + record_update = json.load(f) + data["record_settings"] = record_update["record_settings"] + + data["node_count"] = int(node_count) + data["stream_settings"]["path"] = f"output/{config_name}.json" + data["wards"][0]["max_view"] = int(max_view) + + if overlay_type == "tree": + data["overlay_settings"]["number_of_committees"] = int(number_of_committees) + elif overlay_type == "branch": + data["overlay_settings"]["branch_depth"] = int(number_of_committees) + else: + print("Unknown overlay type. Supported types are 'tree' and 'branch'.") + return + + with open(f"{config_name}.json", 'w') as f: + json.dump(data, f, indent=4) + + print(f"Configuration built and saved as {config_name}.json") + +if __name__ == "__main__": + if len(sys.argv) < 5: + print("Usage: python config_builder.py [max_view] [network_config]") + sys.exit(1) + + overlay_type = sys.argv[1] + number_of_committees = sys.argv[2] + node_count = sys.argv[3] + config_name = sys.argv[4] + max_view = sys.argv[5] if len(sys.argv) > 5 else 1 + network_config = sys.argv[6] if len(sys.argv) > 6 else 'default' + + build_config(overlay_type, number_of_committees, node_count, config_name, max_view, network_config) + diff --git a/scripts/build_config.sh b/scripts/build_config.sh deleted file mode 100755 index 5fe6cd6..0000000 --- a/scripts/build_config.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -if [ "$#" -lt 4 ]; then - echo "Usage: $0 [max_view] [network_config]" - exit 1 -fi - -if ! command -v jq &> /dev/null; then - echo "jq is not installed." - exit 1 -fi - -if ! command -v sponge &> /dev/null; then - echo "moreutils is not installed." - exit 1 -fi - -OVERLAY_TYPE=$1 -NUMBER_OF_COMMITTEES=$2 -NODE_COUNT=$3 -CONFIG_NAME=$4 -MAX_VIEW=${5:-1} -NETWORK_CONFIG=${6:-default} - -TEMPLATE_PATH="config_builder/template.json" -TEMPORARY_PATH="config_builder/temp.json" -NETWORK_UPDATE_PATH="config_builder/network/network_$NETWORK_CONFIG.json" -RECORD_UPDATE_PATH="config_builder/record.json" - -# Update the template with the network settings -jq --slurpfile networkUpdate $NETWORK_UPDATE_PATH \ - '.network_settings = $networkUpdate[0].network_settings' $TEMPLATE_PATH | sponge $TEMPORARY_PATH - -# Update the template with the record settings -jq --slurpfile recordUpdate $RECORD_UPDATE_PATH \ - '.record_settings = $recordUpdate[0].record_settings' $TEMPORARY_PATH | sponge $TEMPORARY_PATH - -# Update new JSON with the command line arguments -jq --arg numCommit "$NUMBER_OF_COMMITTEES" \ - --arg nodeCount "$NODE_COUNT" \ - --arg confName "$CONFIG_NAME" \ - --arg maxView "$MAX_VIEW" \ - '.node_count = ($nodeCount | tonumber) | .stream_settings.path = "output/" + $confName + ".json" | .wards[0].max_view = ($maxView | tonumber)' $TEMPORARY_PATH | sponge $TEMPORARY_PATH - -if [ "$OVERLAY_TYPE" == "tree" ]; then - jq --arg numCommit "$NUMBER_OF_COMMITTEES" \ - '.overlay_settings.number_of_committees = ($numCommit | tonumber)' $TEMPORARY_PATH | sponge $TEMPORARY_PATH -elif [ "$OVERLAY_TYPE" == "branch" ]; then - cat $TEMPORARY_PATH | jq --arg numCommit "$NUMBER_OF_COMMITTEES" \ - '.overlay_settings.branch_depth = ($numCommit | tonumber)' $TEMPORARY_PATH | sponge $TEMPORARY_PATH -else - echo "Unknown overlay type. Supported types are 'tree' and 'branch'." - exit 1 -fi - -mv $TEMPORARY_PATH "$CONFIG_NAME.json" -echo "Configuration built and saved as $CONFIG_NAME.json" diff --git a/scripts/config_builder/record.json b/scripts/config_builder/record.json index 01c3304..8eefe0b 100644 --- a/scripts/config_builder/record.json +++ b/scripts/config_builder/record.json @@ -1,6 +1,15 @@ { "record_settings": { - "node_id": true, - "current_view": true + "current_view": true, + "highest_voted_view": true, + "local_high_qc": true, + "safe_blocks": false, + "last_view_timeout_qc": true, + "latest_committed_block": true, + "latest_committed_view": true, + "root_committee": false, + "parent_committee": false, + "child_committees": false, + "committed_blocks": false } }