-
Notifications
You must be signed in to change notification settings - Fork 0
A local environment in OpenBSD adJ 7.4 for Avalanche
The course Customizing the EVM
available in March 2024 in Avalanche Academy at https://academy.avax.network/course/customize-evm has one section entitled Local Development Environment Setup
with instructions for Mac and Linux (see https://academy.avax.network/path-player?courseid=customize-evm&unit=64acc28c58ec49ae3f0c40f0Unit ). We were able to port to OpenBSD/adJ 7.4 the tools required for that course and to adapt the instructions.
In this article we list the tools ported and their requirements, present instructions to setup a local environment in OpenBSD/adJ 7.4 and add some notes about using these tools for the course.
The main idea for the porting was summarized in this Pull Request. Besides that we just replicated versions, improved shebangs of some bash scripts and replaced modules with the ported ones in the file go.mod
.
The ported tools necessary for this course were:
Repository | Tagged version in original repository | Branch in forked repository | Notes | PRs |
---|---|---|---|---|
supranational/blst | v0.3.11 |
master in original repository with fix proposed by author of blst
|
Withouth the fix in most cpus (except Ryzen 5) blst produced segmentation faults in OpenBSD/adJ see the issue we opened
|
Commit 1 and commit 2 proposed by author of blst
|
cockroachdb/pebble | 829675f94811 | ava1.11.0.adJ74 | Backported OpenBSD support from v1.1.0 | |
ava-labs/avalanchego | v1.11.1 | v1.11.1adJ74 | Added storage support fo OpenBSD/adJ | 2809 |
ava-labs/avalanchego | v1.11.0 | v1.11.0adJ74 | see previous | |
ava-labs/avalanchego | v1.10.11 | v1.10.11adJ74 | see previous | |
ava-labs/coreth | v0.13.0-rc.0 | v0.13.0rc.0adJ74 | 510 | |
ava-labs/coreth | v0.12.5-rc.6 | v0.12.5adJ74 | see previous | |
ava-labs/avalanche-network-runner | v1.7.6 | v1.7.6adJ74 | 707 | |
ava-labs/avalanche-network-runner | v1.7.2 | v1.7.2adJ74 | See previous | |
ava-labs/subnet-evm | v0.5.6 | v0.5.6adJ74 | 1119 | |
ava-labs/subnet-evm | v0.6.0-fuji | v0.6.0fujiadJ74 | See previous | |
ava-labs/precompile-evm | avalanche-academy-start | avalancheacademystartadJ74 | ||
ava-labs/avalanche-cli | v1.4.1 | v1.4.1adJ74 |
scripts/build.sh requires ulimit -d 4000000
|
1539 |
adJ 7.4 already comes with the following tools:
- node 18.18.0
- vim 9.0.1897 instead of VSCode
We will follow the same order of presentation of the mentioned course but skipping the sections about node and VScode.
OpenBSD/adJ 7.4 by default has go v.1.21 but for avalanche it was better 1.22, we prepared a package (not signed) installable with:
doas pkg_add -D unsigned http://adJ.pasosdeJesus.org/pub/AprendiendoDeJesus/7.4-extra/go-1.22.0p0.tgz
Since we recommend zsh
with some configuration scripts (see https://gitlab.com/pasosdeJesus/adJ/-/tree/main/arboldd/usr/local/share/adJ/archconf?ref_type=heads), we added the following lines to ~/.zshrc
:
export GOPATH=$(go env GOPATH)
export PATH="${PATH}:${HOME}/bin:${GOPATH}/bin"
export AVALANCHEGO_EXEC_PATH="${GOPATH}/src/github.com/ava-labs/avalanchego/build/avalanchego"
export AVALANCHEGO_PLUGIN_PATH="${GOPATH}/src/github.com/ava-labs/avalanchego/build/plugins"
Restart the terminal or run
. ~/.zshrc
Since there are not binaries for OpenBSD/adJ, we have to build them with the following procedure:
mkdir -p ~/comp/go
cd ~/comp/go
git clone -b v1.7.6adJ74 [email protected]:vtamara/avalanche-network-runner
cd avalanche-network-runner
./scripts/build.sh
This will produce ./bin/avalanche-network-runner
that you can test and install in ~/bin
with:
./bin/avalanche-network-runner --help
mkdir -p ~/bin/
cp bin/avalanche-network-runner ~/bin
mkdir ~/go
git clone -bv1.10.11adJ74 https://github.com/ava-labs/avalanchego.git $GOPATH/src/github.com/ava-labs/avalanchego
cd $GOPATH/src/github.com/ava-labs/avalanchego
./scripts/build.sh
./build/avalanchego --help
Install yarn with
doas npm install -g yarn
Fork the repository https://github.com/vtamara/precompile-evm
git clone <Link_to_your_fork> $GOPATH/src/github.com/ava-labs/precompile-evm
cd $GOPATH/src/github.com/ava-labs/precompile-evm
git checkout avalancheacademystartadJ74
cd contracts
yarn install
cd ..
./scripts/build.sh
Check the file produced with:
ls $GOPATH/src/github.com/ava-labs/avalanchego/build/plugins/
You can try the binary with the option -v
, something like:
% $GOPATH/src/github.com/ava-labs/avalanchego/build/plugins/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy --version
Precompile-EVM/v0.1.4 Subnet-EVM/v0.5.6 [AvalancheGo=v1.10.11, rpcchainvm=28]
If running the generated plugin produces an error like:
failed to set fd limit correctly due to: error fd-limit: (32768) greater than max: (15000)
Edit /etc/sysctl.conf
to increase hard limit of file descriptors:
kern.maxfiles=32768
After that restart or run doas sysctl -w kern.maxfiles=32768
Then edit /etc/login.conf
and increase in the class staff
(or in the one you use) the limit of files descriptors:
:openfiles-max=32768:\
Then run
doas cap_mkdb /etc/login.conf
Finally restart your session (ssh if it is remote or window manager if it is local) and run:
ulimit -n 32768
It took a long time for me to realize that the exercises of the course need to be donde from the directory $GOPATH/src/github.com/ava-labs/precompile-evm
start with:
cd $GOPATH/src/github.com/ava-labs/precompile-evm
From that directory the most used command is to start the server ANR:
avalanche-network-runner server \
--log-level debug \
--port=":8080" \
--grpc-gateway-port=":8081"
From a different terminal and from the same directory it is possible to start a new subnet using a genesis block located for example at
./.devcontainer/genesis-example.json
with:
avalanche-network-runner control start \
--log-level debug \
--endpoint="0.0.0.0:8080" \
--number-of-nodes=5 \
--blockchain-specs '[{"vm_name": "subnetevm", "genesis": "./.devcontainer/genesis-example.json"}]'
And to check the RPC ports with:
avalanche-network-runner control list-rpcs
The steps to create a precompile
-
Create a solidity interface with you editor in
contracts/contracts/interfaces/
-
Generate the ABI for the interface and rename it (let's say
ICounter.sol
) withcd contracts npx solc@latest --abi ./contracts/interfaces/ICounter.sol -o ./abis --base-path . --include-path ./node_modules mv ./abis/contracts_interfaces_ICounter_sol_ICounter.abi ./abis/ICounter.abi
The ABI will be a JSON file at
./contracts/abis/ICounter.abi
-
Generate the template of the source code of the precompile with:
./scripts/generate_precompile.sh --abi ./contracts/abis/ICounter.abi --type Counter --pkg counter --out ./counter
The initial files will be:
File | Contents |
---|---|
README.md |
Instructions |
config.go |
Configuration of the precompile during its first activation and custom verifications |
config_test.go |
Tests to configuration |
contract.abi |
Copy of ./contracts/abis/ICounter.abi
|
contract.go |
Implement here the functionality of the precompiled contract |
contract_test.go |
Tests to contract.go
|
module.go |
ConfigKey and the address where the contract will be |
I was able to use Metamask (and Brave wallet) to do exercises of this course. I prefer Metamaks over Core because:
- The soures of Core are closed while Metamask sources are open
- Core requires WASM and running it some time ago, I experienced that it was requiring a lot of CPU while I was not using it.
To use https://remix.ethereum.org it is better to use firefox with its extension for Metamask since remix uses WASM (In OpenBSD/adJ WASM is disable by default in chrome, it is possible to enable it with ENABLE_WASM=1 chrome --enable-wasm
but in my case some gaphics and icons of webpages are not presented after enabling WASM).
To support the porting and the creation of content like this please donate to my AVAX address: 0x2e2c4ac19c93d0984840cdd8e7f77500e2ef978e