Skip to content

Commit

Permalink
Add node run infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Nov 19, 2023
1 parent 3197e93 commit 01ca3da
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.DS_Store
build/deployments
**/.idea/
build/devnet/anvil_state.json
33 changes: 33 additions & 0 deletions build/devnet/deploy-rollups-anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash


# Run Anvil in the background
cmd="anvil --host 0.0.0.0 --dump-state anvil_state.json"
eval "${cmd}" &>/dev/null & disown;


# Check Anvil is ready
retries=0
max_retries=50
while [ $retries -lt $max_retries ]; do

ready=$(curl -X POST -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"net_listening","params":[]}' http://127.0.0.1:8545 | jq '.result')

if [ "$ready" == "true" ]; then
echo "Anvil is ready"
break
else
sleep 3
fi
done


# Deploy contracts with Foundry
### DEPLOY CONTRACTS HERE ###

# TEMP : To help debug
# read -n 1 -s -r -p "Press any key to continue"

sleep 3
#Kill Anvil ( just exit )
exit 0
38 changes: 38 additions & 0 deletions build/devnet/devnet.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# syntax=docker.io/docker/dockerfile:1.4
FROM debian:bookworm-20230814-slim as devnet-base

# install curl and jq (for healthcheck support)
RUN <<EOF
apt-get update
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends ca-certificates curl git jq xxd
rm -rf /var/lib/apt/lists/*
EOF

# download pre-compiled binaries
RUN curl -sSL https://github.com/foundry-rs/foundry/releases/download/nightly/foundry_nightly_linux_$(dpkg --print-architecture).tar.gz | \
tar -zx -C /usr/local/bin

# healthcheck script using net_listening JSON-RPC method
COPY eth_isready /usr/local/bin

HEALTHCHECK CMD eth_isready
CMD ["anvil"]


FROM devnet-base as devnet-deploy

WORKDIR /usr/share/cartesi
COPY deploy-rollups-anvil.sh .

RUN ./deploy-rollups-anvil.sh .


FROM devnet-base as devnet

WORKDIR /usr/share/cartesi
COPY ./entrypoint.sh /
COPY --from=devnet-deploy /usr/share/cartesi/anvil_state.json .
COPY --from=devnet-deploy /usr/share/cartesi/localhost.json .

ENTRYPOINT ["/entrypoint.sh"]
CMD ["anvil", "--load-state", "/usr/share/cartesi/state.json"]
3 changes: 3 additions & 0 deletions build/devnet/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
jq -r '.contracts | to_entries | .[] | "\(.value.address) \(.key)"' < /usr/share/cartesi/localhost.json
exec "$@"
4 changes: 4 additions & 0 deletions build/devnet/eth_isready
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

# https://ethereum.org/en/developers/docs/apis/json-rpc/#net_listening
curl -X POST -s -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"net_listening","params":[]}' ${RPC_URL:-http://127.0.0.1:8545} | jq '.result'
12 changes: 12 additions & 0 deletions build/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ target "rollups-node" {
target = "rollups-node"
context = ".."
}

target "machine" {
dockerfile = "./machine.Dockerfile"
target = "server-stage"
context = "."
}

target "devnet" {
dockerfile = "./devnet.Dockerfile"
target = "devnet"
context = "./devnet"
}
26 changes: 26 additions & 0 deletions devnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# Run Node Devnet infrastrucuture

## Run infrastructure with sample echo DApp

```
docker compose up
```

## Send input

```
INPUT=0x68656C6C6F206E6F6465 ;\
INPUT_BOX_ADDRESS=0x59b22D57D4f067708AB0c00552767405926dc768 ;\
DAPP_ADDRESS=0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C ;\
cast send $INPUT_BOX_ADDRESS "addInput(address,bytes)(bytes32)" $DAPP_ADDRESS $INPUT --mnemonic "test test test test test test test test test test test junk" --rpc-url "http://localhost:8545"
```

## query input

Access `http://localhost:4000/graphql` and execute query
```
query{
notices {edges{node{index,payload,input{payload}}}}
}
```
Loading

0 comments on commit 01ca3da

Please sign in to comment.