Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup enable by default #143

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
11 changes: 9 additions & 2 deletions src/cartesi-machine-tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 22 additions & 25 deletions src/cartesi-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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=<key>:<value>[,<key>:<value>[,...]...]
advances the state of the machine through a number of inputs in an epoch
Expand Down Expand Up @@ -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=<directory>
store machine to <directory>, where "%%h" is substituted by the
Expand Down Expand Up @@ -448,7 +446,13 @@ local init_splash = true
local append_bootargs = ""
local append_init = ""
local append_entrypoint = ""
local rollup
local rollup = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only solves for cartesi-machine.lua, what about the C API cm_get_default_config ? Shoudn't we also make this the default there? cc @diegonehab

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It should be default in C++ as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not get the default config in cartesi-machine.lua, right? We build one from scracth. Should we stop doing that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Victor will create an issue about 'get_default_config' vs. 'cartesi-machine.lua'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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
diegonehab marked this conversation as resolved.
Show resolved Hide resolved
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
diegonehab marked this conversation as resolved.
Show resolved Hide resolved
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,
},
Expand Down
16 changes: 8 additions & 8 deletions src/machine-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
1 change: 1 addition & 0 deletions src/tests/htif-rollup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local config_base = {
},
htif = {
yield_automatic = true,
yield_manual = true,
},
rollup = {
rx_buffer = {
Expand Down