Skip to content

Commit

Permalink
fixup! refactor: split reasons for manual and auto yields
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed Mar 19, 2024
1 parent d62900d commit d4f6f73
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 88 deletions.
10 changes: 5 additions & 5 deletions sys-utils/ioctl-echo-loop/ioctl-echo-loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ static int handle_inspect_state_request(cmt_rollup_t *me, struct parsed_args *ar

static int handle_request(cmt_rollup_t *me, struct parsed_args *args, cmt_rollup_finish_t *finish) {
switch (finish->next_request_type) {
case CMT_IO_REASON_ADVANCE:
case HTIF_YIELD_REASON_ADVANCE:
return handle_advance_state_request(me, args);
case CMT_IO_REASON_INSPECT:
case HTIF_YIELD_REASON_INSPECT:
return handle_inspect_state_request(me, args);
default:
/* unknown request type */
Expand Down Expand Up @@ -184,10 +184,10 @@ int main(int argc, char *argv[]) {
break;
}
reject_advance =
(finish.next_request_type == CMT_IO_REASON_ADVANCE) && (args.reject == input_index);
reject_inspect = (finish.next_request_type == CMT_IO_REASON_INSPECT) && args.reject_inspects;
(finish.next_request_type == HTIF_YIELD_REASON_ADVANCE) && (args.reject == input_index);
reject_inspect = (finish.next_request_type == HTIF_YIELD_REASON_INSPECT) && args.reject_inspects;
throw_exception =
(finish.next_request_type == CMT_IO_REASON_ADVANCE) && (args.exception == input_index);
(finish.next_request_type == HTIF_YIELD_REASON_ADVANCE) && (args.exception == input_index);
if (throw_exception) {
const char message[] = "exception";
cmt_rollup_emit_exception(&rollup, sizeof message -1, message);
Expand Down
6 changes: 3 additions & 3 deletions sys-utils/libcmt/doc/examples/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ int exception(union cmt_io_driver *io) {

/* exception -------------------------------------------------------- */
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_TX_EXCEPTION,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION,
.data = n,
}};
if (cmt_io_yield(io, req)) {
Expand Down
4 changes: 2 additions & 2 deletions sys-utils/libcmt/doc/examples/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(void) {
if (cmt_rollup_finish(&rollup, &finish) < 0)
return EXIT_FAILURE;
switch (finish.next_request_type) {
case CMT_IO_REASON_ADVANCE:
case HTIF_YIELD_REASON_ADVANCE:
rc = cmt_rollup_read_advance_state(&rollup, &advance);
if (rc < 0) {
fprintf(stderr, "%s:%d Error on advance %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc));
Expand All @@ -36,7 +36,7 @@ int main(void) {
break;
}
break;
case CMT_IO_REASON_INSPECT:
case HTIF_YIELD_REASON_INSPECT:
break;
}
}
Expand Down
33 changes: 19 additions & 14 deletions sys-utils/libcmt/include/libcmt/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,35 @@
#include <stddef.h>
#include <stdint.h>

/** Device */
enum {
CMT_IO_DEV = 2, /**< IO Device */
HTIF_DEVICE_YIELD = 2, /**< Yield device */
};

/** Request */
/** Commands */
enum {
CMT_IO_CMD_AUTOMATIC = 0, /**< Automatic */
CMT_IO_CMD_MANUAL = 1, /**< Manual */
HTIF_YIELD_CMD_AUTOMATIC = 0, /**< Automatic yield */
HTIF_YIELD_CMD_MANUAL = 1, /**< Manual yield */
};

/** Request */
/** Automatic reasons */
enum {
CMT_IO_AUTOMATIC_REASON_PROGRESS = 1, /**< Progress */
CMT_IO_AUTOMATIC_REASON_TX_OUTPUT = 2, /**< emit an output */
CMT_IO_AUTOMATIC_REASON_TX_REPORT = 4, /**< emit a report */
CMT_IO_MANUAL_REASON_RX_ACCEPTED = 1, /**< Accept and load next input */
CMT_IO_MANUAL_REASON_RX_REJECTED = 2, /**< Reject and revert */
CMT_IO_MANUAL_REASON_TX_EXCEPTION = 4, /**< emit a exception and halt execution */
HTIF_YIELD_AUTOMATIC_REASON_PROGRESS = 1, /**< Progress */
HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT = 2, /**< emit an output */
HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT = 4, /**< emit a report */
};

/** Reply reason when requesting @ref CMT_IO_REASON_RX_ACCEPTED */
/** Manual reasons */
enum {
CMT_IO_REASON_ADVANCE = 0, /**< Input is advance */
CMT_IO_REASON_INSPECT = 1, /**< Input is inspect */
HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED = 1, /**< Accept and load next input */
HTIF_YIELD_MANUAL_REASON_RX_REJECTED = 2, /**< Reject and revert */
HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION = 4, /**< emit a exception and halt execution */
};

/** Reply reason when requesting @ref HTIF_YIELD_REASON_RX_ACCEPTED or HTIF_YIELD_REASON_RX_REJECTED */
enum {
HTIF_YIELD_REASON_ADVANCE = 0, /**< Input is advance */
HTIF_YIELD_REASON_INSPECT = 1, /**< Input is inspect */
};

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion sys-utils/libcmt/include/libcmt/rollup.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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 address */
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) */
Expand Down
28 changes: 14 additions & 14 deletions sys-utils/libcmt/src/mock/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int store_next_output(cmt_io_driver_mock_t *me, char *ns, int *seq, struc

static int mock_progress(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
(void) me;
if (rr->cmd != CMT_IO_CMD_AUTOMATIC) {
if (rr->cmd != HTIF_YIELD_CMD_AUTOMATIC) {
fprintf(stderr, "Expected cmd to be AUTOMATIC\n");
return -EINVAL;
}
Expand All @@ -133,7 +133,7 @@ static int mock_progress(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
}

static int mock_rx_accepted(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
if (rr->cmd != CMT_IO_CMD_MANUAL) {
if (rr->cmd != HTIF_YIELD_CMD_MANUAL) {
fprintf(stderr, "Expected cmd to be MANUAL\n");
return -EINVAL;
}
Expand All @@ -150,7 +150,7 @@ static int mock_rx_accepted(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
}

static int mock_rx_rejected(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
if (rr->cmd != CMT_IO_CMD_MANUAL) {
if (rr->cmd != HTIF_YIELD_CMD_MANUAL) {
fprintf(stderr, "Expected cmd to be MANUAL\n");
return -EINVAL;
}
Expand All @@ -161,23 +161,23 @@ static int mock_rx_rejected(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
}

static int mock_tx_output(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
if (rr->cmd != CMT_IO_CMD_AUTOMATIC) {
if (rr->cmd != HTIF_YIELD_CMD_AUTOMATIC) {
fprintf(stderr, "Expected cmd to be AUTOMATIC\n");
return -EINVAL;
}
return store_next_output(me, "output-", &me->output_seq, rr);
}

static int mock_tx_report(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
if (rr->cmd != CMT_IO_CMD_AUTOMATIC) {
if (rr->cmd != HTIF_YIELD_CMD_AUTOMATIC) {
fprintf(stderr, "Expected cmd to be AUTOMATIC\n");
return -EINVAL;
}
return store_next_output(me, "report-", &me->report_seq, rr);
}

static int mock_tx_exception(cmt_io_driver_mock_t *me, struct cmt_io_yield *rr) {
if (rr->cmd != CMT_IO_CMD_MANUAL) {
if (rr->cmd != HTIF_YIELD_CMD_MANUAL) {
fprintf(stderr, "Expected cmd to be MANUAL\n");
return -EINVAL;
}
Expand All @@ -201,24 +201,24 @@ int cmt_io_yield(cmt_io_driver_t *_me, struct cmt_io_yield *rr) {
rr->dev, rr->cmd, rr->reason, rr->data);
}

if (rr->cmd == CMT_IO_CMD_MANUAL) {
if (rr->cmd == HTIF_YIELD_CMD_MANUAL) {
switch (rr->reason) {
case CMT_IO_MANUAL_REASON_RX_ACCEPTED:
case HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED:
return mock_rx_accepted(me, rr);
case CMT_IO_MANUAL_REASON_RX_REJECTED:
case HTIF_YIELD_MANUAL_REASON_RX_REJECTED:
return mock_rx_rejected(me, rr);
case CMT_IO_MANUAL_REASON_TX_EXCEPTION:
case HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION:
return mock_tx_exception(me, rr);
default:
return -EINVAL;
}
} else if (rr->cmd == CMT_IO_CMD_AUTOMATIC) {
} else if (rr->cmd == HTIF_YIELD_CMD_AUTOMATIC) {
switch (rr->reason) {
case CMT_IO_AUTOMATIC_REASON_PROGRESS:
case HTIF_YIELD_AUTOMATIC_REASON_PROGRESS:
return mock_progress(me, rr);
case CMT_IO_AUTOMATIC_REASON_TX_OUTPUT:
case HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT:
return mock_tx_output(me, rr);
case CMT_IO_AUTOMATIC_REASON_TX_REPORT:
case HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT:
return mock_tx_report(me, rr);
default:
return -EINVAL;
Expand Down
42 changes: 21 additions & 21 deletions sys-utils/libcmt/src/rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ int cmt_rollup_emit_voucher(cmt_rollup_t *me,

size_t m = wr->begin - tx->begin;
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_TX_OUTPUT,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
.data = m,
}};
int rc = DBG(cmt_io_yield(me->io, req));
Expand All @@ -122,9 +122,9 @@ int cmt_rollup_emit_notice(cmt_rollup_t *me, uint32_t length, const void *data)

size_t m = wr->begin - tx->begin;
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_TX_OUTPUT,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
.data = m,
}};
int rc = DBG(cmt_io_yield(me->io, req));
Expand All @@ -146,9 +146,9 @@ int cmt_rollup_emit_report(cmt_rollup_t *me, uint32_t length, const void *data)

memcpy(wr->begin, data, length);
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_TX_REPORT,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT,
.data = length,
}};
return DBG(cmt_io_yield(me->io, req));
Expand All @@ -167,9 +167,9 @@ int cmt_rollup_emit_exception(cmt_rollup_t *me, uint32_t length, const void *dat

memcpy(tx->begin, data, length);
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_TX_EXCEPTION,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION,
.data = length,
}};
return DBG(cmt_io_yield(me->io, req));
Expand Down Expand Up @@ -220,9 +220,9 @@ int cmt_rollup_read_inspect_state(cmt_rollup_t *me, cmt_rollup_inspect_t *inspec

static int accepted(union cmt_io_driver *io, uint32_t *n) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_RX_ACCEPTED,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED,
.data = *n,
}};
int rc = DBG(cmt_io_yield(io, req));
Expand All @@ -235,9 +235,9 @@ static int accepted(union cmt_io_driver *io, uint32_t *n) {

static int revert(union cmt_io_driver *io) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_RX_REJECTED,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_RX_REJECTED,
.data = 0,
}};
return DBG(cmt_io_yield(io, req));
Expand Down Expand Up @@ -267,9 +267,9 @@ int cmt_rollup_finish(cmt_rollup_t *me, cmt_rollup_finish_t *finish) {

int cmt_rollup_progress(cmt_rollup_t *me, uint32_t progress) {
cmt_io_yield_t req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_PROGRESS,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_PROGRESS,
.data = progress,
}};
return DBG(cmt_io_yield(me->io, req));
Expand Down
24 changes: 12 additions & 12 deletions sys-utils/libcmt/src/tests/io_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

int next(union cmt_io_driver *io, uint32_t *n) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_RX_ACCEPTED,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_RX_ACCEPTED,
.data = *n,
}};
if (cmt_io_yield(io, req)) {
Expand All @@ -21,29 +21,29 @@ int next(union cmt_io_driver *io, uint32_t *n) {

int voucher(union cmt_io_driver *io, uint32_t n) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_TX_OUTPUT,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT,
.data = n,
}};
return cmt_io_yield(io, req);
}

int report(union cmt_io_driver *io, uint32_t n) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_AUTOMATIC,
.reason = CMT_IO_AUTOMATIC_REASON_TX_REPORT,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_AUTOMATIC,
.reason = HTIF_YIELD_AUTOMATIC_REASON_TX_REPORT,
.data = n,
}};
return cmt_io_yield(io, req);
}

int exception(union cmt_io_driver *io, uint32_t n) {
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_TX_EXCEPTION,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION,
.data = n,
}};
return cmt_io_yield(io, req);
Expand Down
6 changes: 3 additions & 3 deletions sys-utils/libcmt/src/tests/io_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ int main(void) {

/* exception -------------------------------------------------------- */
struct cmt_io_yield req[1] = {{
.dev = CMT_IO_DEV,
.cmd = CMT_IO_CMD_MANUAL,
.reason = CMT_IO_MANUAL_REASON_TX_EXCEPTION,
.dev = HTIF_DEVICE_YIELD,
.cmd = HTIF_YIELD_CMD_MANUAL,
.reason = HTIF_YIELD_MANUAL_REASON_TX_EXCEPTION,
.data = n,
}};
if (cmt_io_yield(io, req)) {
Expand Down
4 changes: 2 additions & 2 deletions sys-utils/libcmt/src/tests/rollup_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(void) {
goto teardown;

switch (finish.next_request_type) {
case CMT_IO_REASON_ADVANCE:
case HTIF_YIELD_REASON_ADVANCE:
rc = cmt_rollup_read_advance_state(&rollup, &advance);
if (rc < 0) {
fprintf(stderr, "%s:%d Error on advance %s (%d)\n", __FILE__, __LINE__, strerror(-rc), (-rc));
Expand All @@ -64,7 +64,7 @@ int main(void) {
break;
}
break;
case CMT_IO_REASON_INSPECT:
case HTIF_YIELD_REASON_INSPECT:
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions sys-utils/rollup/rollup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ static int finish_request_and_get_next(bool accept) try {
f.accept_previous_request = accept;
if (cmt_rollup_finish(r, &f))
return 1;
if (f.next_request_type == CMT_IO_REASON_ADVANCE) {
if (f.next_request_type == HTIF_YIELD_REASON_ADVANCE) {
write_advance_state(r, &f);
} else if (f.next_request_type == CMT_IO_REASON_INSPECT) {
} else if (f.next_request_type == HTIF_YIELD_REASON_INSPECT) {
write_inspect_state(r, &f);
}
return 0;
Expand Down
Loading

0 comments on commit d4f6f73

Please sign in to comment.