Skip to content

Commit

Permalink
Set up dnsaddr link TXT recrod for bootstrap addresses
Browse files Browse the repository at this point in the history
To avoid updating bootstrap .pi files every time identities change set
up dnsaddr link using DNS TXT records for the network that is being
deployed.

Fixes #1598
  • Loading branch information
masih committed Sep 11, 2024
1 parent 142bfb0 commit 27959b8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ansible/setup_fildev_network.bash
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ EOF
# generate multiaddrs for the bootstrap peers
bootstrap_multiaddrs=( $(ansible -o -i $hostfile -b -m debug -a 'msg="/dns4/{{ ansible_host }}/tcp/{{ lotus_libp2p_port }}/p2p/{{ lotus_libp2p_address }}"' bootstrap | sed 's/.* =>//' | jq -r '.msg') )

# Update dnsaddr link to bootstrap peers
../scripts/update_bootstrap_dnsaddrs.bash "${network}" "${bootstrap_multiaddrs[@]}"

pushd "$lotus_src"
rm -f ./build/genesis/${network_flag}.car || true
truncate -s 0 ./build/bootstrap/${network_flag}.pi

for multiaddr in ${bootstrap_multiaddrs[@]}; do
echo $multiaddr >> ./build/bootstrap/${network_flag}.pi
done
# Override bootstrap.pi file even though it doesn't change in case we are deploying a Lotus branch that does not use dnsaddr link.
echo "/dnsaddr/bootstrap.${network}" > ./build/bootstrap/${network_flag}.pi
popd

read -p "Press enter to continue"
Expand Down
62 changes: 62 additions & 0 deletions scripts/update_bootstrap_dnsaddrs.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# Ensure correct usage: at least 2 arguments (network-name and one or more bootstrap multiaddr)
[[ $# -lt 2 ]] && { echo "Usage: $0 <network-name> <multiaddr>..."; exit 1; }

NETWORK_NAME=${1}

# Extract the domain name
DOMAIN_NAME=$(
case ${NETWORK_NAME} in
butterflynet) printf 'butterfly.fildev.network' ;;
*) exit 1 ;;
esac
) || {
echo "❌ Unknown network: ${NETWORK_NAME}"
exit 1
}
echo "✅ Using domain name: ${DOMAIN_NAME}"
shift 1

# Find the Route53 hosted zone ID from domain name.
LIST_OUTPUT=$(aws route53 list-hosted-zones-by-name --dns-name "${DOMAIN_NAME}" --query 'HostedZones[0].Id' --output text 2>&1) || {
echo "❌ Hosted zone not found for '${NETWORK_NAME}' network with domain '${DOMAIN_NAME}':"
echo "${LIST_OUTPUT}"
exit 1
}
HOSTED_ZONE_ID=${LIST_OUTPUT#/hostedzone/}
echo "✅ Found hosted zone ID for domain: ${HOSTED_ZONE_ID}"

# Create an array of ResourceRecords, each prefixed with "dnsaddr=" and remove tailing comma.
# See addressing spec:
# - https://github.com/libp2p/specs/blob/master/addressing/README.md#dnsaddr-links
RESOURCE_RECORDS=$(printf '{"Value": "\\"dnsaddr=%s\\""},' "$@")
RESOURCE_RECORDS=${RESOURCE_RECORDS%,}

# Submit the change batch to upsert the TXT record and capture the change ID.
CHANGE_OUTPUT=$(aws route53 change-resource-record-sets \
--hosted-zone-id "${HOSTED_ZONE_ID}" \
--change-batch '{
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "_dnsaddr.bootstrap.'"${DOMAIN_NAME}"'",
"Type": "TXT",
"TTL": 300,
"ResourceRecords": ['"${RESOURCE_RECORDS}"']
}
}]
}' --query 'ChangeInfo.Id' --output text 2>&1) || {
echo '❌ Failed to submit TXT record changes:'
echo "${CHANGE_OUTPUT}"
exit 1
}

echo '✅ Change submitted successfully. Waiting for the changes to propagate...'
aws route53 wait resource-record-sets-changed --id "${CHANGE_OUTPUT}" || {
echo '❌ Failed to propagate the TXT record.'
exit 1
}

echo "✅ Bootstrap dnsaddr for ${NETWORK_NAME} network propagated successfully:"
echo " /dnsaddr/bootstrap.${DOMAIN_NAME}"

0 comments on commit 27959b8

Please sign in to comment.