Skip to content

Commit

Permalink
Merge pull request #407 from multiversx/localnet-sirius
Browse files Browse the repository at this point in the history
Update localnet to work with Sirius
  • Loading branch information
andreibancioiu committed Feb 1, 2024
2 parents 7d110d2 + 449ba22 commit b2b07a9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test-localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ jobs:
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_remote.toml --stop-after-seconds=120
if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
else
echo "The localnet failed to process blocks."
exit 1
fi
- name: Smoke test (with resolution == local)
run: |
mkdir -p ~/multiversx-sdk/sandbox
Expand All @@ -65,3 +72,10 @@ jobs:
python3 -m multiversx_sdk_cli.cli localnet clean --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet config --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml
python3 -m multiversx_sdk_cli.cli localnet start --configfile=./multiversx_sdk_cli/tests/testdata/localnet_with_resolution_local.toml --stop-after-seconds=120
if grep -r --include=\*.log "started committing block" ./localnet; then
echo "The localnet processed blocks successfully."
else
echo "The localnet failed to process blocks."
exit 1
fi
52 changes: 43 additions & 9 deletions multiversx_sdk_cli/localnet/step_build_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Dict, List

from multiversx_sdk_cli import dependencies, utils
from multiversx_sdk_cli import dependencies, utils, workstation
from multiversx_sdk_cli.errors import KnownError
from multiversx_sdk_cli.localnet import libraries
from multiversx_sdk_cli.localnet.config_root import ConfigRoot
Expand All @@ -22,18 +22,16 @@ def build(configfile: Path, software_components: List[str]):

cmd_node = config.software.mx_chain_go.get_cmd_node_folder()
_do_build(cmd_node, golang_env)

wasmer_path = golang.get_gopath() / "pkg" / "mod" / _get_wasm_vm_package(config) / "wasmer"
libraries.copy_libraries(wasmer_path, cmd_node)
_copy_wasmer_libs(config, cmd_node)
_set_rpath(cmd_node / "node")

if "seednode" in software_components:
logger.info("Building seednode...")

cmd_seednode = config.software.mx_chain_go.get_cmd_seednode_folder()
_do_build(cmd_seednode, golang_env)

wasmer_path = golang.get_gopath() / "pkg" / "mod" / _get_wasm_vm_package(config) / "wasmer"
libraries.copy_libraries(wasmer_path, cmd_seednode)
_copy_wasmer_libs(config, cmd_seednode)
_set_rpath(cmd_seednode / "seednode")

if "proxy" in software_components:
logger.info("Building proxy...")
Expand All @@ -48,9 +46,45 @@ def _do_build(cwd: Path, env: Dict[str, str]):
raise KnownError(f"error code = {return_code}, see output")


def _get_wasm_vm_package(config: ConfigRoot) -> str:
def _copy_wasmer_libs(config: ConfigRoot, destination: Path):
golang = dependencies.get_golang()
vm_go_folder_name = _get_chain_vm_go_folder_name(config)
vm_go_path = golang.get_gopath() / "pkg" / "mod" / vm_go_folder_name
wasmer_path = vm_go_path / "wasmer"
wasmer2_path = vm_go_path / "wasmer2"

libraries.copy_libraries(wasmer_path, destination)
libraries.copy_libraries(wasmer2_path, destination)


def _get_chain_vm_go_folder_name(config: ConfigRoot) -> str:
go_mod = config.software.mx_chain_go.get_path_within_source(Path("go.mod"))
lines = utils.read_lines(go_mod)
line = [line for line in lines if "github.com/multiversx/mx-chain-vm-v" in line][-1]
line = [line for line in lines if "github.com/multiversx/mx-chain-vm-go" in line][0]
parts = line.split()
return f"{parts[0]}@{parts[1]}"


def _set_rpath(cmd_path: Path):
"""
Set the rpath of the executable to the current directory, on a best-effort basis.
For other occurrences of this approach, see:
- https://github.com/multiversx/mx-chain-scenario-cli-go/blob/master/.github/workflows/on_release_attach_artifacts.yml
"""

if not workstation.is_osx():
# We're only patching the executable on macOS.
# For Linux, we're leveraging LD_LIBRARY_PATH to resolve the libraries.
return

try:
subprocess.check_call([
"install_name_tool",
"-add_rpath",
"@loader_path",
cmd_path
])
except Exception as e:
# In most cases, this isn't critical (libraries might be found among the downloaded Go packages).
logger.warning(f"Failed to set rpath of {cmd_path}: {e}")
2 changes: 1 addition & 1 deletion multiversx_sdk_cli/localnet/step_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async def run(args: List[str], cwd: Path, delay: int = 0):
if workstation.is_linux():
env["LD_LIBRARY_PATH"] = str(cwd)
else:
# For MacOS, libwasmer is directly found near the binary (no workaround needed)
# For MacOS, dylibs are directly found near the binary (no workaround needed)
pass

process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE,
Expand Down
4 changes: 4 additions & 0 deletions multiversx_sdk_cli/workstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def is_windows():
return get_platform() == "windows"


def is_osx():
return get_platform() == "osx"


def get_platform():
platforms = {
"linux": "linux",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.4.0"
version = "9.4.1"
authors = [
{ name="MultiversX" },
]
Expand Down

0 comments on commit b2b07a9

Please sign in to comment.