From f1c9860276e3eab0b682a99096133dac68fae01a Mon Sep 17 00:00:00 2001 From: Victor Fusco <1221933+vfusco@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:52:39 -0300 Subject: [PATCH] feat!: Make rollup enabled by default --- .github/workflows/build.yml | 4 +-- Dockerfile | 3 +-- src/cartesi-machine-tests.lua | 11 ++++++-- src/cartesi-machine.lua | 47 ++++++++++++++++------------------- src/machine-config.h | 16 ++++++------ src/machine.cpp | 3 +++ src/tests/htif-rollup.lua | 1 + 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 889b9bf1..daeed4eb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -198,7 +198,7 @@ jobs: - name: Save and Load run: | mkdir -m 755 -p ${{ env.CARTESI_IMAGES_PATH }}/snapshots - docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --max-mcycle=0 --rollup --store=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test + docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --max-mcycle=0 --store=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test docker run --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --load=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test sudo rm -rf ${{ env.CARTESI_IMAGES_PATH }}/snapshots @@ -344,7 +344,7 @@ jobs: - name: Save and Load run: | mkdir -m 755 -p ${{ env.CARTESI_IMAGES_PATH }}/snapshots - docker run --platform linux/arm64 --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --max-mcycle=0 --rollup --store=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test + docker run --platform linux/arm64 --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --max-mcycle=0 --store=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test docker run --platform linux/arm64 --rm -v ${{ env.CARTESI_IMAGES_PATH }}:${{ env.CARTESI_IMAGES_PATH }} -t ${{ github.repository_owner }}/machine-emulator:devel /usr/bin/cartesi-machine --load=${{ env.CARTESI_IMAGES_PATH }}/snapshots/save_and_load_test sudo rm -rf ${{ env.CARTESI_IMAGES_PATH }}/snapshots diff --git a/Dockerfile b/Dockerfile index b722c370..f20611c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,7 @@ ARG SANITIZE=no RUN apt-get update && \ DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ build-essential vim wget git clang-tidy-15 clang-format-15 lcov \ - libreadline-dev libboost-context1.81-dev \ - libboost-filesystem1.81-dev libssl-dev libc-ares-dev zlib1g-dev \ + libreadline-dev libboost-filesystem1.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 \ luarocks libb64-dev libcrypto++-dev nlohmann-json3-dev && \ diff --git a/src/cartesi-machine-tests.lua b/src/cartesi-machine-tests.lua index 08556958..91e8dfef 100755 --- a/src/cartesi-machine-tests.lua +++ b/src/cartesi-machine-tests.lua @@ -639,8 +639,15 @@ local function build_machine(test_name) }, htif = { console_getchar = false, - yield_progress = false, - yield_rollup = false, + yield_automatic = true, + yield_manual = true, + }, + rollup = { + rx_buffer = { start = 0x60000000, length = 2 << 20 }, + tx_buffer = { start = 0x60200000, length = 2 << 20 }, + input_metadata = { start = 0x60400000, length = 4096 }, + voucher_hashes = { start = 0x60600000, length = 2 << 20 }, + notice_hashes = { start = 0x60800000, length = 2 << 20 }, }, flash_drive = { { start = 0x80000000000000, diff --git a/src/cartesi-machine.lua b/src/cartesi-machine.lua index 1afc7197..284251fb 100755 --- a/src/cartesi-machine.lua +++ b/src/cartesi-machine.lua @@ -168,19 +168,17 @@ where options are: semantics are the same as for the --flash-drive option with the following difference: start and length are mandatory. - --rollup - defines appropriate values for rollup-rx-buffer, rollup-tx-buffer, + --no-rollup + do not define values for rollup-rx-buffer, rollup-tx-buffer, rollup-input-metadata, rollup-voucher-hashes, rollup-notice hashes, and htif yield for use with rollups. - equivalent to the following options: + default defined values are equivalent to the following options: --rollup-rx-buffer=start:0x60000000,length:2<<20 --rollup-tx-buffer=start:0x60200000,length:2<<20 --rollup-input-metadata=start:0x60400000,length:4096 --rollup-voucher-hashes=start:0x60600000,length:2<<20 --rollup-notice-hashes=start:0x60800000,length:2<<20 - --htif-yield-manual - --htif-yield-automatic --rollup-advance-state=:[,:[,...]...] advances the state of the machine through a number of inputs in an epoch @@ -306,11 +304,11 @@ where options are: This option will copy TERM, LANG, LC_ALL environment variables from the host to the guest, allowing the use of true colors and special characters when the host terminal supports. - --htif-yield-manual - honor yield requests with manual reset by target. + --no-htif-yield-manual + do not honor yield requests with manual reset by target. - --htif-yield-automatic - honor yield requests with automatic reset by target. + --no-htif-yield-automatic + do not honor yield requests with automatic reset by target. --store= store machine to , where "%%h" is substituted by the @@ -448,7 +446,13 @@ local init_splash = true local append_bootargs = "" local append_init = "" local append_entrypoint = "" -local rollup +local rollup = { + rx_buffer = { start = 0x60000000, length = 2 << 20 }, + tx_buffer = { start = 0x60200000, length = 2 << 20 }, + input_metadata = { start = 0x60400000, length = 4096 }, + voucher_hashes = { start = 0x60600000, length = 2 << 20 }, + notice_hashes = { start = 0x60800000, length = 2 << 20 }, +} local uarch local rollup_advance local rollup_inspect @@ -457,8 +461,8 @@ local skip_root_hash_check = false local skip_version_check = false local htif_no_console_putchar = false local htif_console_getchar = false -local htif_yield_automatic = false -local htif_yield_manual = false +local htif_yield_automatic = true +local htif_yield_manual = true local initial_hash = false local final_hash = false local initial_proof = {} @@ -670,33 +674,26 @@ local options = { end, }, { - "^%-%-htif%-yield%-manual$", + "^%-%-no%-htif%-yield%-manual$", function(all) if not all then return false end - htif_yield_manual = true + htif_yield_manual = false return true end, }, { - "^%-%-htif%-yield%-automatic$", + "^%-%-no%-htif%-yield%-automatic$", function(all) if not all then return false end - htif_yield_automatic = true + htif_yield_automatic = false return true end, }, { - "^%-%-rollup$", + "^%-%-no%-rollup$", function(all) if not all then return false end - rollup = rollup or {} - rollup.rx_buffer = { start = 0x60000000, length = 2 << 20 } - rollup.tx_buffer = { start = 0x60200000, length = 2 << 20 } - rollup.input_metadata = { start = 0x60400000, length = 4096 } - rollup.voucher_hashes = { start = 0x60600000, length = 2 << 20 } - rollup.notice_hashes = { start = 0x60800000, length = 2 << 20 } - htif_yield_automatic = true - htif_yield_manual = true + rollup = nil return true end, }, diff --git a/src/machine-config.h b/src/machine-config.h index 37036475..91bdb67d 100644 --- a/src/machine-config.h +++ b/src/machine-config.h @@ -112,17 +112,17 @@ struct htif_config final { uint64_t fromhost{FROMHOST_INIT}; ///< Value of fromhost CSR uint64_t tohost{TOHOST_INIT}; ///< Value of tohost CSR bool console_getchar{false}; ///< Make console getchar available? - bool yield_manual{false}; ///< Make yield manual available? - bool yield_automatic{false}; ///< Make yield automatic available? + bool yield_manual{true}; ///< Make yield manual available? + bool yield_automatic{true}; ///< Make yield automatic available? }; /// \brief Rollup configuration -struct rollup_config { // NOLINT(bugprone-exception-escape) - memory_range_config rx_buffer{}; ///< RX buffer - memory_range_config tx_buffer{}; ///< TX buffer - memory_range_config input_metadata{}; ///< Buffer for input metadata - memory_range_config voucher_hashes{}; ///< Buffer for the voucher hash array - memory_range_config notice_hashes{}; ///< Buffer for the notice hash array +struct rollup_config { // NOLINT(bugprone-exception-escape) + memory_range_config rx_buffer{0x60000000, 2 << 20}; ///< RX buffer + memory_range_config tx_buffer{0x60200000, 2 << 20}; ///< TX buffer + memory_range_config input_metadata{0x60400000, 4096}; ///< Buffer for input metadata + memory_range_config voucher_hashes{0x60600000, 2 << 20}; ///< Buffer for the voucher hash array + memory_range_config notice_hashes{0x60800000, 2 << 20}; ///< Buffer for the notice hash array }; /// \brief Machine state configuration diff --git a/src/machine.cpp b/src/machine.cpp index 4f70c7b4..a1d81144 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -380,6 +380,9 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) : // Register rollup memory ranges if (m_c.rollup.has_value()) { + if (!m_c.htif.yield_automatic || !m_c.htif.yield_manual) { + throw std::invalid_argument{"rollup device requires automatic and manual yield"}; + } if (m_c.rollup->rx_buffer.length == 0 || m_c.rollup->rx_buffer.start == 0 || m_c.rollup->tx_buffer.length == 0 || m_c.rollup->tx_buffer.start == 0 || m_c.rollup->input_metadata.length == 0 || m_c.rollup->input_metadata.start == 0 || diff --git a/src/tests/htif-rollup.lua b/src/tests/htif-rollup.lua index 3d2efbe0..bac7eee5 100755 --- a/src/tests/htif-rollup.lua +++ b/src/tests/htif-rollup.lua @@ -35,6 +35,7 @@ local config_base = { }, htif = { yield_automatic = true, + yield_manual = true, }, rollup = { rx_buffer = {