From 83441e50899d29c7cf0f4063e2eec35be966a5df Mon Sep 17 00:00:00 2001 From: dusterbloom <32869278+dusterbloom@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:59:26 +0200 Subject: [PATCH] #77 FIX - Changed ` quartz.manifest.template` to allow any port for the enclave (#92) --- apps/transfers/enclave/quartz.manifest.template | 1 + apps/transfers/enclave/src/cli.rs | 10 ++++++++-- apps/transfers/scripts/listen.sh | 5 ++++- relayer/scripts/relay.sh | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/transfers/enclave/quartz.manifest.template b/apps/transfers/enclave/quartz.manifest.template index 7c2854d..85dd4fd 100644 --- a/apps/transfers/enclave/quartz.manifest.template +++ b/apps/transfers/enclave/quartz.manifest.template @@ -18,6 +18,7 @@ loader.env.RA_TLS_ISV_SVN = { passthrough = true } loader.env.RA_TLS_ISV_PROD_ID = { passthrough = true } loader.env.RA_TLS_EPID_API_KEY = { passthrough = true } loader.env.MYAPP_DATA = { passthrough = true } +loader.env.QUARTZ_PORT = { passthrough = true } loader.argv = ["enclave", "--chain-id", "testing", diff --git a/apps/transfers/enclave/src/cli.rs b/apps/transfers/enclave/src/cli.rs index 7c59e62..21345f3 100644 --- a/apps/transfers/enclave/src/cli.rs +++ b/apps/transfers/enclave/src/cli.rs @@ -1,4 +1,4 @@ -use std::net::SocketAddr; +use std::{env, net::SocketAddr}; use clap::Parser; use color_eyre::eyre::{eyre, Result}; @@ -19,7 +19,7 @@ fn parse_trust_threshold(s: &str) -> Result { #[command(author, version, about, long_about = None)] pub struct Cli { /// RPC server address - #[clap(long, default_value = "127.0.0.1:11090")] + #[clap(long, default_value_t = default_rpc_addr())] pub rpc_addr: SocketAddr, /// Identifier of the chain @@ -50,3 +50,9 @@ pub struct Cli { #[clap(long, default_value = "5")] pub max_block_lag: u64, } + + +fn default_rpc_addr() -> SocketAddr { + let port = env::var("QUARTZ_PORT").unwrap_or_else(|_| "11090".to_string()); + format!("127.0.0.1:{}", port).parse().expect("Invalid socket address") +} diff --git a/apps/transfers/scripts/listen.sh b/apps/transfers/scripts/listen.sh index 34045fe..dbcbe4e 100755 --- a/apps/transfers/scripts/listen.sh +++ b/apps/transfers/scripts/listen.sh @@ -5,6 +5,9 @@ ROOT=${ROOT:-$HOME} DEFAULT_NODE="127.0.0.1:26657" NODE_URL=${NODE_URL:-$DEFAULT_NODE} +# Use the QUARTZ_PORT environment variable if set, otherwise default to 11090 +QUARTZ_PORT="${QUARTZ_PORT:-11090}" + if [ "$#" -eq 0 ]; then echo "Usage: $0 " exit 1 # Exit with a non-zero status to indicate an error @@ -56,7 +59,7 @@ echo "subscribe to events" cd $ROOT/cycles-quartz/apps/transfers/enclave echo "... executing transfer" - export UPDATE=$(grpcurl -plaintext -import-path ./proto/ -proto transfers.proto -d "$REQUEST_MSG" '127.0.0.1:11090' transfers.Settlement/Run | jq .message | jq -R 'fromjson | fromjson' | jq -c ) + export UPDATE=$(grpcurl -plaintext -import-path ./proto/ -proto transfers.proto -d "$REQUEST_MSG" "127.0.0.1:$QUARTZ_PORT" transfers.Settlement/Run | jq .message | jq -R 'fromjson | fromjson' | jq -c ) diff --git a/relayer/scripts/relay.sh b/relayer/scripts/relay.sh index f0e99ce..b1a8b61 100755 --- a/relayer/scripts/relay.sh +++ b/relayer/scripts/relay.sh @@ -20,11 +20,14 @@ REPORT_SIG_FILE="/tmp/${USER}_datareportsig" REQUEST="$1" REQUEST_MSG=${2:-"{}"} +# Use the QUARTZ_PORT environment variable if set, otherwise default to 11090 +QUARTZ_PORT="${QUARTZ_PORT:-11090}" + # clear tmp files from previous runs rm -f "$QUOTE_FILE" "$REPORT_FILE" "$REPORT_SIG_FILE" # query the gRPC quartz enclave service -ATTESTED_MSG=$(grpcurl -plaintext -import-path "$DIR_PROTO" -proto quartz.proto -d "$REQUEST_MSG" '127.0.0.1:11090' quartz.Core/"$REQUEST" | jq -c '.message | fromjson') +ATTESTED_MSG=$(grpcurl -plaintext -import-path "$DIR_PROTO" -proto quartz.proto -d "$REQUEST_MSG" "127.0.0.1:$QUARTZ_PORT" quartz.Core/"$REQUEST" | jq -c '.message | fromjson') # parse out the quote and the message QUOTE=$(echo "$ATTESTED_MSG" | jq -c '.quote')