Skip to content

Commit

Permalink
feat: upgrade to avalanchego-v1.11.4
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderheijden86 committed May 9, 2024
1 parent 9d2e2b4 commit c7be9e5
Show file tree
Hide file tree
Showing 10 changed files with 637 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ yarn-error.log
# Bazel
/bazel-*

/static_files/subnet-evm
10 changes: 5 additions & 5 deletions args.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"dont_start_subnets": false,
"is_elastic": false,
"ephemeral_ports": true,
"avalanchego_image": "avaplatform/avalanchego:v1.10.1-Subnet-EVM-master",
"avalanchego_image": "avaplatform/avalanchego:v1.11.4",
"node_config": {
"network-id": "1337",
"staking-enabled": false,
"health-check-frequency": "5s"
},
"node_count": 5,
"num_validators": 5,
"node_count": 2,
"num_validators": 1,
"min_cpu": 0,
"min_memory": 0,
"vm_name": "testNet",
"chain_name": "testChain",
"custom_subnet_vm_path": "",
"custom_subnet_vm_path": "/uploaded_plugins/subnet-evm",
"custom_subnet_vm_url": "",
"subnet_genesis_json": "/static_files/genesis.json"
"subnet_genesis_json": "/static_files/genesis.json",
}
15 changes: 14 additions & 1 deletion main.star
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ def run(plan, args):
networkId = node_config["network-id"]
if not ephemeral_ports:
plan.print("Warning - Ephemeral ports have been disabled will be publishing first node rpc on 9650 and staking on 9651, this can break due to port clash!")

# initalize the builder service with the plan containing node config and the subnet genesis json
builder_service.init(plan, node_config, subnet_genesis_json)
# generate the genesis file
genesis, vmId = builder_service.genesis(plan, networkId ,node_count, vmName)
# launch the nodes
rpc_urls, public_rpc_urls, launch_commands = node_launcher.launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memory, vmId, dont_start_subnets, custom_subnet_vm_path, custom_subnet_vm_url)
# get the first private rpc url
first_private_rpc_url = rpc_urls[0]
if public_rpc_urls:
rpc_urls = public_rpc_urls
Expand All @@ -52,4 +57,12 @@ def run(plan, args):
output["elastic config"]["export id"] = exportId
output["elastic config"]["import id"] = importId
output["elastic config"]["token symbol"] = "FOO"
return output
# launch the awm relayer
p_chain_api_url = "{0}/ext/P".format(first_private_rpc_url)
info_api_url = "{0}/ext/info".format(first_private_rpc_url)
plan.print("p_chain_api_url: {0}\ninfo_api_url: {1}".format(p_chain_api_url, info_api_url))
source_blockchains = []
destination_blockchains = []
# node_launcher.launch_awm_relayer(plan, p_chain_api_url, info_api_url, source_blockchains, destination_blockchains)

return output
2 changes: 1 addition & 1 deletion src/builder.star
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
static_files = import_module("./static_files_locators.star")
utils = import_module("./utils.star")

GO_IMG = "golang:1.20.4"
GO_IMG = "golang:1.22.2"
ABS_PLUGIN_DIRPATH = "/avalanchego/build/plugins/"

BUILDER_SERVICE_NAME = "builder"
Expand Down
107 changes: 61 additions & 46 deletions src/node_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ STAKING_PORT_NUM = 9651
STAKING_PORT_ID = "staking"

EXECUTABLE_PATH = "avalanchego"
ABS_DATA_DIRPATH= "/tmp/data/"
ABS_DATA_DIRPATH = "/tmp/data/"
NODE_NAME_PREFIX = "node-"

NODE_ID_PATH = "/tmp/data/node-{0}/node_id.txt"
Expand All @@ -16,65 +16,72 @@ PUBLIC_IP = "127.0.0.1"

utils = import_module("./utils.star")

def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memory, vmId, dont_start_subnets, custom_subnet_vm_path, custom_subnet_vm_url):

def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memory, vmId, dont_start_subnets,
custom_subnet_vm_path, custom_subnet_vm_url):
bootstrap_ips = []
bootstrap_ids = []
nodes = []
launch_commands = []

services = {}
plan.print("Creating all the avalanche containers paralllely")
for index in range (0, node_count):
for index in range(0, node_count):
node_name = NODE_NAME_PREFIX + str(index)

node_data_dirpath = ABS_DATA_DIRPATH + node_name + "/"
node_data_dirpath = ABS_DATA_DIRPATH + node_name + "/"
node_config_filepath = node_data_dirpath + "config.json"

launch_node_cmd = [
"nohup",
"/avalanchego/build/" + EXECUTABLE_PATH,
"--genesis=/tmp/data/genesis.json",
"--genesis-file=/tmp/data/genesis.json",
"--data-dir=" + node_data_dirpath,
"--config-file=" + node_config_filepath,
"--http-host=0.0.0.0",
"--staking-port=" + str(STAKING_PORT_NUM),
"--http-port="+ str(RPC_PORT_NUM),
"--log-dir=/tmp/"
"--http-port=" + str(RPC_PORT_NUM),
"--log-dir=/tmp/",
"--network-health-min-conn-peers=" + str(node_count - 1),
]

plan.print("Creating node {0} with command {1}".format(node_name, launch_node_cmd))

public_ports = {}
if not ephemeral_ports:
public_ports["rpc"] = PortSpec(number = RPC_PORT_NUM+ index*2 , transport_protocol = "TCP", wait=None)
public_ports["staking"] = PortSpec(number = STAKING_PORT_NUM + index*2 , transport_protocol = "TCP", wait=None)
public_ports["rpc"] = PortSpec(number=RPC_PORT_NUM + index * 2, transport_protocol="TCP", wait=None)
public_ports["staking"] = PortSpec(number=STAKING_PORT_NUM + index * 2, transport_protocol="TCP", wait=None)

log_files = ["main.log", "C.log", "X.log", "P.log", "vm-factory.log"]
log_files_cmds = ["touch /tmp/{0}".format(log_file) for log_file in log_files]
log_file_cmd = " && ".join(log_files_cmds)

subnet_evm_plugin = plan.upload_files(
"../static_files/subnet-evm")

node_service_config = ServiceConfig(
image = image,
ports = {
"rpc": PortSpec(number = RPC_PORT_NUM, transport_protocol = "TCP", wait = None),
"staking": PortSpec(number = STAKING_PORT_NUM, transport_protocol = "TCP", wait = None)
},
entrypoint = ["/bin/sh", "-c", log_file_cmd + " && cd /tmp && tail -F *.log"],
files = {
entrypoint=["/bin/sh", "-c", log_file_cmd + " && cd /tmp && tail -F *.log"],
files={
"/tmp/data": genesis,
"/uploaded_plugins/": subnet_evm_plugin,
},
public_ports = public_ports,
min_cpu = min_cpu,
min_memory = min_memory,
public_ports=public_ports,
min_cpu=min_cpu,
min_memory=min_memory,
)

services[node_name] = node_service_config
launch_commands.append(launch_node_cmd)


nodes = plan.add_services(services)


for index in range(0, node_count):
node_name = NODE_NAME_PREFIX + str(index)
node_name = NODE_NAME_PREFIX + str(index)

node = nodes[node_name]
launch_node_cmd = launch_commands[index]
Expand All @@ -84,6 +91,12 @@ def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memor
launch_node_cmd.append("--bootstrap-ids={0}".format(",".join(bootstrap_ids)))

if not dont_start_subnets:
plan.exec(
service_name=node_name,
recipe=ExecRecipe(
command=["mkdir", "-p", ABS_PLUGIN_DIRPATH]
)
)
if custom_subnet_vm_path:
cp(plan, node_name, custom_subnet_vm_path, ABS_PLUGIN_DIRPATH + vmId)
elif custom_subnet_vm_url:
Expand All @@ -92,24 +105,24 @@ def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memor
copy_over_default_plugin(plan, node_name, vmId)

plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", " ".join(launch_node_cmd) + " >/dev/null 2>&1 &"],
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c", " ".join(launch_node_cmd) + " >/dev/null 2>&1 &"],
)
)
)

bootstrap_ips.append("{0}:{1}".format(node.ip_address, STAKING_PORT_NUM))
bootstrap_id_file = NODE_ID_PATH.format(index)
bootstrap_id = utils.read_file_from_service(plan, BUILDER_SERVICE_NAME, bootstrap_id_file)
bootstrap_ids.append(bootstrap_id)


wait_for_health(plan, "node-"+ str(node_count-1))
wait_for_health(plan, "node-" + str(node_count - 1))

rpc_urls = ["http://{0}:{1}".format(node.ip_address, RPC_PORT_NUM) for _, node in nodes.items()]
public_rpc_urls = []
if not ephemeral_ports:
public_rpc_urls = ["http://{0}:{1}".format(PUBLIC_IP, RPC_PORT_NUM + index*2) for index, node in enumerate(nodes)]
public_rpc_urls = ["http://{0}:{1}".format(PUBLIC_IP, RPC_PORT_NUM + index * 2) for index, node in
enumerate(nodes)]

return rpc_urls, public_rpc_urls, launch_commands

Expand All @@ -119,23 +132,24 @@ def restart_nodes(plan, num_nodes, launch_commands, subnetId, vmId):
node_name = NODE_NAME_PREFIX + str(index)
launch_command = launch_commands[index]
launch_command.append("--track-subnets={0}".format(subnetId))

# have no ps or pkill; so this is a work around
plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", """grep -l 'avalanchego' /proc/*/status | awk -F'/' '{print $3}' | while read -r pid; do kill -9 "$pid"; done"""]
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c",
"""grep -l 'avalanchego' /proc/*/status | awk -F'/' '{print $3}' | while read -r pid; do kill -9 "$pid"; done"""]
)
)

plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", " ".join(launch_command) + " >/dev/null 2>&1 &"],
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c", " ".join(launch_command) + " >/dev/null 2>&1 &"],
)
)

wait_for_health(plan, "node-"+ str(num_nodes-1))
wait_for_health(plan, "node-" + str(num_nodes - 1))


def wait_for_health(plan, node_name):
Expand All @@ -144,9 +158,9 @@ def wait_for_health(plan, node_name):
recipe=PostHttpRequestRecipe(
port_id=RPC_PORT_ID,
endpoint="/ext/health",
content_type = "application/json",
content_type="application/json",
body="{ \"jsonrpc\":\"2.0\", \"id\" :1, \"method\" :\"health.health\"}",
extract = {
extract={
"healthy": ".result.healthy",
}
),
Expand All @@ -159,9 +173,9 @@ def wait_for_health(plan, node_name):

def copy_over_default_plugin(plan, node_name, vmId):
filename_response = plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "ls {0} | tr -d '\n'".format(ABS_PLUGIN_DIRPATH)]
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c", "ls {0} | tr -d '\n'".format(ABS_PLUGIN_DIRPATH)]
)
)
default_plugin_name = filename_response["output"]
Expand All @@ -170,24 +184,25 @@ def copy_over_default_plugin(plan, node_name, vmId):

def cp(plan, node_name, src, dest):
plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["cp", src, dest]
service_name=node_name,
recipe=ExecRecipe(
command=["cp", src, dest]
)
)


def download_to_path(plan, node_name, url, dest):
plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "apt update --allow-insecure-repositories && apt-get install curl -y --allow-unauthenticated"]
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c",
"apt update --allow-insecure-repositories && apt-get install curl -y --allow-unauthenticated"]
)
)

plan.exec(
service_name = node_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "curl {0} -o {1}".format(url, dest)]
service_name=node_name,
recipe=ExecRecipe(
command=["/bin/sh", "-c", "curl {0} -o {1}".format(url, dest)]
)
)
6 changes: 3 additions & 3 deletions src/package_io/input_parser.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DEFAULT_AVALANCHEGO_IMAGE = "avaplatform/avalanchego:v1.10.1-Subnet-EVM-master"
DEFAULT_AVALANCHEGO_IMAGE = "avaplatform/avalanchego:v1.11.4"

def parse_input(input_args):
result = get_default_input_args()
Expand All @@ -15,7 +15,7 @@ def get_default_input_args():
"ephemeral_ports": True,
"avalanchego_image": DEFAULT_AVALANCHEGO_IMAGE,
"node_config": default_node_cfg,
"node_count": 5,
"node_count": 2,
# in milli cores 1000 millicores is 1 core
"min_cpu": 0,
# in megabytes
Expand All @@ -29,7 +29,7 @@ def get_default_input_args():

def get_default_node_cfg():
return {
"network-id": "1337",
"network-id": "local",
"staking-enabled": False,
"health-check-frequency": "5s",
}
Loading

0 comments on commit c7be9e5

Please sign in to comment.