Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PR workflow #15

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/actions/bootstrap/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: "Test local bootstrap"

runs:
using: composite
steps:
- name: Setup
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Build
shell: bash
run: |
make geth
go run build/ci.go install -static ./cmd/bootnode

- name: Test
shell: bash
run: ./.github/scripts/bootstrap_test.sh
58 changes: 58 additions & 0 deletions .github/actions/cache/golang/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: "Restore cache Go build and mod files"
description: "Restore cache Go build and mod files"

inputs:
cache-key-suffix:
description: Suffix to append to the cache key
required: false
default: ${{ github.sha }}
refresh-go-cache:
description: Flag to control cache refresh
default: false
runs:
using: "composite"
steps:
- name: Restore Go mod (pkg)
if: ${{ inputs.refresh-go-cache != 'true' }}
uses: actions/cache/restore@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-gomod-

- name: Restore Go build (test)
if: ${{ inputs.refresh-go-cache != 'true' }}
uses: actions/cache/restore@v3
with:
path: |
~/.cache/go-build
key: ${{ runner.os }}-gobuild-${{ hashFiles('**/go.sum') }}-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-gobuild-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-gobuild-

- name: Cache Go mod (pkg)
if: ${{ inputs.refresh-go-cache == 'true' }}
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-gomod-

- name: Cache Go build (test)
if: ${{ inputs.refresh-go-cache == 'true' }}
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
key: ${{ runner.os }}-gobuild-${{ hashFiles('**/go.sum') }}-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-gobuild-${{ hashFiles('**/go.sum') }}
${{ runner.os }}-gobuild-
52 changes: 52 additions & 0 deletions .github/actions/cache/golangci-lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: "Cache golangci-lint"
description: "Cache golangci-lint and analysis cache"

inputs:
cache-key-suffix:
description: Suffix to append to the cache key
required: false
default: ${{ github.sha }}
golangci-lint-version:
description: Golangci-lint version to use
required: false
default: v1.51.1
refresh-analysis-cache:
description: Flag to control if golangci-lint analysis cache needs to be refreshed
default: false
runs:
using: "composite"
steps:
- name: Cache golangci-lint
uses: actions/cache@v3
id: cache-golangci-lint
with:
path: ~/go/bin/golangci-lint
key: ${{ runner.os }}-golangci-lint@${{ inputs.golangci-lint-version }}

- name: Install golangci-lint
if: steps.cache-golangci-lint.outputs.cache-hit != 'true'
shell: bash
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${{ inputs.golangci-lint-version }}

- name: Restore golangci-lint analysis cache
if: ${{ inputs.refresh-analysis-cache != 'true' }}
uses: actions/cache/restore@v3
with:
path: ~/.cache/golangci-lint
# This technique will make the cache key unique to the commit SHA,
# so that we can still hit cache using the restore-key and renew the cache using the key.
key: ${{ runner.os }}-golangci-lint-analysis-cache-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-golangci-lint-analysis-cache-

- name: Cache golangci-lint analysis cache
if: ${{ inputs.refresh-analysis-cache == 'true' }}
uses: actions/cache@v3
with:
path: ~/.cache/golangci-lint
# This technique will make the cache key unique to the commit SHA,
# so that we can still hit cache using the restore-key and renew the cache using the key.
key: ${{ runner.os }}-golangci-lint-analysis-cache-${{ inputs.cache-key-suffix }}
restore-keys: |
${{ runner.os }}-golangci-lint-analysis-cache-
19 changes: 19 additions & 0 deletions .github/actions/rewind/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: "Test chain rewind"

runs:
using: composite
steps:
- name: Setup
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Build
shell: bash
run: |
make geth

- name: Test
shell: bash
run: ./.github/scripts/rewind_test.sh
28 changes: 28 additions & 0 deletions .github/scripts/bootstrap_snap_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# This script can be used to start a local geth node from genesis against a specified
# network. For example, `./.github/scripts/dev.toml` is a config for connecting to devnet
# if you have port-forwarded to the p2p partner pod via `kubectl port-forward pod/zkevm-geth-partner-0 30300:30300`.

set -e
set -o pipefail

# Clean up subprocesses on exit
_exit() {
pkill geth || true
# sleep 5s to let it kill
sleep 5
}
trap _exit EXIT

# Set the env var to enable long range sync
export GETH_FLAG_IMMUTABLE_LONG_RANGE_SYNC="1"

./build/bin/geth immutable bootstrap local \
--env devnet \
--syncmode snap \
--gcmode full \
--config ./.github/scripts/dev.toml \
--boots "0" \
--rpcs "1" \
--validators "0"
108 changes: 108 additions & 0 deletions .github/scripts/bootstrap_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

# These tests bootstrap a local network and run tests through the eth JSON RPC.
# The network will undergo a number of hard forks between various test fixtures.
# The Prevrandao fork is intended to be <= Shanghai fork.

# TODO(serge): move these tests to a proper test suite implemented in Go
# when we know what the final test suite will look like.
# Features for test suite:
# * Set of fixtures that create transactions affected by all EVM-related hard forks
# * Fixtures can be run with expectation of success or failure depending on fork state

set -e
set -o pipefail

# necho prints a line without a newline
function necho() {
echo -n "> $*: "
}

# Clean up subprocesses on exit
_exit() {
pkill geth || true
# sleep 5s to let it kill
sleep 5
}
trap _exit EXIT

# Assign in case PWD changes
dir="$PWD"
log="/tmp/bootstrapout"
boots=2
validators=1
rpcs=2
# Set prevrandao override to be before shanghai
now=$(date +%s)
prevrandao_timestamp=$now
# Set shanghai override to be after genesis block and pre-shanghai tests
shanghai_timestamp=$((now+30))
# Set cancun override a few blocks after shanghai
cancun_timestamp=$((shanghai_timestamp+4))

export GETH_FLAG_NET_RESTRICT="0.0.0.0/0"
export GETH_FLAG_P2P_SUBNET="127.0.0.1/32"

function start_geth() {
necho "Starting geth"

# Bootstrap and run local network
./build/bin/geth immutable bootstrap local \
--boots "$boots" \
--rpcs "$rpcs" \
--validators "$validators" \
--blocklistfilepath "$dir/cmd/geth/testdata/acl_list.txt" \
--override.prevrandao="$prevrandao_timestamp" \
--override.shanghai="$shanghai_timestamp" \
--override.cancun="$cancun_timestamp" > "$log" 2>&1 &

# Wait for geth processes to start
while [ "$(pgrep geth | wc -l)" -lt "$((boots+rpcs+1))" ]; do
sleep 1
echo -n "."
done
echo ""
necho "To view geth logs run"
echo "tail -f $log"
sleep 2
}

function wait_shanghai() {
# Wait for shanghai timestamp
now=$(date +%s)
if [ "$now" -lt "$shanghai_timestamp" ]; then
diff=$((shanghai_timestamp-now+5))
necho "Waiting $diff seconds for shanghai timestamp"
sleep "$diff"
fi
echo ""
}

# Run geth
start_geth

# Need to use 0x44 opcode for Prevrandao fork.
echo "> Running post-prevrandao, pre-shanghai tests"
go test -count=1 -v ./tests/immutable \
-privkey="$dir/cmd/geth/testdata/key.prv" \
-rpc=http://localhost:8546 \
-validatoradmin=http://localhost:8545 \
-skipvoting=true \
-run='.*Randao.*'

# Wait for shanghai override
wait_shanghai

# Run tests
# Need to use contracts compiled with solc relevant to Shanghai fork.
echo "> Running post-fork tests"
go test -count=1 -v ./tests/immutable \
-privkey="$dir/cmd/geth/testdata/key.prv" \
-blockedprivkey="$dir/cmd/geth/testdata/blockedkey.prv" \
-rpc=http://localhost:8546 \
-validatoradmin=http://localhost:8545 \
-skipvoting=true

echo "> Running vote test" # Tests after this will fail due to stalled block production
./build/bin/geth immutable vote add --voters http://localhost:8545 --validator 0x7442eD1e3c9FD421F47d12A2742AfF5DaFBf43f8
echo "Tests finished successfully"
83 changes: 83 additions & 0 deletions .github/scripts/dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[Eth]
NetworkId = 15003
SyncMode = "full"
EthDiscoveryURLs = []
SnapDiscoveryURLs = []
NoPruning = true
NoPrefetch = false
TxLookupLimit = 2350000
TransactionHistory = 2350000
StateScheme = "hash"
DatabaseCache = 512
DatabaseFreezer = ""
TrieCleanCache = 256
TrieDirtyCache = 256
TrieTimeout = 3600000000000
SnapshotCache = 64
Preimages = false
FilterLogCacheSize = 32
EnablePreimageRecording = false
RPCGasCap = 50000000
RPCEVMTimeout = 5000000000
RPCTxFeeCap = 0e+00

[Eth.Miner]
GasFloor = 0
GasCeil = 30000000
GasPrice = 10000000000
Recommit = 999999999000000000
NewPayloadTimeout = 2000000000

[Eth.TxPool]
Locals = []
NoLocals = true
Journal = "transactions.rlp"
Rejournal = 3600000000000
PriceLimit = 10000000000
PriceBump = 10
AccountSlots = 16
GlobalSlots = 5120
AccountQueue = 64
GlobalQueue = 1024
Lifetime = 3600000000000

[Eth.BlobPool]
Datadir = "blobpool"
Datacap = 1
PriceBump = 100

[Eth.GPO]
Blocks = 120
Percentile = 60
MaxHeaderHistory = 1024
MaxBlockHistory = 1024
MaxPrice = 500000000000
IgnorePrice = 2

[Node]
DataDir = ""
IPCPath = "geth.ipc"
HTTPHost = ""
HTTPModules = []
WSHost = ""
WSModules = []
AllowUnprotectedTxs = true

[Node.P2P]
MaxPeers = 100
NoDiscovery = true
StaticNodes = [
"enode://56724a169266dedfbb41dc50a1f237f4b55569fadccce347c2bb25526c1357b6ff9450ce91c0f21a13abb02fa348ad9e928e8a4fee969a1f14a943c8f6409fb1@127.0.0.1:30300",
]
TrustedNodes = [
"enode://56724a169266dedfbb41dc50a1f237f4b55569fadccce347c2bb25526c1357b6ff9450ce91c0f21a13abb02fa348ad9e928e8a4fee969a1f14a943c8f6409fb1@127.0.0.1:30300",
]
ListenAddr = ""
DiscAddr = ""
EnableMsgEvents = false

[Node.HTTPTimeouts]
ReadTimeout = 0
ReadHeaderTimeout = 0
WriteTimeout = 0
IdleTimeout = 0
Loading