From 96c7bcad4367534cf8ca841e1d26da0a5cfeba75 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 18 Sep 2023 12:02:04 +0530 Subject: [PATCH] Setup consensus config --- .../docker-compose-watcher-mobymask-v3.yml | 2 + ...T9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ.json | 11 ++++ ...S4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5.json | 11 ++++ ...kAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi.json | 11 ++++ .../watcher-mobymask-v3/start-server.sh | 60 +++++++++++++++++++ .../watcher-config-template.toml | 8 ++- app/data/stacks/mobymask-v3/watcher.md | 4 ++ 7 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 app/data/config/watcher-mobymask-v3/keys/12D3KooWAMjBkFCT9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ.json create mode 100644 app/data/config/watcher-mobymask-v3/keys/12D3KooWBNEbY3QS4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5.json create mode 100644 app/data/config/watcher-mobymask-v3/keys/12D3KooWSRH6ftgkAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi.json diff --git a/app/data/compose/docker-compose-watcher-mobymask-v3.yml b/app/data/compose/docker-compose-watcher-mobymask-v3.yml index 655fbd82..4b12debd 100644 --- a/app/data/compose/docker-compose-watcher-mobymask-v3.yml +++ b/app/data/compose/docker-compose-watcher-mobymask-v3.yml @@ -92,6 +92,7 @@ services: CERC_CA_ADDRESS: ${CERC_CA_ADDRESS} CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER} CERC_PRIVATE_KEY_NITRO: ${CERC_PRIVATE_KEY_NITRO} + CERC_PEER_ID: ${CERC_PEER_ID} entrypoint: ["bash", "-c"] command: ["./deploy-nitro-contracts.sh && ./start-server.sh"] volumes: @@ -99,6 +100,7 @@ services: - ../config/watcher-mobymask-v3/deploy-nitro-contracts.ts:/app/deploy-nitro-contracts.ts - ../config/watcher-mobymask-v3/watcher-config-template.toml:/app/environments/watcher-config-template.toml - ../config/watcher-mobymask-v3/watcher-config-rates.toml:/app/environments/rates.toml + - ../config/watcher-mobymask-v3/keys:/app/keys - ../config/watcher-mobymask-v3/start-server.sh:/app/start-server.sh - peers_ids:/app/peers - nitro_addresses:/nitro diff --git a/app/data/config/watcher-mobymask-v3/keys/12D3KooWAMjBkFCT9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ.json b/app/data/config/watcher-mobymask-v3/keys/12D3KooWAMjBkFCT9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ.json new file mode 100644 index 00000000..84465346 --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/keys/12D3KooWAMjBkFCT9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ.json @@ -0,0 +1,11 @@ +{ + "peerId": { + "id": "12D3KooWAMjBkFCT9DtCnSDcxftxJzSuTBvzVojabv64cnEvX4AZ", + "privKey": "CAESQAKCrnY0QKTky1I18fqn+VPydXGUv1NYiV+nVKqBFkw/CAjE9sKKIDGnYAo8mivnI6dngFenERY+0Q8AJrPTaXY=", + "pubKey": "CAESIAgIxPbCiiAxp2AKPJor5yOnZ4BXpxEWPtEPACaz02l2" + }, + "consensus": { + "publicKey": "02cd17b05ca998955be5ca7bf4fd4531243d438f1aae7ce8a0ed5159f53cee5b40", + "privateKey": "67d80505614bdf61fca11cbad31d93acb2c7df1c653dc25975d77d05f05f154f" + } +} diff --git a/app/data/config/watcher-mobymask-v3/keys/12D3KooWBNEbY3QS4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5.json b/app/data/config/watcher-mobymask-v3/keys/12D3KooWBNEbY3QS4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5.json new file mode 100644 index 00000000..8eea1872 --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/keys/12D3KooWBNEbY3QS4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5.json @@ -0,0 +1,11 @@ +{ + "peerId": { + "id": "12D3KooWBNEbY3QS4y23ngupDw9PDc4bvNvRJGVRejjV9EZLjux5", + "privKey": "CAESQGSTw0ymvn8+wX9Dbvyr4/Gib1q2voe0CC0VyeClMQP6FwW14x0fpRbBIx0XhLdxWHkRndphVg3gVAHyC+7ZI8o=", + "pubKey": "CAESIBcFteMdH6UWwSMdF4S3cVh5EZ3aYVYN4FQB8gvu2SPK" + }, + "consensus": { + "publicKey": "029c8035b3e9401b8f178f7c37285b5cb22501e017340e2058b3b842f2a1f0ae45", + "privateKey": "0261008e8e3ec808168e99333599da38ca59a056a2ae4510a6ad3d8b5cb0918c" + } +} diff --git a/app/data/config/watcher-mobymask-v3/keys/12D3KooWSRH6ftgkAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi.json b/app/data/config/watcher-mobymask-v3/keys/12D3KooWSRH6ftgkAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi.json new file mode 100644 index 00000000..80721faa --- /dev/null +++ b/app/data/config/watcher-mobymask-v3/keys/12D3KooWSRH6ftgkAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi.json @@ -0,0 +1,11 @@ +{ + "peerId": { + "id": "12D3KooWSRH6ftgkAZsKZK7UX1Zr6Hx6YAsEepHqzopFszqfTxxi", + "privKey": "CAESQHBjlHxfVhZ2gXsBItrIEEgSGKcjMkFiGs3PPz9E3ace9qyWEkvR4oit5ve9SAROVoh20hoa42IC91NIafMaqws=", + "pubKey": "CAESIPaslhJL0eKIreb3vUgETlaIdtIaGuNiAvdTSGnzGqsL" + }, + "consensus": { + "publicKey": "039160c244a7ad8be16a64bdb69e6dbacdcfe20b37076792a0d06032a8097468ca", + "privateKey": "8894685fe81001d75662b079905472699373967451d1255ee5fc669d0a09a9ca" + } +} diff --git a/app/data/config/watcher-mobymask-v3/start-server.sh b/app/data/config/watcher-mobymask-v3/start-server.sh index 92a052cb..9ff4020f 100755 --- a/app/data/config/watcher-mobymask-v3/start-server.sh +++ b/app/data/config/watcher-mobymask-v3/start-server.sh @@ -52,6 +52,61 @@ fi echo "Using CERC_PRIVATE_KEY_PEER (account with funds) from env for sending txs to L2" echo "Using CERC_PRIVATE_KEY_NITRO from env for Nitro account" +if [ -n "$CERC_PEER_ID" ]; then + echo "Using CERC_PEER_ID ${CERC_PEER_ID} from env for watcher fixture" + echo "Consensus module enabled" + + # Set corresponding variables + PEER_ID_FILE='./peer-id.json' + CONSENSUS_ENABLED=true + WATCHER_PARTY_PEERS_FILE='./watcher-party-peers.json' + + # Create watcher party array + watcher_parties=() + + # Iterate over each fixture JSON file + for peer_data_file in "$watcher_keys_dir"/*.json; do + # Extract the filename without the path and extension + peer_id=$(basename "$peer_data_file" .json) + + # Read the consensus keys + consensus_public_key=$(jq -r '.consensus.publicKey' "$peer_data_file") + consensus_private_key=$(jq -r '.consensus.privateKey' "$peer_data_file") + + # Append watcher party + watcher_party=$(jq -n \ + --arg peerId "$peer_id" \ + --arg publicKey "$consensus_public_key" \ + '.peerId = $peerId | .publicKey = $publicKey') + watcher_parties+=("$watcher_party") + + if [ "$peer_id" = "$CERC_PEER_ID" ]; then + # Export peer id + peer_id_data=$(jq '.peerId' "$peer_data_file") + echo "$peer_id_data" > "${PEER_ID_FILE}" + + # Set consensus keys for this peer + CONSENSUS_PUBLIC_KEY=${consensus_public_key} + CONSENSUS_PRIVATE_KEY=${consensus_private_key} + fi + done + + # Export watcher party file + watcher_parties_json=$(printf '%s\n' "${watcher_parties[@]}" | jq -s .) + echo "$watcher_parties_json" > "${WATCHER_PARTY_PEERS_FILE}" + echo "Watcher party peers exported to ${WATCHER_PARTY_PEERS_FILE}" +else + echo "Using generated peer id" + echo "Consensus module disabled" + + # Set corresponding variables + PEER_ID_FILE='./peers/peer-id.json' + CONSENSUS_ENABLED=false + WATCHER_PARTY_PEERS_FILE='' + CONSENSUS_PUBLIC_KEY='' + CONSENSUS_PRIVATE_KEY='' +fi + # Read in the config template TOML file and modify it WATCHER_CONFIG_TEMPLATE=$(cat environments/watcher-config-template.toml) WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ @@ -60,10 +115,15 @@ WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \ s/REPLACE_WITH_CERC_PUBSUB/${CERC_PUBSUB}/g; \ s/REPLACE_WITH_CERC_RELAY_ANNOUNCE_DOMAIN/${CERC_RELAY_ANNOUNCE_DOMAIN}/g; \ s|REPLACE_WITH_CERC_RELAY_MULTIADDR|${CERC_RELAY_MULTIADDR}|g; \ + s|REPLACE_WITH_PEER_ID_FILE|${PEER_ID_FILE}|g; \ s/REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS/${CERC_ENABLE_PEER_L2_TXS}/g; \ s/REPLACE_WITH_CERC_PRIVATE_KEY_PEER/${CERC_PRIVATE_KEY_PEER}/g; \ s/REPLACE_WITH_CERC_PRIVATE_KEY_NITRO/${CERC_PRIVATE_KEY_NITRO}/g; \ s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/g; \ + s/REPLACE_WITH_CONSENSUS_ENABLED/${CONSENSUS_ENABLED}/g; \ + s/REPLACE_WITH_CONSENSUS_PUBLIC_KEY/${CONSENSUS_PUBLIC_KEY}/g; \ + s/REPLACE_WITH_CONSENSUS_PRIVATE_KEY/${CONSENSUS_PRIVATE_KEY}/g; \ + s|REPLACE_WITH_WATCHER_PARTY_PEERS_FILE|${WATCHER_PARTY_PEERS_FILE}|g; \ s|REPLACE_WITH_CERC_L2_GETH_RPC_ENDPOINT|${CERC_L2_GETH_RPC}| ") # Write the modified content to a new file diff --git a/app/data/config/watcher-mobymask-v3/watcher-config-template.toml b/app/data/config/watcher-mobymask-v3/watcher-config-template.toml index 911dee74..dbf5b407 100644 --- a/app/data/config/watcher-mobymask-v3/watcher-config-template.toml +++ b/app/data/config/watcher-mobymask-v3/watcher-config-template.toml @@ -37,7 +37,7 @@ relayMultiaddr = 'REPLACE_WITH_CERC_RELAY_MULTIADDR' pubSubTopic = 'mobymask' denyMultiaddrs = REPLACE_WITH_CERC_DENY_MULTIADDRS - peerIdFile = './peers/peer-id.json' + peerIdFile = 'REPLACE_WITH_PEER_ID_FILE' pubsub = 'REPLACE_WITH_CERC_PUBSUB' enableDebugInfo = true enableL2Txs = REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS @@ -63,6 +63,12 @@ maxPaymentChannels = 10000 paymentChannelTTLInSecs = 1800 + [server.p2p.consensus] + enabled = REPLACE_WITH_CONSENSUS_ENABLED + publicKey = 'REPLACE_WITH_CONSENSUS_PUBLIC_KEY' + privateKey = 'REPLACE_WITH_CONSENSUS_PRIVATE_KEY' + watcherPartyFile = 'REPLACE_WITH_WATCHER_PARTY_PEERS_FILE' + [metrics] host = "0.0.0.0" port = 9000 diff --git a/app/data/stacks/mobymask-v3/watcher.md b/app/data/stacks/mobymask-v3/watcher.md index 8b171c0e..4fa7007c 100644 --- a/app/data/stacks/mobymask-v3/watcher.md +++ b/app/data/stacks/mobymask-v3/watcher.md @@ -70,6 +70,10 @@ Create and update an env file to be used in the next step ([defaults](../../conf # Specify private key for the Nitro account CERC_PRIVATE_KEY_NITRO= + + # (Optional) Set a pre-existing peer id to be used (enables consensus) + # Uses a generated peer id if not set (disables consensus) + CERC_PEER_ID= ``` * NOTE: If Optimism is running on the host machine, use `host.docker.internal` as the hostname to access the host port