Skip to content

Commit

Permalink
Merge branch 'main' into feat/store-block-number-and-hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Jan 10, 2025
2 parents 3b6bbfa + 084f809 commit 1228c49
Show file tree
Hide file tree
Showing 36 changed files with 505 additions and 110 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-xmtpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Git describe
id: ghd
uses: proudust/gh-describe@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -62,7 +64,7 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: "GIT_COMMIT=dev-${{ github.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }}"
build-args: "VERSION=${{ steps.ghd.outputs.describe }}"

- name: Set xmtpd digest output
if: ${{ matrix.image == 'xmtpd' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: "GIT_COMMIT=${{ github.ref_name }}-${{ github.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }}"
build-args: "VERSION=${{ github.ref_name }}-${{ github.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }}"
42 changes: 42 additions & 0 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,45 @@ jobs:
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: contracts/output.sarif

abis:
needs: init
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Restore cache
uses: actions/cache/restore@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}

- name: Restore forge
uses: actions/download-artifact@v4
with:
name: forge
path: /usr/local/bin

- run: chmod +x /usr/local/bin/forge

- name: Setup Go
uses: actions/setup-go@v5

- name: Install abigen
run: go install github.com/ethereum/go-ethereum/cmd/[email protected]

- name: Generate ABIs
run: dev/generate

- name: Check for ABI changes
working-directory: ${{ github.workspace }}
run: |
if git diff --exit-code --ignore-space-change --ignore-all-space --ignore-cr-at-eol -- contracts/pkg; then
echo "No ABI changes detected."
else
echo "ERROR: Generated files are not up to date. Please run 'contracts/dev/generate' and commit the changes."
exit 1
fi
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ jobs:
name: Test (Node)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-tags: true
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ build/*
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml
.idea/**/contentModel.xml

# Ignores development deployments
contracts/config/anvil_localnet/*
*.tmp.log
16 changes: 12 additions & 4 deletions cmd/replication/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/Masterminds/semver/v3"
"log"
"sync"

Expand All @@ -18,7 +19,7 @@ import (
"go.uber.org/zap"
)

var Commit string = "unknown"
var Version string = "unknown"

var options config.ServerOptions

Expand All @@ -33,7 +34,7 @@ func main() {
}

if options.Version {
fmt.Printf("Version: %s\n", Commit)
fmt.Printf("Version: %s\n", Version)
return
}

Expand All @@ -48,10 +49,16 @@ func main() {
}
logger = logger.Named("replication")

logger.Info(fmt.Sprintf("Version: %s", Commit))
logger.Info(fmt.Sprintf("Version: %s", Version))

version, err := semver.NewVersion(Version)
if err != nil {
logger.Error(fmt.Sprintf("Could not parse semver version (%s): %s", Version, err))
}

if options.Tracing.Enable {
logger.Info("starting tracer")
tracing.Start(Commit, logger)
tracing.Start(Version, logger)
defer func() {
logger.Info("stopping tracer")
tracing.Stop()
Expand Down Expand Up @@ -124,6 +131,7 @@ func main() {
dbInstance,
blockchainPublisher,
fmt.Sprintf("0.0.0.0:%d", options.API.Port),
version,
)
if err != nil {
log.Fatal("initializing server", zap.Error(err))
Expand Down
4 changes: 4 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ out/
/broadcast/*/31337/
/broadcast/**/dry-run/

# Ignores development deployments
contracts/config/anvil_localnet/*
*.tmp.log

# Docs
docs/

Expand Down
2 changes: 1 addition & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ The scripts output the deployment and upgrade in the `output` folder.
- Deploy with `forge create`:

```shell
forge create --broadcast --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "src/Nodes.sol:Nodes"
forge create --broadcast --legacy --json --rpc-url $RPC_URL --private-key $PRIVATE_KEY "src/Nodes.sol:Nodes"
```
29 changes: 18 additions & 11 deletions contracts/dev/deploy-local
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/bin/bash
# Deploy the smart contracts to the local anvil node
set -euo pipefail

# Make sure the build directory exists
mkdir -p ./build
############################################
# Work always from the contracts directory #
############################################
export source_dir="${SOURCE_DIR:-src}"
export build_dir="${BUILD_DIR:-build}"
export output_dir="${OUTPUT_DIR:-pkg}"
export localnet_dir="${LOCALNET_DIR:-config/anvil_localnet}"

# Always work from the contracts directory
script_dir=$(dirname "$(realpath "$0")")
repo_root=$(realpath "${script_dir}/../")
cd "${repo_root}"

mkdir -p "${build_dir}" \
"${output_dir}" \
"${localnet_dir}"

source dev/lib/env
source dev/lib/common

# Update depencencies
forge soldeer update &> /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: Failed to update dependencies"
exit 1
fi

############################################
# Deploy the smart contracts to ${RPC_URL} #
############################################
forge_clean
forge_soldeer_update
forge_build_contracts
forge_test_contracts
forge_deploy_script group_messages
forge_deploy_script identity_updates
forge_deploy_script nodes src/Nodes.sol Nodes
39 changes: 21 additions & 18 deletions contracts/dev/generate
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/bin/bash

set -euo pipefail

# Default directories (can be overridden with environment variables)
source_dir="${SOURCE_DIR:-src}"
build_dir="${BUILD_DIR:-build}"
output_dir="${OUTPUT_DIR:-pkg}"
############################################
# Work always from the contracts directory #
############################################
export source_dir="${SOURCE_DIR:-src}"
export build_dir="${BUILD_DIR:-build}"
export output_dir="${OUTPUT_DIR:-pkg}"

# Ensure required directories exist and clean up old artifacts
function setup_directories() {
mkdir -p "${build_dir}" "${output_dir}"
}
script_dir=$(dirname "$(realpath "$0")")
repo_root=$(realpath "${script_dir}/../")
cd "${repo_root}"

mkdir -p "${build_dir}" "${output_dir}"

# Generate bindings for a given contract
function generate_bindings() {
local filename="$1"
local package="$(echo "${filename}" | tr '[:upper:]' '[:lower:]')"
Expand Down Expand Up @@ -47,13 +48,6 @@ function generate_bindings() {
}

function main() {
# Always work from the contracts directory
script_dir=$(dirname "$(realpath "$0")")
repo_root=$(realpath "${script_dir}/../")
cd "${repo_root}"

setup_directories

# Define contracts (pass as arguments or use a default list)
local contracts=("$@")
if [ "${#contracts[@]}" -eq 0 ]; then
Expand All @@ -62,9 +56,18 @@ function main() {

# Generate bindings for each contract
for contract in "${contracts[@]}"; do
echo "Processing contract: ${contract}"
echo "⧖ Generating ABIs for contract: ${contract}"
generate_bindings "${contract}"
done
echo -e "\033[32m✔\033[0m ABIs generated successfully!\n"
}

#################################################
# Generate the smart contracts bindings for Go #
#################################################
source dev/lib/env
source dev/lib/common

forge_clean
forge_soldeer_update
main "$@"
86 changes: 73 additions & 13 deletions contracts/dev/lib/common
Original file line number Diff line number Diff line change
@@ -1,43 +1,103 @@
#!/bin/bash
set -euo pipefail

function get_chain_id() {
hex_chain_id=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_chainId","id":1}' ${RPC_URL} | jq -r '.result')
export chain_id=$((hex_chain_id))
}

function forge_deploy_script() {
get_chain_id
case $1 in
group_messages)
forge script --rpc-url "${DOCKER_RPC_URL}" --broadcast script/DeployGroupMessages.s.sol &> /dev/null
echo "⧖ Deploying GroupMessages to chainId ${chain_id} using RPC ${RPC_URL}"
forge script --quiet --rpc-url "${RPC_URL}" --broadcast script/DeployGroupMessages.s.sol
if [ $? -ne 0 ]; then
echo "Failed to deploy group messages contract"
exit 1
fi

echo -e "✅ GroupMessages contract deployed.\n"
cat config/anvil_localnet/GroupMessages.json
echo -e "\n"
echo -e "\033[32m✔\033[0m GroupMessages deployed. Deployment details in contracts/config/anvil_localnet/GroupMessages.json\n"
;;

identity_updates)
forge script --rpc-url "${DOCKER_RPC_URL}" --broadcast script/DeployIdentityUpdates.s.sol &> /dev/null
echo "⧖ Deploying IdentityUpdates to chainId ${chain_id} using RPC ${RPC_URL}"
forge script --quiet --rpc-url "${RPC_URL}" --broadcast script/DeployIdentityUpdates.s.sol
if [ $? -ne 0 ]; then
echo "Failed to deploy identity updates contract"
exit 1
fi

echo -e "✅ IdentityUpdates contract deployed.\n"
cat config/anvil_localnet/IdentityUpdates.json
echo -e "\n"
echo -e "\033[32m✔\033[0m IdentityUpdates deployed. Deployment details in contracts/config/anvil_localnet/IdentityUpdates.json\n"
;;

nodes)
# TODO: Migrate to forge script
forge create --broadcast --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$2:$3" > ../build/$3.json
echo -e "✅ Nodes contract deployed.\n"
cat ../build/$3.json
echo -e "\n"
echo "⧖ Deploying Nodes to chainId ${chain_id} using RPC ${RPC_URL}"
forge create --broadcast --legacy --json --rpc-url $RPC_URL --private-key $PRIVATE_KEY "$2:$3" > config/anvil_localnet/$3.json
echo -e "\033[32m✔\033[0m Nodes deployed. Deployment details in contracts/config/anvil_localnet/$3.json\n"
;;

*)
echo "Invalid option. Use 'group_messages' or 'identity_updates'."
echo "Invalid option. Use 'group_messages', 'identity_updates' or 'nodes'."
exit 1
;;
esac
}

function forge_clean() {
echo -e "⧖ Cleaning old artifacts"

forge clean &> .forge_clean.tmp.log
if [ $? -ne 0 ]; then
echo "ERROR: Failed to clean old artifacts"
cat .forge_clean.tmp.log
exit 1
fi
rm .forge_clean.tmp.log

echo -e "\033[32m✔\033[0m Old artifacts cleaned successfully\n"
}

function forge_soldeer_update() {
echo -e "⧖ Updating dependencies"

forge soldeer update &> .forge_soldeer_update.tmp.log
if [ $? -ne 0 ]; then
echo "ERROR: Failed to update dependencies"
cat .forge_soldeer_update.tmp.log
exit 1
fi
rm .forge_soldeer_update.tmp.log

echo -e "\033[32m✔\033[0m Dependencies updated successfully\n"
}

function forge_build_contracts() {
echo -e "⧖ Building contracts"

forge build &> .forge_build.tmp.log
if [ $? -ne 0 ]; then
echo "ERROR: Failed to build contracts"
cat .forge_build.tmp.log
exit 1
fi
rm .forge_build.tmp.log

echo -e "\033[32m✔\033[0m Contracts built successfully\n"
}

function forge_test_contracts() {
echo -e "⧖ Running contract tests"

forge test &> .forge_test.tmp.log
if [ $? -ne 0 ]; then
echo "ERROR: Tests failed"
cat .forge_test.tmp.log
exit 1
fi
rm .forge_test.tmp.log

echo -e "\033[32m✔\033[0m Tests passed successfully\n"
}

Loading

0 comments on commit 1228c49

Please sign in to comment.