diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c3ac64..b605149 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,11 +2,10 @@ name: Build/Test/Release on: [push] env: EMULATOR_REPOSITORY: cartesi/machine-emulator - EMULATOR_TAG: 0.15.3 - ROM_VERSION: v0.17.0 - KERNEL_VERSION: v0.17.0 - LINUX_VERSION: 5.15.63-ctsi-2-v0.17.0 - ROOTFS_VERSION: v0.18.0 + EMULATOR_TAG: 0.16.0 + KERNEL_VERSION: v0.19.1 + LINUX_VERSION: 6.5.9-ctsi-1-v0.19.1 + TOOLS_VERSION: v0.14.0 CARTESI_IMAGES_PATH: /usr/share/cartesi-machine/images HOST_IMAGES_PATH: /tmp/cartesi-machine-images/ permissions: @@ -19,18 +18,18 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout server-manager source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -69,25 +68,25 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout server-manager source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Depot CLI uses: depot/setup-action@v1 @@ -130,9 +129,9 @@ jobs: - name: Download [rootfs.ext2] uses: Legion2/download-release-action@v2.1.0 with: - repository: ${{ github.repository_owner }}/image-rootfs - tag: ${{ env.ROOTFS_VERSION }} - file: rootfs-${{ env.ROOTFS_VERSION }}.ext2 + repository: ${{ github.repository_owner }}/machine-emulator-tools + tag: ${{ env.TOOLS_VERSION }} + file: rootfs-tools-${{ env.TOOLS_VERSION }}.ext2 - name: Download [kernel.bin] uses: Legion2/download-release-action@v2.1.0 @@ -141,20 +140,12 @@ jobs: tag: ${{ env.KERNEL_VERSION }} file: linux-${{ env.LINUX_VERSION }}.bin - - name: Download [rom.bin] - uses: Legion2/download-release-action@v2.1.0 - with: - repository: ${{ github.repository_owner }}/machine-emulator-rom - tag: ${{ env.ROM_VERSION }} - file: rom-${{ env.ROM_VERSION }}.bin - - name: Move images to cartesi images folder run: | mkdir -m 755 -p /tmp/cartesi-machine-images - mv rom-*.bin linux-*.bin rootfs-*.ext2 ${{ env.HOST_IMAGES_PATH }} + mv linux-*.bin rootfs-*.ext2 ${{ env.HOST_IMAGES_PATH }} cd ${{ env.HOST_IMAGES_PATH }} && ln -s linux-${{ env.LINUX_VERSION }}.bin linux.bin - cd ${{ env.HOST_IMAGES_PATH }} && ln -s rom-${{ env.ROM_VERSION }}.bin rom.bin - cd ${{ env.HOST_IMAGES_PATH }} && ln -s rootfs-${{ env.ROOTFS_VERSION }}.ext2 rootfs.ext2 + cd ${{ env.HOST_IMAGES_PATH }} && ln -s rootfs-tools-${{ env.TOOLS_VERSION }}.ext2 rootfs.ext2 - name: Run test suite inside the docker image (Linux/${{ matrix.arch }}) run: | @@ -180,25 +171,25 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout server-manager source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Depot CLI uses: depot/setup-action@v1 @@ -241,9 +232,9 @@ jobs: - name: Download [rootfs.ext2] uses: Legion2/download-release-action@v2.1.0 with: - repository: ${{ github.repository_owner }}/image-rootfs - tag: ${{ env.ROOTFS_VERSION }} - file: rootfs-${{ env.ROOTFS_VERSION }}.ext2 + repository: ${{ github.repository_owner }}/machine-emulator-tools + tag: ${{ env.TOOLS_VERSION }} + file: rootfs-tools-${{ env.TOOLS_VERSION }}.ext2 - name: Download [kernel.bin] uses: Legion2/download-release-action@v2.1.0 @@ -252,20 +243,12 @@ jobs: tag: ${{ env.KERNEL_VERSION }} file: linux-${{ env.LINUX_VERSION }}.bin - - name: Download [rom.bin] - uses: Legion2/download-release-action@v2.1.0 - with: - repository: ${{ github.repository_owner }}/machine-emulator-rom - tag: ${{ env.ROM_VERSION }} - file: rom-${{ env.ROM_VERSION }}.bin - - name: Move images to cartesi images folder run: | mkdir -m 755 -p /tmp/cartesi-machine-images - mv rom-*.bin linux-*.bin rootfs-*.ext2 ${{ env.HOST_IMAGES_PATH }} + mv linux-*.bin rootfs-*.ext2 ${{ env.HOST_IMAGES_PATH }} cd ${{ env.HOST_IMAGES_PATH }} && ln -s linux-${{ env.LINUX_VERSION }}.bin linux.bin - cd ${{ env.HOST_IMAGES_PATH }} && ln -s rom-${{ env.ROM_VERSION }}.bin rom.bin - cd ${{ env.HOST_IMAGES_PATH }} && ln -s rootfs-${{ env.ROOTFS_VERSION }}.ext2 rootfs.ext2 + cd ${{ env.HOST_IMAGES_PATH }} && ln -s rootfs-tools-${{ env.TOOLS_VERSION }}.ext2 rootfs.ext2 - name: Run test suite inside the docker image (Linux/${{ matrix.arch }}) run: | @@ -285,18 +268,18 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout server-manager source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -335,7 +318,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout server-manager source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive @@ -351,13 +334,13 @@ jobs: type=semver,pattern={{version}},enable=${{startsWith(github.ref, 'refs/tags/v')}} - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} diff --git a/.github/workflows/commits.yml b/.github/workflows/commits.yml new file mode 100644 index 0000000..2965873 --- /dev/null +++ b/.github/workflows/commits.yml @@ -0,0 +1,24 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Conventional Commits Check +on: [push] +jobs: + commit_messages: + runs-on: ubuntu-latest + steps: + - name: Install cocogitto tool + run: | + VERSION=5.6.0 + TAR=cocogitto-${VERSION}-x86_64-unknown-linux-musl.tar.gz + curl --output-dir /tmp -OL https://github.com/cocogitto/cocogitto/releases/download/${VERSION}/${TAR} + sudo tar -xzf /tmp/${TAR} -C /usr/local/bin + + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Conventional commit check + run: | + # Assuming 'main' is the default base branch + BASE_BRANCH=${{ github.base_ref || 'origin/main' }} + cog check ${BASE_BRANCH}..HEAD diff --git a/.gitmodules b/.gitmodules index 008c6be..6d6d78f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "lib/grpc-interfaces"] path = lib/grpc-interfaces url = ../grpc-interfaces.git -[submodule "lib/machine-emulator-defines"] - path = lib/machine-emulator-defines - url = ../machine-emulator-defines.git diff --git a/CHANGELOG.md b/CHANGELOG.md index 984b364..b6bdbca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.9.0] - 2024-02-09 +### Changed +- Updated machine-emulator base image to v0.16.0 +- Updated libboost version to 1.81 +- Updated grpc-interfaces +- Removed machine-emulator-defines +- Look for remote-cartesi-machine in PATH +- Bumped version to 0.9.0 + +### Added +- Added \-\-version command line option + ## [0.8.3] - 2024-01-25 ### Changed - Updated server-manager version to v0.8.3 @@ -44,7 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The creation of test machines was extracted from the test-server-manager to a lua script - The license changed to Apache license 2.0 -[Unreleased]: https://github.com/cartesi/server-manager/compare/v0.8.3...HEAD +[Unreleased]: https://github.com/cartesi/server-manager/compare/v0.9.0...HEAD +[0.9.0]: https://github.com/cartesi/server-manager/releases/tag/v0.9.0 [0.8.3]: https://github.com/cartesi/server-manager/releases/tag/v0.8.3 [0.8.2]: https://github.com/cartesi/server-manager/releases/tag/v0.8.2 [0.8.1]: https://github.com/cartesi/server-manager/releases/tag/v0.8.1 diff --git a/Dockerfile b/Dockerfile index 4610074..bdb2431 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,26 @@ ARG EMULATOR_REPOSITORY=cartesi/machine-emulator -ARG EMULATOR_TAG=0.15.3 +ARG EMULATOR_TAG=0.16.0 ARG RELEASE=yes -FROM --platform=$TARGETPLATFORM ${EMULATOR_REPOSITORY}:${EMULATOR_TAG} as dep-builder +FROM --platform=$TARGETPLATFORM ${EMULATOR_REPOSITORY}:${EMULATOR_TAG} as linux-env USER root RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ - build-essential wget git \ - libreadline-dev libboost-coroutine-dev libboost-context-dev \ - libboost-filesystem-dev libboost-log-dev libssl-dev libc-ares-dev zlib1g-dev \ - ca-certificates automake libtool patchelf cmake pkg-config lua5.4 liblua5.4-dev \ - libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \ - libcrypto++-dev clang-tidy-15 clang-format-15 && \ - update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 && \ - update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120 && \ + build-essential wget git procps \ + libreadline-dev libboost-coroutine1.81-dev libboost-context1.81-dev \ + libboost-filesystem1.81-dev libboost-log1.81-dev libssl-dev libc-ares-dev zlib1g-dev \ + ca-certificates automake libtool patchelf cmake pkg-config lua5.4 liblua5.4-dev \ + libgrpc++-dev libprotobuf-dev protobuf-compiler-grpc \ + libcrypto++-dev clang-tidy-16 clang-format-16 && \ + update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120 && \ + update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120 && \ rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/server-manager -FROM --platform=$TARGETPLATFORM dep-builder as builder +FROM --platform=$TARGETPLATFORM linux-env as builder COPY . . @@ -36,7 +36,11 @@ FROM --platform=$TARGETPLATFORM ${EMULATOR_REPOSITORY}:${EMULATOR_TAG} USER root RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y \ - libboost-log1.74.0 \ + libboost-coroutine1.81.0 \ + libboost-context1.81.0 \ + libboost-filesystem1.81.0 \ + libboost-log1.81.0 \ + libcrypto++8 \ && rm -rf /var/lib/apt/lists/* COPY --from=installer /usr/bin/server-manager /usr/bin/server-manager diff --git a/Makefile b/Makefile index 44e56d1..53191ec 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ HEALTHCHECK_PROTO := third-party/health.proto # Docker image settings TAG ?= devel -EMULATOR_TAG ?= 0.15.3 +EMULATOR_TAG ?= 0.16.0 EMULATOR_REPOSITORY ?= cartesi/machine-emulator # Mac OS X specific settings @@ -109,7 +109,7 @@ $(SERVER_MANAGER_PROTO): @exit 1 test server-manager: | $(SERVER_MANAGER_PROTO) $(HEALTHCHECK_PROTO) -test lint coverage-report check-format format server-manager create-machines create-and-test clean-machines run-test-server-manager: +test lint coverage-report check-format format server-manager create-machines create-and-test clean-machines clean-test-processes run-test-server-manager: @eval $$($(MAKE) -s --no-print-directory env); $(MAKE) -C $(SRCDIR) $@ source-default: | $(SERVER_MANAGER_PROTO) checksum @@ -118,9 +118,30 @@ source-default: | $(SERVER_MANAGER_PROTO) checksum image: docker build -t cartesi/server-manager:$(TAG) -f Dockerfile --build-arg EMULATOR_REPOSITORY=$(EMULATOR_REPOSITORY) --build-arg EMULATOR_TAG=$(EMULATOR_TAG) . +linux-env-stage-image: + docker build --target linux-env -t cartesi/server-manager:linux-env -f Dockerfile --build-arg EMULATOR_REPOSITORY=$(EMULATOR_REPOSITORY) --build-arg EMULATOR_TAG=$(EMULATOR_TAG) . + installer-stage-image: docker build --target installer -t cartesi/server-manager:installer -f Dockerfile --build-arg EMULATOR_REPOSITORY=$(EMULATOR_REPOSITORY) --build-arg EMULATOR_TAG=$(EMULATOR_TAG) . +check-linux-env: + @if docker images $(DOCKER_PLATFORM) -q cartesi/server-manager:linux-env 2>/dev/null | grep -q .; then \ + echo "Docker image cartesi/server-manager:linux-env exists"; \ + else \ + echo "Docker image cartesi/server-manager:linux-env does not exist. Creating:"; \ + $(MAKE) linux-env-stage-image; \ + fi + +linux-env: check-linux-env + @docker run $(DOCKER_PLATFORM) --hostname linux-env -it --rm \ + -e USER=$$(id -u -n) \ + -e GROUP=$$(id -g -n) \ + -e UID=$$(id -u) \ + -e GID=$$(id -g) \ + -v `pwd`:/usr/src/server-manager \ + -w /usr/src/server-manager \ + cartesi/server-manager:linux-env /bin/bash + $(SUBCLEAN): %.clean: $(MAKE) -C $* clean diff --git a/README.md b/README.md index 740e393..cecc3bb 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Cleaning targets: - GNU Make >= 3.81 - GRPC 1.50.0 - Lua 5.4.x -- Boost >= 1.71 +- Boost >= 1.81 Obs: Please note that Apple Clang Version number does not follow upstream LLVM/Clang. @@ -42,7 +42,7 @@ sudo apt-get install build-essential wget git libreadline-dev libboost-coroutine ##### MacPorts ``` -sudo port install clang-15 automake boost libtool wget cmake pkgconfig c-ares zlib openssl lua54 grpc +sudo port install clang-16 automake boost libtool wget cmake pkgconfig c-ares zlib openssl lua54 grpc ``` For `create-machines.lua` script to work it is expected that `lua5.4` binary is available in the system PATH. If operating system/package manager that you are using provides only `lua` or lua binary named in a different way, please create symbolic link or alias `lua5.4`. @@ -90,11 +90,11 @@ We use clang-tidy 15 as the linter. #### Debian Bookworm -You need to install the package clang-tidy-15 and set it as the default executable with update-alternatives. +You need to install the package clang-tidy-16 and set it as the default executable with update-alternatives. ```bash -$ apt install clang-tidy-15 -$ update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 120 +$ apt install clang-tidy-16 +$ update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-16 120 ``` ### Running Lint @@ -111,11 +111,11 @@ We use clang-format to format the code base. #### Debian Bookworm -You need to install the package clang-format-15 and set is as the default executable with update-alternatives. +You need to install the package clang-format-16 and set is as the default executable with update-alternatives. ```bash -$ apt install clang-format-15 -$ update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 120 +$ apt install clang-format-16 +$ update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-16 120 ``` ### Formatting code diff --git a/lib/grpc-interfaces b/lib/grpc-interfaces index cba7c3f..5efc7c7 160000 --- a/lib/grpc-interfaces +++ b/lib/grpc-interfaces @@ -1 +1 @@ -Subproject commit cba7c3f1c53b83bee83d8a1e5a1074591279220f +Subproject commit 5efc7c7d204340602b387dea3c6ba86ddd819206 diff --git a/lib/machine-emulator-defines b/lib/machine-emulator-defines deleted file mode 160000 index 4f164a7..0000000 --- a/lib/machine-emulator-defines +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4f164a788ff34b43c6c070fdc14204cd69110440 diff --git a/src/Makefile b/src/Makefile index ef58384..6c9bba8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -46,10 +46,13 @@ CXX_Darwin=clang++ INCS_Darwin= ifeq ($(UNAME),Darwin) + ifeq ($(MACOSX_DEPLOYMENT_TARGET),) export MACOSX_DEPLOYMENT_TARGET := $(shell sw_vers -productVersion | sed -r "s/([[:digit:]]+)\.([[:digit:]]+)\..+/\1.\2.0/") endif + SOLDFLAGS_Darwin+=-Wl,-rpath,$(BUILDDIR)/lib -Wl,-rpath,$(CURDIR) + # Homebrew installation ifneq (,$(shell which brew)) BREW_PREFIX := $(shell brew --prefix) @@ -59,11 +62,12 @@ CRYPTOPP_LIB_Darwin:=-L$(BREW_PREFIX)/lib -lcryptopp CRYPTOPP_INC_Darwin:=-I$(BREW_PREFIX)/include GRPC_INC_Darwin:=$(shell pkg-config --cflags-only-I grpc++ protobuf) GRPC_LIB_Darwin:=$(shell pkg-config --libs grpc++ protobuf) + # Macports installation else ifneq (,$(shell which port)) PORT_PREFIX=/opt/local -BOOST_LIB_DIR_Darwin=-L$(PORT_PREFIX)/lib -BOOST_INC_Darwin=-I$(PORT_PREFIX)/include +BOOST_LIB_DIR_Darwin=-L$(PORT_PREFIX)/libexec/boost/1.81/lib +BOOST_INC_Darwin=-I$(PORT_PREFIX)/libexec/boost/1.81/include CRYPTOPP_LIB_Darwin:=-L$(PORT_PREFIX)/lib -lcryptopp CRYPTOPP_INC_Darwin:=-I$(PORT_PREFIX)/include GRPC_INC_Darwin=-I$(dir $(GRPC_CPP_PLUGIN))../include @@ -112,7 +116,7 @@ GRPC_LIB=$(GRPC_LIB_$(UNAME)) GRPC_INC=$(GRPC_INC_$(UNAME)) CARTESI_EXECUTABLE_LDFLAGS=$(CARTESI_EXECUTABLE_LDFLAGS_$(UNAME)) -SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(BOOST_CORO_LIB) $(BOOST_LOG_LIB) -ldl +SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(BOOST_CORO_LIB) $(BOOST_LOG_LIB) $(BOOST_FILESYSTEM_LIB) -ldl TEST_SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) -ldl WARNS=-W -Wall -pedantic @@ -185,7 +189,7 @@ CLANG_FORMAT_FILES:=$(filter-out %.pb.h,$(strip $(CLANG_FORMAT_FILES))) EMPTY:= SPACE:=$(EMPTY) $(EMPTY) -CLANG_TIDY_HEADER_FILTER=$(PWD)/($(subst $(SPACE),|,$(LINTER_HEADERS))) +CLANG_TIDY_HEADER_FILTER=$(CURDIR)/($(subst $(SPACE),|,$(LINTER_HEADERS))) CXXFLAGS+=$(OPTFLAGS) -std=c++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) CFLAGS+=$(OPTFLAGS) -std=c99 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) @@ -346,13 +350,13 @@ test-server-manager: $(TEST_SERVER_MANAGER_OBJS) $(PROTOC) $(PROTOC_FLAGS) -I$(HEALTHCHECK_DIR) --cpp_out=. $< %.clang-tidy: %.cpp $(PROTO_SOURCES) - @$(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CXXFLAGS) 2>/dev/null - @$(CXX) $(CXXFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 + $(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CXXFLAGS) 2>/dev/null + $(CXX) $(CXXFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 @touch $@ %.clang-tidy: %.c $(PROTO_SOURCES) - @$(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CFLAGS) 2>/dev/null - @$(CC) $(CFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 + $(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CFLAGS) 2>/dev/null + $(CC) $(CFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 @touch $@ %.o: %.cpp diff --git a/src/back-merkle-tree.cpp b/src/back-merkle-tree.cpp index e6a55c6..7cfaf7f 100644 --- a/src/back-merkle-tree.cpp +++ b/src/back-merkle-tree.cpp @@ -15,6 +15,7 @@ // #include "back-merkle-tree.h" +#include #include /// \file diff --git a/src/complete-merkle-tree.cpp b/src/complete-merkle-tree.cpp index 62fe1bb..b9ad28e 100644 --- a/src/complete-merkle-tree.cpp +++ b/src/complete-merkle-tree.cpp @@ -16,6 +16,8 @@ #include "complete-merkle-tree.h" +#include + /// \file /// \brief Complete Merkle tree implementation. diff --git a/src/create-machines.lua b/src/create-machines.lua index 6e18efd..0548ba1 100755 --- a/src/create-machines.lua +++ b/src/create-machines.lua @@ -16,8 +16,8 @@ -- limitations under the License. -- -local cartesi = require"cartesi" -local util = require"cartesi.util" +local cartesi = require "cartesi" +local util = require "cartesi.util" local function stderr_unsilenceable(fmt, ...) io.stderr:write(string.format(fmt, ...)) @@ -54,6 +54,7 @@ where options are: end local rollup_init = false +local cmdline_opts_finished = false -- List of supported options -- Options are processed in order -- For each option, @@ -79,28 +80,28 @@ local options = { end }, { ".*", function(all) if not all then return false end - local not_option = all:sub(1,1) ~= "-" + local not_option = all:sub(1, 1) ~= "-" if not_option or all == "--" then - cmdline_opts_finished = true - return true + cmdline_opts_finished = true + return true end error("unrecognized option " .. all) end } } -- Process command line options -for i, a in ipairs(arg) do +for _, a in ipairs(arg) do if not cmdline_opts_finished then - for j, option in ipairs(options) do - if option[2](a:match(option[1])) then - break - end - end + for _, option in ipairs(options) do + if option[2](a:match(option[1])) then + break + end + end end end local function create_directory(path) - local success, message = io.open(path, "r") + local success = io.open(path, "r") if success == nil then os.execute("mkdir " .. path) stderr("Created directory:" .. path .. "\n") @@ -111,62 +112,64 @@ local function create_directory(path) end local function get_file_length(file_path) - local file = io.open(file_path, "rb") - local size = file:seek("end") - file:close() - return size + local file = io.open(file_path, "rb") + if file == nil then error("File not found: " .. file_path) end + local size = file:seek("end") + file:close() + return size end -function create_default_config(images_dir, command) +local function create_default_config(images_dir, command) return { - ram = { - length = 0x4000000, - image_filename = images_dir .. "linux.bin", - }, - rom = { - image_filename = images_dir .. "rom.bin", - bootargs = "console=hvc0 rootfstype=ext2 root=/dev/mtdblock0 rw quiet swiotlb=noforce splash=no mtdparts=flash.0:-(root) init=/opt/cartesi/bin/init " .. command, - }, - htif = { - console_getchar = false, -- default - yield_automatic = true, - yield_manual = true, - }, - flash_drive = { - { - start = 1<<55, - length = get_file_length(images_dir .. "rootfs.ext2"), - image_filename = images_dir .. "rootfs.ext2", - shared = false, -- default - }, - }, - rollup = { - rx_buffer = { - start = 0x60000000, - length = 0x200000, - shared = false, -- default + ram = { + length = 0x4000000, + image_filename = images_dir .. "linux.bin", }, - tx_buffer = { - start = 0x60200000, - length = 0x200000, - shared = false, -- default + dtb = { + bootargs = "quiet earlycon=sbi console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw init=/usr/sbin/cartesi-init", + init = "USER=dapp\n", + entrypoint = command, }, - input_metadata = { - start = 0x60400000, - length = 0x1000, - shared = false, -- default + htif = { + console_getchar = false, -- default + yield_automatic = true, + yield_manual = true, }, - voucher_hashes = { - start = 0x60600000, - length = 0x200000, - shared = false, -- default + flash_drive = { + { + start = 1 << 55, + length = get_file_length(images_dir .. "rootfs.ext2"), + image_filename = images_dir .. "rootfs.ext2", + shared = false, -- default + }, }, - notice_hashes = { - start = 0x60800000, - length = 0x200000, - shared = false, -- default + rollup = { + rx_buffer = { + start = 0x60000000, + length = 0x200000, + shared = false, -- default + }, + tx_buffer = { + start = 0x60200000, + length = 0x200000, + shared = false, -- default + }, + input_metadata = { + start = 0x60400000, + length = 0x1000, + shared = false, -- default + }, + voucher_hashes = { + start = 0x60600000, + length = 0x200000, + shared = false, -- default + }, + notice_hashes = { + start = 0x60800000, + length = 0x200000, + shared = false, -- default + }, }, - }, } end @@ -180,19 +183,19 @@ local function instantiate_filename(pattern, values) return (string.gsub(pattern, "\0", "%")) end -local function store_machine(machine, config, store_dir) +local function store_machine(machine, store_dir) local h = util.hexhash(machine:get_root_hash()) local name = instantiate_filename(store_dir, { h = h }) machine:store(name) end local function create_machine(machine_name, command, config_func) - stderr("Creating machine: " .. machine_name .. " ...\n") - local config = create_default_config(IMAGES_DIR, command) - if config_func then config_func(config) end - local machine = cartesi.machine(config) - machine:run(math.maxinteger) - store_machine(machine, config, MACHINES_DIR .. "/" .. machine_name ) + stderr("Creating machine: " .. machine_name .. " ...\n") + local config = create_default_config(IMAGES_DIR, command) + if config_func then config_func(config) end + local machine = cartesi.machine(config) + machine:run(math.maxinteger) + store_machine(machine, MACHINES_DIR .. "/" .. machine_name) end @@ -201,57 +204,62 @@ create_directory(MACHINES_DIR) -- Basic cases if rollup_init then - create_machine("advance-state-machine", "-- rollup-init echo-dapp --vouchers=2 --notices=2 --reports=2 --verbose"); - create_machine("inspect-state-machine", "-- rollup-init echo-dapp --reports=2 --verbose"); - create_machine("one-notice-machine", "-- rollup-init echo-dapp --vouchers=0 --notices=1 --reports=0 --verbose"); - create_machine("one-report-machine", "-- rollup-init echo-dapp --vouchers=0 --notices=0 --reports=1 --verbose"); - create_machine("one-voucher-machine", "-- rollup-init echo-dapp --vouchers=1 --notices=0 --reports=0 --verbose"); - create_machine("advance-rejecting-machine", "-- rollup-init echo-dapp --reject=0 --verbose"); - create_machine("inspect-rejecting-machine", "-- rollup-init echo-dapp --reports=0 --reject-inspects --verbose"); + create_machine("advance-state-machine", "rollup-init echo-dapp --vouchers=2 --notices=2 --reports=2 --verbose"); + create_machine("inspect-state-machine", "rollup-init echo-dapp --reports=2 --verbose"); + create_machine("one-notice-machine", "rollup-init echo-dapp --vouchers=0 --notices=1 --reports=0 --verbose"); + create_machine("one-report-machine", "rollup-init echo-dapp --vouchers=0 --notices=0 --reports=1 --verbose"); + create_machine("one-voucher-machine", "rollup-init echo-dapp --vouchers=1 --notices=0 --reports=0 --verbose"); + create_machine("advance-rejecting-machine", "rollup-init echo-dapp --reject=0 --verbose"); + create_machine("inspect-rejecting-machine", "rollup-init echo-dapp --reports=0 --reject-inspects --verbose"); else - create_machine("advance-state-machine", "-- ioctl-echo-loop --vouchers=2 --notices=2 --reports=2 --verbose=1"); - create_machine("inspect-state-machine", "-- ioctl-echo-loop --reports=2 --verbose=1"); - create_machine("one-notice-machine", "-- ioctl-echo-loop --vouchers=0 --notices=1 --reports=0 --verbose=1"); - create_machine("one-report-machine", "-- ioctl-echo-loop --vouchers=0 --notices=0 --reports=1 --verbose=1"); - create_machine("one-voucher-machine", "-- ioctl-echo-loop --vouchers=1 --notices=0 --reports=0 --verbose=1"); - create_machine("advance-rejecting-machine", "-- ioctl-echo-loop --reject=0 --verbose=1"); - create_machine("inspect-rejecting-machine", "-- ioctl-echo-loop --reports=0 --reject-inspects --verbose=1"); + create_machine("advance-state-machine", "ioctl-echo-loop --vouchers=2 --notices=2 --reports=2 --verbose=1"); + create_machine("inspect-state-machine", "ioctl-echo-loop --reports=2 --verbose=1"); + create_machine("one-notice-machine", "ioctl-echo-loop --vouchers=0 --notices=1 --reports=0 --verbose=1"); + create_machine("one-report-machine", "ioctl-echo-loop --vouchers=0 --notices=0 --reports=1 --verbose=1"); + create_machine("one-voucher-machine", "ioctl-echo-loop --vouchers=1 --notices=0 --reports=0 --verbose=1"); + create_machine("advance-rejecting-machine", "ioctl-echo-loop --reject=0 --verbose=1"); + create_machine("inspect-rejecting-machine", "ioctl-echo-loop --reports=0 --reject-inspects --verbose=1"); end -- Some edge cases -create_machine("no-output-machine", "-- while true; do rollup accept; done"); -create_machine("infinite-loop-machine", "-- rollup accept; while true; do :; done"); -create_machine("halting-machine", "-- rollup accept"); -create_machine("init-exception-machine", "-- echo '{\"payload\":\"test payload\"}' | rollup exception"); -create_machine("exception-machine", "-- rollup accept; echo '{\"payload\":\"test payload\"}' | rollup exception"); +create_machine("no-output-machine", "while true; do rollup accept; done"); +create_machine("infinite-loop-machine", "rollup accept; while true; do :; done"); +create_machine("halting-machine", "rollup accept"); +create_machine("init-exception-machine", "echo '{\"payload\":\"test payload\"}' | rollup exception"); +create_machine("exception-machine", "rollup accept; echo '{\"payload\":\"test payload\"}' | rollup exception"); + + +create_machine("fatal-error-machine", [[ +echo 'curl -vv -H "Content-Type: application/json" -d "{\"status\":\"accept\"}" http://127.0.0.1:5004/finish ; exit 2' > /home/dapp/s.sh; +chmod +x /home/dapp/s.sh; +rollup-init bash /home/dapp/s.sh +]]); + +create_machine("http-server-error-machine", [[ +echo 'curl -vv -H "Content-Type: application/json" -d "{\"status\":\"accept\"}" http://127.0.0.1:5004/finish ; killall rollup-http-server; sleep 86400' > /home/dapp/s.sh; +chmod +x /home/dapp/s.sh; +rollup-init bash /home/dapp/s.sh +]]); -create_machine("fatal-error-machine", - "-- echo 'import requests; requests.post(\"http://127.0.0.1:5004/finish\", json={\"status\":\"accept\"}); exit(2);' > s.py; rollup-init python3 s.py"); -create_machine("http-server-error-machine", - "-- echo 'import requests; import os; requests.post(\"http://127.0.0.1:5004/finish\", json={\"status\":\"accept\"}); os.system(\"killall rollup-http-server\");' > s.py; rollup-init python3 s.py"); create_machine("voucher-on-inspect-machine", - "-- rollup accept; echo '{\"address\":\"fafafafafafafafafafafafafafafafafafafafa\",\"payload\":\"test payload\"}' | rollup voucher; rollup accept"); + "rollup accept; echo '{\"address\":\"fafafafafafafafafafafafafafafafafafafafa\",\"payload\":\"test payload\"}' | rollup voucher; rollup accept"); create_machine("notice-on-inspect-machine", - "-- rollup accept; echo '{\"payload\":\"test payload\"}' | rollup notice; rollup accept"); + "rollup accept; echo '{\"payload\":\"test payload\"}' | rollup notice; rollup accept"); -- Should not work with no rollup or misconfigured htif -create_machine("no-manual-yield-machine", "-- yield automatic rx-accepted 0", - function(config) config.htif.yield_manual = false end ); -create_machine("no-automatic-yield-machine", "-- rollup accept", - function(config) config.htif.yield_automatic= false end ); -create_machine("console-getchar-machine", "-- rollup accept", - function(config) config.htif.console_getchar = true end ); -create_machine("no-rollup-machine", "-- yield manual rx-accepted 0", - function(config) config.rollup = nil end ); +create_machine("console-getchar-machine", "rollup accept", + function(config) config.htif.console_getchar = true end); +create_machine("no-rollup-machine", "yield manual rx-accepted 0", + function(config) config.rollup = nil end); -- Should not work with shared buffers -create_machine("shared-rx-buffer-machine", "-- rollup accept", - function(config) config.rollup.rx_buffer.shared = true end ); -create_machine("shared-tx-buffer-machine", "-- rollup accept", - function(config) config.rollup.tx_buffer.shared = true end ); -create_machine("shared-input-metadata-machine", "-- rollup accept", - function(config) config.rollup.input_metadata.shared = true end ); -create_machine("shared-voucher-hashes-machine", "-- rollup accept", - function(config) config.rollup.voucher_hashes.shared = true end ); -create_machine("shared-notice-hashes-machine", "-- rollup accept", - function(config) config.rollup.notice_hashes.shared = true end ); +create_machine("shared-rx-buffer-machine", "rollup accept", + function(config) config.rollup.rx_buffer.shared = true end); +create_machine("shared-tx-buffer-machine", "rollup accept", + function(config) config.rollup.tx_buffer.shared = true end); +create_machine("shared-input-metadata-machine", "rollup accept", + function(config) config.rollup.input_metadata.shared = true end); +create_machine("shared-voucher-hashes-machine", "rollup accept", + function(config) config.rollup.voucher_hashes.shared = true end); +create_machine("shared-notice-hashes-machine", "rollup accept", + function(config) config.rollup.notice_hashes.shared = true end); diff --git a/src/htif-defines.h b/src/htif-defines.h new file mode 100644 index 0000000..cf12b2e --- /dev/null +++ b/src/htif-defines.h @@ -0,0 +1,55 @@ +// Copyright Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef HTIF_DEFINES_H +#define HTIF_DEFINES_H + +#include + +/// \brief HTIF protocol shifts +enum HTIF_protocol_shift : uint64_t { HTIF_DEV_SHIFT = 56, HTIF_CMD_SHIFT = 48, HTIF_DATA_SHIFT = 0 }; + +/// \brief HTIF protocol masks +enum HTIF_protocol_mask : uint64_t { + HTIF_DEV_MASK = 0xFF00000000000000, + HTIF_CMD_MASK = 0x00FF000000000000, + HTIF_DATA_MASK = 0x0000FFFFFFFFFFFF +}; + +/// \brief HTIF device identifiers +enum HTIF_device : uint64_t { HTIF_DEVICE_HALT = 0, HTIF_DEVICE_CONSOLE = 1, HTIF_DEVICE_YIELD = 2 }; + +/// \brief HTIF device commands +enum HTIF_device_command : uint64_t { + HTIF_HALT_HALT = 0, + HTIF_CONSOLE_GETCHAR = 0, + HTIF_CONSOLE_PUTCHAR = 1, + HTIF_YIELD_AUTOMATIC = 0, + HTIF_YIELD_MANUAL = 1 +}; + +/// \brief HTIF yield reasons +enum HTIF_yield_reason : uint64_t { + HTIF_YIELD_REASON_PROGRESS = 0, + HTIF_YIELD_REASON_RX_ACCEPTED = 1, + HTIF_YIELD_REASON_RX_REJECTED = 2, + HTIF_YIELD_REASON_TX_VOUCHER = 3, + HTIF_YIELD_REASON_TX_NOTICE = 4, + HTIF_YIELD_REASON_TX_REPORT = 5, + HTIF_YIELD_REASON_TX_EXCEPTION = 6, +}; + +#endif /* end of include guard: HTIF_DEFINES_H */ diff --git a/src/i-hasher.h b/src/i-hasher.h index da26096..ff0e059 100644 --- a/src/i-hasher.h +++ b/src/i-hasher.h @@ -22,7 +22,6 @@ #include #include -#include #include "meta.h" diff --git a/src/machine-merkle-tree.h b/src/machine-merkle-tree.h index c464d0c..6011e97 100644 --- a/src/machine-merkle-tree.h +++ b/src/machine-merkle-tree.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "keccak-256-hasher.h" @@ -44,7 +43,7 @@ namespace cartesi { /// /// To optimize for space, subtrees corresponding to pristine /// memory are represented by nullptr nodes. -/// Additionaly, the tree is truncated below *page* nodes +/// Additionally, the tree is truncated below *page* nodes /// subintending LOG2_PAGE_SIZE bits of address space. /// The trees corresponding to pages are rebuilt from the /// original data whenever needed and never stored. @@ -158,7 +157,7 @@ class machine_merkle_tree final { /// \brief Maps a page_index to a node. /// \param page_index Page index. /// \param node Node subintending page. - /// \return 1 if succeeded, 0 othewise. + /// \return 1 if succeeded, 0 otherwise. int set_page_node_map(address_type page_index, tree_node *node); /// \brief Creates and returns a new tree node. diff --git a/src/merkle-tree-proof.h b/src/merkle-tree-proof.h index fe26b46..14df744 100644 --- a/src/merkle-tree-proof.h +++ b/src/merkle-tree-proof.h @@ -20,10 +20,8 @@ /// \file /// \brief Merkle tree proof structure -#include +#include "i-hasher.h" #include -#include -#include #include namespace cartesi { @@ -221,7 +219,7 @@ class merkle_tree_proof final { throw std::out_of_range{"log2_root_size is too large"}; } if (new_log2_target_size < get_log2_target_size()) { - throw std::out_of_range{"log2_taget_size is too small"}; + throw std::out_of_range{"log2_target_size is too small"}; } merkle_tree_proof sliced(new_log2_root_size, new_log2_target_size); hash_type hash = get_target_hash(); @@ -254,7 +252,7 @@ class merkle_tree_proof final { private: /// \brief Converts log2_size to index into siblings array - /// \return Index into siblings array, or throws exception if out of bouds + /// \return Index into siblings array, or throws exception if out of bounds int log2_size_to_index(int log2_size) const { // We know log2_root_size > 0, so log2_root_size-1 >= 0 const int index = m_log2_root_size - 1 - log2_size; diff --git a/src/meta.h b/src/meta.h index e8e6eec..51642f7 100644 --- a/src/meta.h +++ b/src/meta.h @@ -17,7 +17,7 @@ #ifndef META_H #define META_H -#include +#include #include /// \file diff --git a/src/pristine-merkle-tree.cpp b/src/pristine-merkle-tree.cpp index 1184c62..d1867f6 100644 --- a/src/pristine-merkle-tree.cpp +++ b/src/pristine-merkle-tree.cpp @@ -15,6 +15,7 @@ // #include "pristine-merkle-tree.h" +#include #include /// \file diff --git a/src/pristine-merkle-tree.h b/src/pristine-merkle-tree.h index 5e2092e..b668dbe 100644 --- a/src/pristine-merkle-tree.h +++ b/src/pristine-merkle-tree.h @@ -17,12 +17,10 @@ #ifndef PRISTINE_MERKLE_TREE_H #define PRISTINE_MERKLE_TREE_H -#include #include #include #include "keccak-256-hasher.h" -#include "meta.h" /// \file /// \brief Pristine Merkle tree interface. diff --git a/src/protobuf-util.h b/src/protobuf-util.h index 103abc4..68938f7 100644 --- a/src/protobuf-util.h +++ b/src/protobuf-util.h @@ -20,7 +20,6 @@ #pragma GCC diagnostic ignored "-Wdeprecated-copy" #pragma GCC diagnostic ignored "-Wtype-limits" #include "cartesi-machine.pb.h" -#include "versioning.pb.h" #pragma GCC diagnostic pop #include "machine-merkle-tree.h" diff --git a/src/server-manager.cpp b/src/server-manager.cpp index 672d0fd..6fea746 100644 --- a/src/server-manager.cpp +++ b/src/server-manager.cpp @@ -14,16 +14,20 @@ // limitations under the License. // +#if defined(__clang__) && defined(__APPLE__) +#if !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +#define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +#endif +#endif + #include #include #include #include #include -#include #include #include #include -#include #include #include #include @@ -78,30 +82,18 @@ #pragma clang diagnostic pop #endif -#include - #include "complete-merkle-tree.h" +#include "htif-defines.h" #include "keccak-256-hasher.h" #include "merkle-tree-proof.h" #include "protobuf-util.h" -/// \brief HTIF yield reasons -enum HTIF_yield_reason : uint64_t { - HTIF_YIELD_REASON_PROGRESS = HTIF_YIELD_REASON_PROGRESS_DEF, - HTIF_YIELD_REASON_RX_ACCEPTED = HTIF_YIELD_REASON_RX_ACCEPTED_DEF, - HTIF_YIELD_REASON_RX_REJECTED = HTIF_YIELD_REASON_RX_REJECTED_DEF, - HTIF_YIELD_REASON_TX_VOUCHER = HTIF_YIELD_REASON_TX_VOUCHER_DEF, - HTIF_YIELD_REASON_TX_NOTICE = HTIF_YIELD_REASON_TX_NOTICE_DEF, - HTIF_YIELD_REASON_TX_REPORT = HTIF_YIELD_REASON_TX_REPORT_DEF, - HTIF_YIELD_REASON_TX_EXCEPTION = HTIF_YIELD_REASON_TX_EXCEPTION_DEF, -}; - constexpr const uint64_t ROLLUP_ADVANCE_STATE = 0; constexpr const uint64_t ROLLUP_INSPECT_STATE = 1; static constexpr uint32_t manager_version_major = 0; -static constexpr uint32_t manager_version_minor = 8; -static constexpr uint32_t manager_version_patch = 3; +static constexpr uint32_t manager_version_minor = 9; +static constexpr uint32_t manager_version_patch = 0; static constexpr const char *manager_version_pre_release = ""; static constexpr const char *manager_version_build = ""; @@ -190,7 +182,7 @@ static std::string request_metadata(const grpc::ServerContext &context) { // The idea is as follows: // 1) Completion queue returns tag-1 identifying an server call // 2) Processing of tag-1 starts the appropriate client call -// using stub->Async() and reader->Finish(), and specifes tag-2 for +// using stub->Async() and reader->Finish(), and specifies tag-2 for // completion // 4) Completion queue returns tag-2 identifying the client call is complete // 5) Processing of tag-2 passes result back using write->Finish(), and @@ -471,7 +463,7 @@ class auto_lock final { } } - /// \brief Desctructor automatically releases lock + /// \brief Destructor automatically releases lock ~auto_lock() { m_lock = false; } @@ -1554,25 +1546,25 @@ void trigger_and_wait_checkin(handler_context &hctx, async_context &actx, T trig /// \param data New data field /// \return Register value with replaced data field static constexpr uint64_t htif_replace_data_field(uint64_t reg, uint64_t data) { - return (reg & (~HTIF_DATA_MASK_DEF)) | ((data << HTIF_DATA_SHIFT_DEF) & HTIF_DATA_MASK_DEF); + return (reg & (~HTIF_DATA_MASK)) | ((data << HTIF_DATA_SHIFT) & HTIF_DATA_MASK); } /// \brief Obtains the dev field in HTIF's fromhost/tohost register value /// \return Dev data field in register static constexpr uint64_t htif_dev_field(uint64_t reg) { - return (reg & HTIF_DEV_MASK_DEF) >> HTIF_DEV_SHIFT_DEF; + return (reg & HTIF_DEV_MASK) >> HTIF_DEV_SHIFT; } /// \brief Extracts the cmd field in HTIF's fromhost/tohost register value /// \return cmd data field in register static constexpr uint64_t htif_cmd_field(uint64_t reg) { - return (reg & HTIF_CMD_MASK_DEF) >> HTIF_CMD_SHIFT_DEF; + return (reg & HTIF_CMD_MASK) >> HTIF_CMD_SHIFT; } /// \brief Extracts the data field in HTIF's fromhost/tohost register value /// \return cmd data field in register static constexpr uint64_t htif_data_field(uint64_t reg) { - return (reg & HTIF_DATA_MASK_DEF) >> HTIF_DATA_SHIFT_DEF; + return (reg & HTIF_DATA_MASK) >> HTIF_DATA_SHIFT; } /// \brief Checks if HTIF's tohost/fromhost matches an yield device manual command @@ -1581,15 +1573,15 @@ static constexpr uint64_t htif_data_field(uint64_t reg) { /// \param value Register value static void check_htif_yield_manual(async_context &actx, const std::string ®name, uint64_t value) { auto dev = htif_dev_field(value); - if (dev != HTIF_DEVICE_YIELD_DEF) { + if (dev != HTIF_DEVICE_YIELD) { THROW((taint_session{actx.session, grpc::StatusCode::INTERNAL, - "invalid dev field in " + regname + " (expected " + std::to_string(HTIF_DEVICE_YIELD_DEF) + ", got " + + "invalid dev field in " + regname + " (expected " + std::to_string(HTIF_DEVICE_YIELD) + ", got " + std::to_string(dev) + ")"})); } auto cmd = htif_cmd_field(value); - if (cmd != HTIF_YIELD_MANUAL_DEF) { + if (cmd != HTIF_YIELD_MANUAL) { THROW((taint_session{actx.session, grpc::StatusCode::INTERNAL, - "invalid cmd field in " + regname + " (expected " + std::to_string(HTIF_YIELD_MANUAL_DEF) + ", got " + + "invalid cmd field in " + regname + " (expected " + std::to_string(HTIF_YIELD_MANUAL) + ", got " + std::to_string(cmd) + ")"})); } } @@ -1598,10 +1590,10 @@ static void check_htif_yield_manual(async_context &actx, const std::string ®n /// \param value Register value static void check_yield_reason_accepted(uint64_t value) { auto data = htif_data_field(value) << 16 >> 48; - if (data != HTIF_YIELD_REASON_RX_ACCEPTED_DEF) { + if (data != HTIF_YIELD_REASON_RX_ACCEPTED) { THROW((finish_error_yield_none{grpc::StatusCode::INVALID_ARGUMENT, - "invalid data field in htif.tohost (expected " + std::to_string(HTIF_YIELD_REASON_RX_ACCEPTED_DEF) + - ", got " + std::to_string(data) + ")"})); + "invalid data field in htif.tohost (expected " + std::to_string(HTIF_YIELD_REASON_RX_ACCEPTED) + ", got " + + std::to_string(data) + ")"})); } } @@ -2008,7 +2000,7 @@ static std::string read_memory_range(async_context &actx, const MemoryRangeConfi return data ? std::move(*data) : std::string{}; } -/// \brief Checkes if all values are null +/// \brief Checks if all values are null /// \param begin First element /// \param end One past last element /// \return True if all are null, false otherwie @@ -2411,7 +2403,7 @@ static void process_pending_query(handler_context &hctx, async_context &actx, ep set_htif_yield_ack_data(actx, ROLLUP_INSPECT_STATE); auto max_mcycle = actx.session.current_mcycle + actx.session.server_cycles.max_inspect_state; // Loop getting reports until the machine exceeds max_mcycle, rejects the query, accepts the query, - // or behaves inaproppriately + // or behaves inappropriately q.status = completion_status::accepted; auto start_time = std::chrono::system_clock::now(); auto current_mcycle = actx.session.current_mcycle; @@ -2521,7 +2513,7 @@ static void process_pending_inputs(handler_context &hctx, async_context &actx, e check_htif_yield_ack_data(actx, ROLLUP_ADVANCE_STATE); auto max_mcycle = actx.session.current_mcycle + actx.session.server_cycles.max_advance_state; // Loop getting vouchers and notices until the machine exceeds - // max_mcycle, rejects the input, accepts the input, or behaves inaproppriately + // max_mcycle, rejects the input, accepts the input, or behaves inappropriately auto start_time = std::chrono::system_clock::now(); auto mcycle_increment = actx.session.server_cycles.advance_state_increment; auto deadline_increment = actx.session.server_deadline.advance_state_increment; @@ -3282,6 +3274,9 @@ where passed to the spawned remote cartesi machine default: localhost:0 + --version + prints the server version number + --help prints this message and exits @@ -3289,6 +3284,11 @@ where name); } +/// \brief Prints server_manager version +static void print_version() { + (void) fprintf(stderr, "%d.%d.%d\n", manager_version_major, manager_version_minor, manager_version_patch); +} + /// \brief Checks if string matches prefix and captures remaninder /// \param pre Prefix to match in str. /// \param str Input string @@ -3345,6 +3345,9 @@ int main(int argc, char *argv[]) try { ; } else if (stringval("--server-address=", argv[i], &server_address)) { ; + } else if (strcmp(argv[i], "--version") == 0) { + print_version(); + exit(0); } else if (strcmp(argv[i], "--help") == 0) { help(argv[0]); exit(0); @@ -3361,8 +3364,7 @@ int main(int argc, char *argv[]) try { init_logger(); handler_context hctx{}; - std::filesystem::path remote_cartesi_machine_path = - boost::dll::program_location().replace_filename("remote-cartesi-machine"); + std::filesystem::path remote_cartesi_machine_path = boost::process::search_path("remote-cartesi-machine").string(); if (!std::filesystem::exists(remote_cartesi_machine_path)) { remote_cartesi_machine_path = "/usr/bin/remote-cartesi-machine"; if (!std::filesystem::exists(remote_cartesi_machine_path)) { diff --git a/src/test-server-manager.cpp b/src/test-server-manager.cpp index 63bced1..a3a8607 100644 --- a/src/test-server-manager.cpp +++ b/src/test-server-manager.cpp @@ -47,7 +47,6 @@ #pragma clang diagnostic pop #endif -#include "back-merkle-tree.h" #include "complete-merkle-tree.h" using CartesiMachine::Void; @@ -508,7 +507,7 @@ static void init_valid_advance_state_request(AdvanceStateRequest &request, const input_metadata->set_input_index(input_index); auto *input_payload = request.mutable_input_payload(); - *input_payload = get_voucher_payload(input_index); // NOLINT: suppres crytopp warnings + *input_payload = get_voucher_payload(input_index); // NOLINT: suppress crytopp warnings } static void init_valid_inspect_state_request(InspectStateRequest &request, const std::string &session_id, @@ -516,7 +515,7 @@ static void init_valid_inspect_state_request(InspectStateRequest &request, const request.set_session_id(session_id); auto *query_payload = request.mutable_query_payload(); - *query_payload = get_report_payload(input); // NOLINT: suppres crytopp warnings + *query_payload = get_report_payload(input); // NOLINT: suppress crytopp warnings } static void init_valid_finish_epoch_request(FinishEpochRequest &epoch_request, const std::string &session_id, @@ -537,8 +536,8 @@ static void assert_status(Status &status, const std::string &rpcname, bool expec throw std::runtime_error("Call to " + rpcname + " failed. Code: " + std::to_string(status.error_code()) + " Message: " + status.error_message() + ". Assert at " + file + ":" + std::to_string(line)); } - throw std::runtime_error("Call to " + rpcname + " succeded when was expected to fail. Assert at " + file + ":" + - std::to_string(line)); + throw std::runtime_error("Call to " + rpcname + " succeeded when was expected to fail. Assert at " + file + + ":" + std::to_string(line)); } } @@ -565,12 +564,12 @@ void assert_bool(bool value, const std::string &msg, const std::string &file, in #define ASSERT_STATUS_CODE(s, f, v) assert_status_code(s, f, v, __FILE__, __LINE__) static void test_get_version(const std::function &test) { - test("The server-manager server version should be 0.8.x", [](ServerManagerClient &manager) { + test("The server-manager server version should be 0.9.x", [](ServerManagerClient &manager) { Versioning::GetVersionResponse response; Status status = manager.get_version(response); ASSERT_STATUS(status, "GetVersion", true); ASSERT((response.version().major() == 0), "Version Major should be 0"); - ASSERT((response.version().minor() == 8), "Version Minor should be 8"); + ASSERT((response.version().minor() == 9), "Version Minor should be 9"); }); } @@ -655,22 +654,6 @@ static void test_start_session(const std::function files = { - "hash", "config.protobuf", - "0000000000001000-f000.bin", // rom + "hash", "config.json", "0000000000020000-6000.bin", // shadow tlb + "0000000000600000-200000.bin", // uarch-ram "0000000060000000-200000.bin", // rollup rx buffer "0000000060200000-200000.bin", // rollup tx buffer "0000000060400000-1000.bin", // rollup input metadata "0000000060600000-200000.bin", // rollup voucher hashes "0000000060800000-200000.bin", // rollup notice hashes + "000000007ff00000-100000.bin", // dtb "0000000080000000-4000000.bin", // ram - "0080000000000000-4400000.bin" // root drive + "0080000000000000-6400000.bin" // root drive }; if (machine_dir.empty()) { return false; @@ -3506,7 +3490,7 @@ static void test_finish_epoch(const std::function