This proposal relates to improving the read-only system in the Massa node.
Needs
- Simulate an execution to estimate the gas usage of a call/executeSC
- Simulate an execution to estimate coin costs
- Call a read-only SC function to read its result for free
- Automated smart dapp backend testing (eg. multi-SC)
- Simulate an execution for debugging
- Simulate an execution sequence as part of IDE tooling
Currently the system is limited:
- issues with nested calls for non-existing addresses
- no easy way to estimate coin consumption
- no return values from read-only executions
- gas inconsistencies
- no automated testing features / limited debugging capabilities , especially multi-contract
- no way to atomically execute multiple read-only runs at the same slot
Solution
New endpoint
- read_only_sequences([[ReadOnlySequenceRequestItem]]) → ReadOnlySequenceResult or Error
- ReadOnlySequenceRequestItem is an enum of different possible requests
- ReadOnlySequenceResult { execution_slot: Slot, items: [[ReadOnlySequenceItemReturn]]}
- The inner array states a list of tasks to run consecutively in the same temporary context
- The outer array states allows running a set of independent task lists at the same slot (context is reset between each item)
Supported requests
- get_balance { addr } returns { addr, balance }
- get_bytecode { addr } returns { addr, Option }
- get_datastore_entry { addr, key } returns { addr, key, value: Option }
- has_datastore_entry { addr, key } returns { addr, key, bool }
- list_keys { addr, key_start, key_start_included, key_end, key_end_included, prefix, max_count } returns {addr, keys: [byte]}
- set_balance { addr, balance } returns {}
- set_bytecode {addr, bytecode} returns {}
- set_datastore_item {item, key, value} returns {}
- del_datastore_item {addr, key} returns {}
- execute_operation {call_stack: [address], op: Operation} returns {outcome: ExecutionResult, state_changes: […], return_value: [byte], gas_usage}
(limited total item count and gas for security)
Usage examples
Estimate gas and coins simultaneously
- set the coins available to the sender address to a high value
- make sure the SC reimburses excess coins
- run the operation
- count how much gas was spent, how much coins were spent
- recover the output value
Simulate a full dapp for integration testing
- spin a local sandbox node or use buildnet/mainnet
- simulate the deployment of multiple smart contracts
- set the right initial conditions
- run a sequence of calls on the different smart contracts
- read the output state