Skip to content

Commit

Permalink
feat!: Bump emulator and grpc-interfaces
Browse files Browse the repository at this point in the history
- Add --version option and bump the version for the next release.
- Update boost to version 1.81
  • Loading branch information
vfusco committed Nov 21, 2023
1 parent 2f3361e commit bc3ed0a
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 65 deletions.
21 changes: 2 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Build/Test/Release
on: [push]
env:
EMULATOR_REPOSITORY: cartesi/machine-emulator
EMULATOR_TAG: 0.15.2
ROM_VERSION: v0.17.0
EMULATOR_REPOSITORY: ghcr.io/cartesi/machine-emulator
EMULATOR_TAG: main
KERNEL_VERSION: v0.17.0
LINUX_VERSION: 5.15.63-ctsi-2-v0.17.0
ROOTFS_VERSION: v0.18.0
Expand Down Expand Up @@ -141,19 +140,11 @@ jobs:
tag: ${{ env.KERNEL_VERSION }}
file: linux-${{ env.LINUX_VERSION }}.bin

- name: Download [rom.bin]
uses: Legion2/[email protected]
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 }}
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
- name: Run test suite inside the docker image (Linux/${{ matrix.arch }})
Expand Down Expand Up @@ -252,19 +243,11 @@ jobs:
tag: ${{ env.KERNEL_VERSION }}
file: linux-${{ env.LINUX_VERSION }}.bin

- name: Download [rom.bin]
uses: Legion2/[email protected]
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 }}
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
- name: Run test suite inside the docker image (Linux/${{ matrix.arch }})
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Updated libboost version to 1.81
- Updated grpc-interfaces
- Updated machine-emulator-defines
- Bumped version to 0.9.0

### Added
- Added \-\-version command line option

## [0.8.2] - 2023-08-21
### Changed
- Updated server-manager version to v0.8.2
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ 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 \
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-15 clang-format-15 && \
Expand All @@ -36,7 +36,7 @@ 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-log1.81.0 \
&& rm -rf /var/lib/apt/lists/*

COPY --from=installer /usr/bin/server-manager /usr/bin/server-manager
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ HEALTHCHECK_PROTO := third-party/health.proto

# Docker image settings
TAG ?= devel
EMULATOR_TAG ?= 0.15.2
EMULATOR_REPOSITORY ?= cartesi/machine-emulator
EMULATOR_TAG ?= main
EMULATOR_REPOSITORY ?= ghcr.io/cartesi/machine-emulator

# Mac OS X specific settings
ifeq ($(UNAME),Darwin)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cartesi Server-Manager

The Cartesi Server-Manager is a microservice that serves as an interface between the Remote Cartesi Machine (RCM) and other components of the Cartesi Rollup node. It is designed to simplify the communication between the RCM and the rest of the Cartesi node. It's written in C/C++ with POSIX dependencies restricted to the terminal and process facilites. Currently, it is distributed as a docker image.
The Cartesi Server-Manager is a microservice that serves as an interface between the Remote Cartesi Machine (RCM) and other components of the Cartesi Rollup node. It is designed to simplify the communication between the RCM and the rest of the Cartesi node. It's written in C/C++ with POSIX dependencies restricted to the terminal and process facilities. Currently, it is distributed as a docker image.

## Getting Started

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion lib/grpc-interfaces
1 change: 0 additions & 1 deletion lib/machine-emulator-defines
Submodule machine-emulator-defines deleted from 4f164a
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ BOOST_INC_Darwin=-I/usr/local/opt/boost/include
CRYPTOPP_LIB_Darwin:=-L/usr/local/opt/cryptopp/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I/usr/local/opt/cryptopp/include
else # Macports installation
BOOST_LIB_DIR_Darwin=-L/opt/local/lib
BOOST_INC_Darwin=-I/opt/local/include
BOOST_LIB_DIR_Darwin=-L/opt/local/libexec/boost/1.81/lib
BOOST_INC_Darwin=-I/opt/local/libexec/boost/1.81/include
CRYPTOPP_LIB_Darwin:=-L/opt/local/lib -lcryptopp
CRYPTOPP_INC_Darwin:=-I/opt/local/include
endif
Expand Down Expand Up @@ -107,7 +107,7 @@ GRPC_INC=$(GRPC_INC_$(UNAME))
PROTOBUF_LIB=$(PROTOBUF_LIB_$(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
Expand Down
5 changes: 2 additions & 3 deletions src/create-machines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ function create_default_config(images_dir, command)
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,
dtb = {
bootargs = "console=hvc0 rootfstype=ext2 root=/dev/mtdblock0 rw quiet swiotlb=noforce splash=no mtdparts=flash.0:-(root) init=/opt/cartesi/bin/init random.trust_bootloader=on " .. command,
},
htif = {
console_getchar = false, -- default
Expand Down
55 changes: 55 additions & 0 deletions src/htif-defines.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

/// \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 */
51 changes: 25 additions & 26 deletions src/server-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,18 @@
#pragma clang diagnostic pop
#endif

#include <htif-defines.h>

#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 = 2;
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 = "";

Expand Down Expand Up @@ -1554,25 +1542,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
Expand All @@ -1581,15 +1569,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 &regname, 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) + ")"}));
}
}
Expand All @@ -1598,10 +1586,10 @@ static void check_htif_yield_manual(async_context &actx, const std::string &regn
/// \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) + ")"}));
}
}

Expand Down Expand Up @@ -3282,13 +3270,21 @@ where
passed to the spawned remote cartesi machine
default: localhost:0
--version
prints the server version number
--help
prints this message and exits
)",
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
Expand Down Expand Up @@ -3345,6 +3341,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);
Expand Down
4 changes: 2 additions & 2 deletions src/test-server-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,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<void(const std::string &title, test_function f)> &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");
});
}

Expand Down

0 comments on commit bc3ed0a

Please sign in to comment.