forked from Fantom-foundation/go-opera
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ pip3 install -r requirements.txt | |
> run the simulated network. Replace NUM_OF_NODES with the number of nodes you want to simulate. | ||
```shell | ||
# be in the docker/networksimulator directory | ||
cd docker/networksimulator | ||
|
||
# install deps | ||
pip3 install -r requirements.txt | ||
|
||
|
@@ -26,10 +29,63 @@ python3 generate.py 10 && docker compose up --build | |
|
||
Give it a few minutes for all the nodes to start up. | ||
|
||
> Test the RPC endpoint | ||
```shell | ||
curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' http://127.0.0.1:8545 | ||
``` | ||
|
||
Use the fakenet private keys from [../evmcore/apply_fake_genesis.go](../evmcore/apply_fake_genesis.go) to access the validator accounts and their funds | ||
|
||
See test.py for an example of how to interact with the network. | ||
|
||
## Lachesis Base | ||
|
||
This is a hacky way to include a custom Lachesis base inside the docker build context. | ||
|
||
> Rsync your lachesis base files into the `lachesis-base` directory inside go-x1. This will be copied into the docker build context. | ||
```shell | ||
rsync -rav --exclude .git ../lachesis-base/ lachesis-base/ | ||
``` | ||
|
||
> Update the go.mod file to point to the local lachesis-base directory | ||
```shell | ||
echo "replace github.com/Fantom-foundation/lachesis-base => ./lachesis-base" >> go.mod | ||
``` | ||
|
||
> Now build the docker image as usual | ||
```shell | ||
cd docker/networksimulator | ||
|
||
# Example: build and run a network of 10 nodes | ||
python3 generate.py 10 && docker compose up --build | ||
``` | ||
|
||
## Include a Custom SFC contract | ||
|
||
The custom SFC contract will be built and included in the genesis block of the simulated network. | ||
|
||
Note: The genesis will no longer be compatible with the testnet genesis. | ||
|
||
```shell | ||
# clone the sfc contract repo into the parent directory of go-x1 | ||
# so both repos are in the same directory | ||
cd ../../.. | ||
git clone [email protected]:nibty/x1-sfc.git | ||
|
||
cd x1-sfc | ||
# make any changes to the SFC contract here | ||
|
||
# run go generate ./... inside the go-x1 directory | ||
# This will build the SFC contract and generate the go bindings. | ||
# This requires Docker, takes a long time, and will not exit with ctrl-c, so be careful. | ||
cd ../go-x1 | ||
go generate ./... | ||
``` | ||
|
||
> Now build the docker image as usual | ||
```shell | ||
cd docker/networksimulator | ||
|
||
# Example: build and run a network of 10 nodes | ||
python3 generate.py 10 && docker compose up --build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
import jinja2 | ||
import ipaddress | ||
import sys | ||
import argparse | ||
|
||
ip_base = '172.16.239.0' | ||
starting_port = 6050 | ||
DEFAULT_IP_BASE = '172.16.239.0' | ||
DEFAULT_NUM_NODES = 3 | ||
DEFAULT_STARTING_PORT = 7050 | ||
DEFAULT_FLAGS = "--testnet --http --http.port 8545 --http.addr 0.0.0.0 --http.vhosts '*' --http.corsdomain '*' --ws --ws.addr 0.0.0.0 --ws.port 8546 --ws.origins '*' --verbosity 3 " | ||
BOOT_NODE_KEY = "4b20a091f6389ca9ee1492187cc2d775511fa1e0801bf1f787b3a14f961530b1" | ||
BOOT_NODE_PUB_KEY = "d06482f636e5c68586215f9ab9dfda270d38bf468195fc2e767d5d74b5fc7ab4faffc46028aa360b723ce53ded022949a8a6b1c96013d8ec1771f4ed448518b4" | ||
|
||
if len(sys.argv) > 1: | ||
num_nodes = int(sys.argv[1]) | ||
else: | ||
num_nodes = 3 | ||
|
||
argparser = argparse.ArgumentParser() | ||
argparser.add_argument(type=int, dest="num_nodes", default=DEFAULT_NUM_NODES) | ||
argparser.add_argument('--ip-base', type=str, default=DEFAULT_IP_BASE) | ||
argparser.add_argument('--flags', type=str, default=DEFAULT_FLAGS) | ||
argparser.add_argument('--starting-port', type=int, default=DEFAULT_STARTING_PORT) | ||
args = argparser.parse_args() | ||
|
||
environment = jinja2.Environment() | ||
environment.filters['ip_address'] = ipaddress.ip_address | ||
environment.loader = jinja2.FileSystemLoader('templates') | ||
template = environment.get_template('docker-compose.yaml.j2') | ||
|
||
template.stream({ | ||
"num_nodes": num_nodes, | ||
"ip_base": ip_base, | ||
"starting_port": starting_port, | ||
"num_nodes": args.num_nodes, | ||
"ip_base": args.ip_base, | ||
"starting_port": args.starting_port, | ||
"flags": args.flags, | ||
"bootnode_key": BOOT_NODE_KEY, | ||
"bootnode_pub_key": BOOT_NODE_PUB_KEY, | ||
}).dump('docker-compose.yaml') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters