Skip to content

Commit

Permalink
Arb deployment fixes (#494)
Browse files Browse the repository at this point in the history
* chore: add raw deployment script & CI

* chore: lint

* chore: store state before contract deployment 🧪

* chore: stop containers not using compose

* chore: add funding for extra address

* fix: permissions

* chore: renew docker login

* chore: add arb_init.ts

* fix: fon't stop arb

* chore: idempotent contract deployment

* chore: stop containers before saving state

* chore: don't deploy contracts 🤦‍♂️

* chore: add `arbitrum-gizmo-shop` docker image 🩻🐳

* fix: set agg key

* fix: add arbitry aggkey for L2 contracts 💀

* fix: wrong working directory

* chore: better logs from arb_init script

---------

Co-authored-by: Assem Hasna <[email protected]>
  • Loading branch information
albert-llimos and ahasna authored Feb 22, 2024
1 parent faaedad commit 19fde2b
Show file tree
Hide file tree
Showing 8 changed files with 3,108 additions and 41 deletions.
165 changes: 125 additions & 40 deletions .github/workflows/create-geth-arb-network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ on:
required: false
default: ""

permissions:
contents: read
packages: write

env:
SEED: test test test test test test test test test test test junk
NUM_GENESIS_VALIDATORS: ${{ inputs.genesis_validators }}
Expand All @@ -35,6 +39,7 @@ env:
GENESIS_STAKE: "1000000000000000000000"
DEPLOYER_ACCOUNT_INDEX: "0"
DEPLOY_ARTEFACT_ID: "docker"
DEPLOY_RAW_TX_ID: "arbRawDeploymentTxs"
IMAGE_TAG: ${{ inputs.tag }}-${{ inputs.genesis_validators }}-node${{ inputs.docker_image_tag_suffix }}

jobs:
Expand Down Expand Up @@ -237,28 +242,7 @@ jobs:
./test-node.bash --init --detach
./test-node.bash script send-l2 --to address_0x076d3803349fd5FB48863c5Fc33483cB2243C0Df --ethamount 10000
./test-node.bash script send-l2 --to address_0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --ethamount 10000
- name: Install Python virtualenv
run: pip install virtualenv

- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: "16"

- name: Install Poetry
uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b

- run: npm install --global ganache-cli
- run: npm install --global yarn
- run: yarn
- run: poetry install

- name: Add the network
run: poetry run brownie networks add Ethereum arb-l2 host=http://localhost:8547 chainid=412346

- name: Deploy contracts
run: poetry run brownie run deploy_contracts --network arb-l2
./test-node.bash script send-l2 --to address_0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --ethamount 10000
- name: Stop Containers
run: |
Expand All @@ -272,26 +256,12 @@ jobs:
# Stop any other containers that may be running
docker stop $(docker ps -a -q)
- name: Summary
run: |
CONTRACTS=$(jq . ./scripts/.artefacts/docker.json)
echo "## Deployed L2 Contracts for \`${{ inputs.genesis_validators }}-node\`" >> $GITHUB_STEP_SUMMARY
echo "\`agg_key\` = \`${{ env.AGG_KEY }}\`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
echo "$CONTRACTS" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## Docker Image" >> $GITHUB_STEP_SUMMARY
echo "\`ghcr.io/chainflip-io/chainflip-eth-contracts/geth:${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
- name: Save agg key to file
run: echo ${{ env.AGG_KEY }} > agg_key

- name: Update permissions
run: |
sudo chown -R $USER:$USER ./nitro-testnode/data
sudo chmod -R 777 ./nitro-testnode/data
- name: Save artifacts
- name: Save Initial State Artifacts
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
with:
name: ${{ env.IMAGE_TAG }}-localnet-initial-state
Expand All @@ -312,9 +282,6 @@ jobs:
needs:
- build-arb-state
runs-on: [self-hosted, linux, x64, ephemeral]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
Expand Down Expand Up @@ -370,3 +337,121 @@ jobs:
BUILD_DATETIME="${{ steps.get_time.outputs.current_datetime }}"
VCS_REF="${{ github.sha }}"
BACKEND_REF="${{ inputs.chainflip_backend_ref }}"
get-l2-contracts-raw-tx:
env:
AGG_KEY: "346529871269487315764593845752985329862751012"
needs:
- build-initial-state-container
runs-on: [self-hosted, linux, x64, ephemeral]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Set up QEMU ⚙️
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3

- name: Set up Docker Buildx 👷
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
with:
driver-opts: |
image=moby/buildkit:v0.10.6
- name: Docker meta 🔖
id: meta
uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4
with:
images: ghcr.io/${{ github.repository }}/arbitrum-gizmo-shop
tags: ${{ env.IMAGE_TAG }}

- name: Login to GitHub Container Registry ➡️🦑
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Update Docker user 🐳
run: |
sudo usermod -aG docker $USER
newgrp docker
- name: Start Arb Network 🚀
run: |
docker compose pull > /dev/null 2>&1
docker compose up init -d
docker compose up -d
- name: Install Python virtualenv
run: pip install virtualenv

- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: "16"

- name: Install Poetry
uses: snok/install-poetry@93ada01c735cc8a383ce0ce2ae205a21c415379b

- run: npm install --global ganache-cli
- run: npm install --global yarn
- run: yarn
- run: poetry install

- name: Add the network
run: poetry run brownie networks add Ethereum arb-l2 host=http://localhost:8547 chainid=412346

- name: Deploy contracts
run: poetry run brownie run deploy_contracts --network arb-l2

- name: Get raw deployment transactions
run: poetry run brownie run store_raw_deployment_txs --network arb-l2

- name: Summary
run: |
CONTRACTS=$(jq . ./scripts/.artefacts/docker.json)
echo "## Deployed L2 Contracts for \`${{ inputs.genesis_validators }}-node\`" >> $GITHUB_STEP_SUMMARY
echo "\`agg_key\` = \`${{ env.AGG_KEY }}\`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
echo "$CONTRACTS" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "## Docker Image" >> $GITHUB_STEP_SUMMARY
echo "\`ghcr.io/chainflip-io/chainflip-eth-contracts/geth:${{ env.IMAGE_TAG }}\`" >> $GITHUB_STEP_SUMMARY
- name: Save agg key to file
run: echo ${{ env.AGG_KEY }} > agg_key

- name: Save ARB Raw Deployment Txs Artifacts
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
with:
name: Arbitrum raw deployment transactions
path: |
./scripts/.artefacts/arbRawDeploymentTxs.json
- name: Get Current Time ⌚️
id: get_time
run: echo "current_datetime=$(date -u +"%b %d, %Y at %R UTC")" >> $GITHUB_OUTPUT

- name: Build Arbitrum Gizmo Shop Image 🪀
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
with:
context: .
file: ci/docker/arbitrum-gizmo-shop.Dockerfile
push: true
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_DATETIME="${{ steps.get_time.outputs.current_datetime }}"
VCS_REF="${{ github.sha }}"
BACKEND_REF="${{ inputs.chainflip_backend_ref }}"
- name: Clean Up docker containers 🧹
if: always()
continue-on-error: true
run: |
docker ps -a
docker compose logs
docker compose down --rmi all --volumes --remove-orphans
77 changes: 77 additions & 0 deletions arb-utils/arb_init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env -S pnpm tsx
// INSTRUCTIONS
//
// This command takes no arguments.
// It will perform the initial arbitrum contract deployment according to the `arbRawDeploymentTxs.json` file
// and will send a transaction every ~260ms to mimic the Arbitrum mainnet block production.

import fs from 'fs/promises';
import Web3 from 'web3';
import { setTimeout as sleep } from 'timers/promises';

async function main(): Promise<void> {
let rawTxsFile =
process.env.ARB_RAW_TXS_FILE ?? "../scripts/.artefacts/arbRawDeploymentTxs.json";
const web3 = new Web3(process.env.ARB_ENDPOINT ?? 'http://127.0.0.1:8547');
const usdcArbitrumAddress = '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9';

const bytecode = await web3.eth.getCode(usdcArbitrumAddress);

if (bytecode === '0x') {
const abi = await fs.readFile(rawTxsFile, "utf-8");
const arbRawTxs: JSON = JSON.parse(abi);

// Loop through each raw transaction data
for (const arbRawTx of Object.values(arbRawTxs)) {
const txHash = await web3.eth.sendSignedTransaction(arbRawTx, (error) => {
if (error) {
console.log(`❌ Arbitrum transaction failure:`, error);
}
});
console.log(`💌 Transaction sent with hash: ${txHash.transactionHash}`);
}

console.log("=== 🪂 Arbitrum contracts deployed successfully ===");
} else {
console.log(`=== Contracts already deployed ===`);
}

console.log("=== 🧶 Start spamming ===");

const whaleKey = '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d';
const whaleAddress = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8';

// NOTE: The naive approach to just have a nonce increment every time seems to work fine
let nonce = await web3.eth.getTransactionCount(whaleAddress);
let livelinessLogCounter = 0;
let spammingTxCounter = 0;
while (true) {
const tx = { to: whaleAddress, data: undefined, gas: 5000000, nonce, value: 1 };

const signedTx = await web3.eth.accounts.signTransaction(tx, whaleKey);

await web3.eth.sendSignedTransaction(
signedTx.rawTransaction as string,
(error) => {
if (error) {
console.error(`Arbitrum transaction failure:`, error);
}
},
);
nonce++;
spammingTxCounter++;
livelinessLogCounter++;
if (livelinessLogCounter === 120) { // 120 * 250ms = 30s
console.log(
`💌 Total Number of Spamming TXs sent: ${livelinessLogCounter}`
);
livelinessLogCounter = 0;
}
await sleep(250);
}
}

main().catch((error) => {
console.error(error);
process.exit(-1);
});
16 changes: 16 additions & 0 deletions arb-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "scripts",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"tsx": "^4.7.1",
"web3": "^1.9.0"
}
}
Loading

0 comments on commit 19fde2b

Please sign in to comment.