Skip to content

Commit

Permalink
Merge pull request #26 from ava-labs/cleanup-scripts
Browse files Browse the repository at this point in the history
Cleanup ./scripts/run.sh
  • Loading branch information
patrick-ogrady authored Mar 2, 2022
2 parents 0f8a802 + 60e5de9 commit 505f039
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 30 deletions.
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,42 @@ and creates a `subnet-evm` genesis file.
```bash
# to startup a local cluster (good for development)
cd ${HOME}/go/src/github.com/ava-labs/subnet-evm
./scripts/run.sh 1.7.5
./scripts/run.sh 1.7.5 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
```

Once the the network is started up, the following info will be printed to the
console:
```bash
# inspect cluster endpoints when ready
cat /tmp/avalanchego-v1.7.5/output.yaml
<<COMMENT
endpoint: /ext/bc/2VCAhX6vE3UnXC6s1CBPE6jJ4c4cHWMfPgCptuWS59pQ9vbeLM
logsDir: ...
pid: 12811
uris:
- http://localhost:56239
- http://localhost:56251
- http://localhost:56253
- http://localhost:56255
- http://localhost:56257
COMMENT
Logs Directory: /var/folders/mp/6jm81gc11dv3xtcwxmrd8mcr0000gn/T/runnerlogs2402729383
PID: 90118

EVM Chain ID: 99999
Funded Address: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
RPC Endpoints:
- http://localhost:53423/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc
- http://localhost:53425/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc
- http://localhost:53427/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc
- http://localhost:53429/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc
- http://localhost:53431/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc

WS Endpoints:
- ws://localhost:53423/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/ws
- ws://localhost:53425/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/ws
- ws://localhost:53427/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/ws
- ws://localhost:53429/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/ws
- ws://localhost:53431/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/ws

MetaMask Quick Start:
Funded Address: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Network Name: Local EVM
RPC URL: http://localhost:53423/ext/bc/AHdWCyWDaudRX4JkHNgpzyMFdhHK7iEgB4HHMTuarzWghkAdg/rpc
Chain ID: 99999
Curreny Symbol: LEVM
```

# ping the local cluster
curl --location --request POST 'http://localhost:62045/ext/bc/x7gVMwHuGG4H1zXytxN8LRpShExiHnAiXG336EAhavpPmm8gF/rpc' \
You can then ping the local cluster or add the network to MetaMask:
```bash
curl --location --request POST 'http://localhost:61278/ext/bc/2Z36RnQuk1hvsnFeGWzfZUfXNr7w1SjzmDQ78YxfTVNAkDq3nZ/rpc' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
Expand All @@ -108,9 +124,11 @@ curl --location --request POST 'http://localhost:62045/ext/bc/x7gVMwHuGG4H1zXytx
"result": "0x0"
}
COMMENT
```

# to terminate the cluster
kill 12811
To terminate the cluster, kill the PID:
```bash
kill -2 55547
```

## Fuji Subnet Deployment
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -o pipefail

export GOGC=25

go test -p 2 -v -race -timeout="25m" -coverprofile="coverage.out" -covermode="atomic" ./...
go test -p 1 -v -race -timeout="25m" -coverprofile="coverage.out" -covermode="atomic" ./...
14 changes: 14 additions & 0 deletions scripts/parser/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/ava-labs/subnet-evm/scripts/parser

go 1.17

require (
github.com/fatih/color v1.13.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
15 changes: 15 additions & 0 deletions scripts/parser/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
76 changes: 76 additions & 0 deletions scripts/parser/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// (c) 2022 Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package main

import (
"io/ioutil"
"os"
"strings"

"github.com/fatih/color"
"gopkg.in/yaml.v2"
)

/*
===Example File===
endpoint: /ext/bc/2Z36RnQuk1hvsnFeGWzfZUfXNr7w1SjzmDQ78YxfTVNAkDq3nZ
logsDir: /var/folders/mp/6jm81gc11dv3xtcwxmrd8mcr0000gn/T/runnerlogs2984620995
pid: 55547
uris:
- http://localhost:61278
- http://localhost:61280
- http://localhost:61282
- http://localhost:61284
- http://localhost:61286
*/

type output struct {
Endpoint string `yaml:"endpoint"`
Logs string `yaml:"logsDir"`
PID int `yaml:"pid"`
URIs []string `yaml:"uris"`
}

func main() {
if len(os.Args) != 4 {
panic("missing args <yaml> <chainID> <address>")
}

yamlFile, err := ioutil.ReadFile(os.Args[1])
if err != nil {
panic(err)
}
var o output
if err := yaml.Unmarshal(yamlFile, &o); err != nil {
panic(err)
}

color.Green("\n")
color.Green("Logs Directory: %s", o.Logs)
color.Green("PID: %d", o.PID)
color.Green("\n")

color.Green("EVM Chain ID: %s", os.Args[2])
color.Green("Funded Address: %s", os.Args[3])
color.Green("RPC Endpoints:")
for _, uri := range o.URIs {
color.Green("- %s%s/rpc", uri, o.Endpoint)
}
color.Green("\n")

color.Green("WS Endpoints:")
for _, uri := range o.URIs {
wsURI := strings.ReplaceAll(uri, "http", "ws")
color.Green("- %s%s/ws", wsURI, o.Endpoint)
}
color.Green("\n")

color.Yellow("MetaMask Quick Start:")
color.Yellow("Funded Address: %s", os.Args[3])
color.Yellow("Network Name: Local EVM")
color.Yellow("RPC URL: %s%s/rpc", o.URIs[0], o.Endpoint)
color.Yellow("Chain ID: %s", os.Args[2])
color.Yellow("Curreny Symbol: LEVM")
}
75 changes: 64 additions & 11 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ source "$SUBNET_EVM_PATH"/scripts/constants.sh
VERSION=$1
if [[ -z "${VERSION}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION]" >> /dev/stderr
echo "Usage: ${0} [VERSION] [GENESIS_ADDRESS]" >> /dev/stderr
exit 255
fi

GENESIS_ADDRESS=$2
if [ -z "${GENESIS_ADDRESS}" ]; then
echo "Missing address argument!"
echo "Usage: ${0} [VERSION] [GENESIS_ADDRESS]" >> /dev/stderr
exit 255
fi

Expand Down Expand Up @@ -61,11 +68,14 @@ go build \
"plugin/"*.go
find /tmp/avalanchego-v${VERSION}

# Create genesis file to use in network (make sure to add your address to
# "alloc")
export CHAIN_ID=99999
echo "creating genesis"
cat <<EOF > /tmp/genesis.json
{
"config": {
"chainId": 99999,
"chainId": $CHAIN_ID,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
Expand All @@ -88,10 +98,8 @@ cat <<EOF > /tmp/genesis.json
"blockGasCostStep": 500000
}
},
"airdropHash":"0xccbf8e430b30d08b5b3342208781c40b373d1b5885c1903828f367230a2568da",
"airdropAmount":"0x8AC7230489E80000",
"alloc": {
"D23cbfA7eA985213aD81223309f588A7E66A246A": {
"${GENESIS_ADDRESS:2}": {
"balance": "0x52B7D2DCC80CD2E4000000"
}
},
Expand All @@ -108,6 +116,53 @@ cat <<EOF > /tmp/genesis.json
}
EOF

# If you'd like to try the airdrop feature, use the commented genesis
# cat <<EOF > /tmp/genesis.json
# {
# "config": {
# "chainId": $CHAIN_ID,
# "homesteadBlock": 0,
# "eip150Block": 0,
# "eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
# "eip155Block": 0,
# "eip158Block": 0,
# "byzantiumBlock": 0,
# "constantinopleBlock": 0,
# "petersburgBlock": 0,
# "istanbulBlock": 0,
# "muirGlacierBlock": 0,
# "subnetEVMTimestamp": 0,
# "feeConfig": {
# "gasLimit": 20000000,
# "minBaseFee": 1000000000,
# "targetGas": 100000000,
# "baseFeeChangeDenominator": 48,
# "minBlockGasCost": 0,
# "maxBlockGasCost": 10000000,
# "targetBlockRate": 2,
# "blockGasCostStep": 500000
# }
# },
# "airdropHash":"0xccbf8e430b30d08b5b3342208781c40b373d1b5885c1903828f367230a2568da",
# "airdropAmount":"0x8AC7230489E80000",
# "alloc": {
# "${GENESIS_ADDRESS:2}": {
# "balance": "0x52B7D2DCC80CD2E4000000"
# }
# },
# "nonce": "0x0",
# "timestamp": "0x0",
# "extraData": "0x00",
# "gasLimit": "0x1312D00",
# "difficulty": "0x0",
# "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
# "coinbase": "0x0000000000000000000000000000000000000000",
# "number": "0x0",
# "gasUsed": "0x0",
# "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
# }
# EOF

echo "building runner"
pushd ./runner
go build -v -o /tmp/runner .
Expand All @@ -121,19 +176,17 @@ echo "launch local test cluster in the background"
--output-path=/tmp/avalanchego-v${VERSION}/output.yaml 2> /dev/null &
PID=${!}

echo "wait until local cluster is ready from PID ${PID}"
sleep 360
while [[ ! -s /tmp/avalanchego-v${VERSION}/output.yaml ]]
do
echo "waiting for /tmp/avalanchego-v${VERSION}/output.yaml creation"
sleep 30
while [[ ! -s /tmp/avalanchego-v${VERSION}/output.yaml ]]; do
echo "waiting for local cluster on PID ${PID}"
sleep 5
# wait up to 5-minute
((c++)) && ((c==60)) && break
done

if [[ -f "/tmp/avalanchego-v${VERSION}/output.yaml" ]]; then
echo "cluster is ready!"
cat /tmp/avalanchego-v${VERSION}/output.yaml
go run scripts/parser/main.go /tmp/avalanchego-v${VERSION}/output.yaml $CHAIN_ID $GENESIS_ADDRESS
else
echo "cluster is not ready in time... terminating ${PID}"
kill ${PID}
Expand Down

0 comments on commit 505f039

Please sign in to comment.