From 5dc880c370a5026207621ae09a370385e6124b6e Mon Sep 17 00:00:00 2001 From: Diego Nehab <1635557+diegonehab@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:35:34 +0000 Subject: [PATCH] refactor: make field names consistent with evm --- sys-utils/ioctl-echo-loop/ioctl-echo-loop.c | 8 +++---- sys-utils/libcmt/include/libcmt/rollup.h | 20 ++++++++-------- sys-utils/libcmt/src/rollup.c | 14 +++++------ sys-utils/libcmt/src/tests/rollup_echo.c | 6 ++--- sys-utils/rollup/rollup.cpp | 26 ++++++++++----------- 5 files changed, 36 insertions(+), 38 deletions(-) diff --git a/sys-utils/ioctl-echo-loop/ioctl-echo-loop.c b/sys-utils/ioctl-echo-loop/ioctl-echo-loop.c index 4e1c1107..03097d76 100644 --- a/sys-utils/ioctl-echo-loop/ioctl-echo-loop.c +++ b/sys-utils/ioctl-echo-loop/ioctl-echo-loop.c @@ -122,13 +122,13 @@ static int handle_advance_state_request(cmt_rollup_t *me, struct parsed_args *ar int rc = cmt_rollup_read_advance_state(me, &advance); if (rc) return rc; - if (write_vouchers(me, args->voucher_count, advance.sender, advance.length, advance.data) != 0) { + if (write_vouchers(me, args->voucher_count, advance.msg_sender, advance.payload_length, advance.payload) != 0) { return -1; } - if (write_notices(me, args->notice_count, advance.length, advance.data) != 0) { + if (write_notices(me, args->notice_count, advance.payload_length, advance.payload) != 0) { return -1; } - if (write_reports(me, args->report_count, advance.length, advance.data) != 0) { + if (write_reports(me, args->report_count, advance.payload_length, advance.payload) != 0) { return -1; } return 0; @@ -139,7 +139,7 @@ static int handle_inspect_state_request(cmt_rollup_t *me, struct parsed_args *ar int rc = cmt_rollup_read_inspect_state(me, &inspect); if (rc) return rc; - if (write_reports(me, args->report_count, inspect.length, inspect.data) != 0) { + if (write_reports(me, args->report_count, inspect.payload_length, inspect.payload) != 0) { return -1; } return 0; diff --git a/sys-utils/libcmt/include/libcmt/rollup.h b/sys-utils/libcmt/include/libcmt/rollup.h index 5dea9d91..af2fed02 100644 --- a/sys-utils/libcmt/include/libcmt/rollup.h +++ b/sys-utils/libcmt/include/libcmt/rollup.h @@ -43,20 +43,20 @@ typedef struct cmt_rollup { /** Public struct with the advance state contents */ typedef struct cmt_rollup_advance { - uint64_t chain_id; /**< network */ - uint8_t app[CMT_ADDRESS_LENGTH]; /**< application contract address */ - uint8_t sender[CMT_ADDRESS_LENGTH]; /**< input sender */ - uint64_t block_number; /**< block number of this input */ - uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */ - uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */ - uint32_t length; /**< length in bytes of the data field */ - void *data; /**< advance contents */ + uint64_t chain_id; /**< network */ + uint8_t app_contract[CMT_ADDRESS_LENGTH]; /**< application contract address */ + uint8_t msg_sender[CMT_ADDRESS_LENGTH]; /**< input sender address */ + uint64_t block_number; /**< block number of this input */ + uint64_t block_timestamp; /**< block timestamp of this input UNIX epoch format) */ + uint64_t index; /**< input index (in relation to all inputs ever sent to the DApp) */ + uint32_t payload_length; /**< length in bytes of the payload field */ + void *payload; /**< payload for this input */ } cmt_rollup_advance_t; /** Public struct with the inspect state contents */ typedef struct cmt_rollup_inspect { - uint32_t length; /**< length in bytes of the data field */ - void *data; /**< inspect contents */ + uint32_t payload_length; /**< length in bytes of the payload field */ + void *payload; /**< payload for this query */ } cmt_rollup_inspect_t; /** Public struct with the finish state contents */ diff --git a/sys-utils/libcmt/src/rollup.c b/sys-utils/libcmt/src/rollup.c index 6f4f488f..2df247d4 100644 --- a/sys-utils/libcmt/src/rollup.c +++ b/sys-utils/libcmt/src/rollup.c @@ -185,18 +185,18 @@ int cmt_rollup_read_advance_state(cmt_rollup_t *me, cmt_rollup_advance_t *advanc cmt_buf_t st[1] = {{rd->begin + 4, rd->end}}; // EVM offsets are from after funsel cmt_buf_t of[1]; - size_t length = 0; + size_t payload_length = 0; if (DBG(cmt_abi_check_funsel(rd, EVM_ADVANCE)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->chain_id), &advance->chain_id)) || - DBG(cmt_abi_get_address(rd, advance->app)) || - DBG(cmt_abi_get_address(rd, advance->sender)) || + DBG(cmt_abi_get_address(rd, advance->app_contract)) || + DBG(cmt_abi_get_address(rd, advance->msg_sender)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_number), &advance->block_number)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->block_timestamp), &advance->block_timestamp)) || DBG(cmt_abi_get_uint(rd, sizeof(advance->index), &advance->index)) || DBG(cmt_abi_get_bytes_s(rd, of)) || - DBG(cmt_abi_get_bytes_d(st, of, &length, &advance->data))) + DBG(cmt_abi_get_bytes_d(st, of, &payload_length, &advance->payload))) return -ENOBUFS; - advance->length = length; + advance->payload_length = payload_length; return 0; } @@ -206,8 +206,8 @@ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspec if (!inspect) return -EINVAL; cmt_buf_t rx[1] = {cmt_io_get_rx(me->io)}; - inspect->length = cmt_buf_length(rx); - inspect->data = rx->begin; + inspect->payload_length = cmt_buf_length(rx); + inspect->payload = rx->begin; return 0; } diff --git a/sys-utils/libcmt/src/tests/rollup_echo.c b/sys-utils/libcmt/src/tests/rollup_echo.c index ab3f9320..55ceb241 100644 --- a/sys-utils/libcmt/src/tests/rollup_echo.c +++ b/sys-utils/libcmt/src/tests/rollup_echo.c @@ -46,19 +46,19 @@ int main(void) { break; } - rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.sender, advance.sender, sizeof small, small, advance.length, advance.data); + rc = cmt_rollup_emit_voucher(&rollup, sizeof advance.msg_sender, advance.msg_sender, sizeof small, small, advance.payload_length, advance.payload); if (rc < 0) { fprintf(stderr, "%s:%d Error on voucher %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc)); break; } - rc = cmt_rollup_emit_notice(&rollup, advance.length, advance.data); + rc = cmt_rollup_emit_notice(&rollup, advance.payload_length, advance.payload); if (rc < 0) { fprintf(stderr, "%s:%d Error on notice %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc)); break; } - rc = cmt_rollup_emit_report(&rollup, advance.length, advance.data); + rc = cmt_rollup_emit_report(&rollup, advance.payload_length, advance.payload); if (rc < 0) { fprintf(stderr, "%s:%d Error on notice %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc)); break; diff --git a/sys-utils/rollup/rollup.cpp b/sys-utils/rollup/rollup.cpp index 5b42780e..842c8697 100644 --- a/sys-utils/rollup/rollup.cpp +++ b/sys-utils/rollup/rollup.cpp @@ -97,16 +97,14 @@ static void print_help(void) { when field "request_type" contains "advance_state", field "data" contains a JSON object in the format { - "metadata": { - "chain_id": , - "app":
, - "sender":
, - "epoch_index": , - "input_index": , - "block_number": , - "timestamp": - }, - "payload": + "chain_id": , + "app_contract":
, + "msg_sender":
, + "epoch_index": , + "input_index": , + "block_number": , + "timestamp": + "payload": }, where field
contains a 20-byte EVM address in hex @@ -262,9 +260,9 @@ static void write_advance_state(rollup &r, cmt_rollup_finish_t *f) { {"request_type", "advance_state"}, {"data", { {"chain_id", advance.chain_id}, - {"payload", hex(reinterpret_cast(advance.data), advance.length)}, - {"app", hex(advance.app, sizeof(advance.app))}, - {"sender", hex(advance.sender, sizeof(advance.sender))}, + {"payload", hex(reinterpret_cast(advance.payload), advance.payload_length)}, + {"app_contract", hex(advance.app_contract, sizeof(advance.app_contract))}, + {"msg_sender", hex(advance.msg_sender, sizeof(advance.msg_sender))}, {"block_number", advance.block_number}, {"block_timestamp", advance.block_timestamp}, {"index", advance.index}, @@ -283,7 +281,7 @@ static void write_inspect_state(rollup &r, cmt_rollup_finish_t *f) { nlohmann::json j = { {"request_type", "inspect_state"}, {"data", { - {"payload", hex(reinterpret_cast(inspect.data), inspect.length)}, + {"payload", hex(reinterpret_cast(inspect.payload), inspect.payload_length)}, }} }; std::cout << j.dump(2) << '\n';