cartesi / machine-emulator

The off-chain implementation of the Cartesi Machine
GNU Lesser General Public License v3.0
64 stars 33 forks source link

Remove magic constants for advance-state and inspect-state #45

Closed diegonehab closed 5 months ago

diegonehab commented 1 year ago

Context

When a rolling Cartesi machine returns from a manual yield with the new request, it checks the value of the least significant 32 bits of HTIF fromhost CSR to know if it received an advance-state request (value 0) or an inspect-state request (value 1).

The /dev/rollup header rollup.h defines constants for these magic numbers, but these constants do not exist in other APIs that may need them:

#define CARTESI_ROLLUP_ADVANCE_STATE 0
#define CARTESI_ROLLUP_INSPECT_STATE 1

Perhaps these should be defined instead in the /dev/yield driver yield.h, since it already defines constants

#define HTIF_YIELD_REASON_PROGRESS 0
#define HTIF_YIELD_REASON_RX_ACCEPTED 1
#define HTIF_YIELD_REASON_RX_REJECTED 2
#define HTIF_YIELD_REASON_TX_VOUCHER 3
#define HTIF_YIELD_REASON_TX_NOTICE 4
#define HTIF_YIELD_REASON_TX_REPORT 5
#define HTIF_YIELD_REASON_TX_EXCEPTION 6

The Cartesi Machine documentation lists them under the yield driver as:

HTIF_YIELD_ADVANCE_STATE  0
HTIF_YIELD_INSPECT_STATE  1

Possible solutions

The machine API (C++, C, Lua) should include these constants.

How can we make these constants available in JSONRPC?

Subtasks

vfusco commented 5 months ago

This was done in https://github.com/cartesi/machine-emulator/pull/136