Skip to content

Module dev_process.erl

This module contains the device implementation of AO processes in AO-Core.

Description

The core functionality of the module is in 'routing' requests for different functionality (scheduling, computing, and pushing messages) to the appropriate device. This is achieved by swapping out the device of the process message with the necessary component in order to run the execution, then swapping it back before returning. Computation is supported as a stack of devices, customizable by the user, while the scheduling device is (by default) a single device.

This allows the devices to share state as needed. Additionally, after each computation step the device caches the result at a path relative to the process definition itself, such that the process message's ID can act as an immutable reference to the process's growing list of interactions. See dev_process_cache for details.

The external API of the device is as follows:

   GET /ID/Schedule:                Returns the messages in the schedule
   POST /ID/Schedule:               Adds a message to the schedule
   GET /ID/Compute/[IDorSlotNum]:   Returns the state of the process after
                                    applying a message
   GET /ID/Now:                     Returns the <code>/Results</code> key of the latest
                                    computed message

An example process definition will look like this:

       Device: Process/1.0
       Scheduler-Device: Scheduler/1.0
       Execution-Device: Stack/1.0
       Execution-Stack: "Scheduler/1.0", "Cron/1.0", "WASM/1.0", "PoDA/1.0"
       Cron-Frequency: 10-Minutes
       WASM-Image: WASMImageID
       PoDA:
           Device: PoDA/1.0
           Authority: A
           Authority: B
           Authority: C
           Quorum: 2

Runtime options: Cache-Frequency: The number of assignments that will be computed before the full (restorable) state should be cached. Cache-Keys: A list of the keys that should be cached for all assignments, in addition to /Results.

Function Index

aos_browsable_state_test_/0*
aos_compute_test_/0*
aos_persistent_worker_benchmark_test_/0*
aos_state_access_via_http_test_/0*
aos_state_patch_test_/0*
as_process/2Change the message to for that has the device set as this module.
compute/3Compute the result of an assignment applied to the process state, if it is the next message.
compute_slot/5*Compute a single slot for a process, given an initialized state.
compute_to_slot/5*Continually get and apply the next assignment from the scheduler until we reach the target slot that the user has requested.
default_device/3*Returns the default device for a given piece of functionality.
default_device_index/1*
dev_test_process/0Generate a device that has a stack of two dev_tests for execution.
do_test_restore/0
ensure_loaded/3*Ensure that the process message we have in memory is live and up-to-date.
ensure_process_key/2Helper function to store a copy of the process key in the message.
get_scheduler_slot_test/0*
http_wasm_process_by_id_test/0*
info/1When the info key is called, we should return the process exports.
init/0
init/3*Before computation begins, a boot phase is required.
next/3*
now/3Returns the known state of the process at either the current slot, or the latest slot in the cache depending on the process_now_from_cache option.
now_results_test_/0*
persistent_process_test/0*
prior_results_accessible_test_/0*
process_id/3Returns the process ID of the current process.
push/3Recursively push messages to the scheduler until we find a message that does not lead to any further messages being scheduled.
recursive_path_resolution_test/0*
restore_test_/0*Manually test state restoration without using the cache.
run_as/4*Run a message against Msg1, with the device being swapped out for the device found at Key.
schedule/3Wraps functions in the Scheduler device.
schedule_aos_call/2
schedule_aos_call/3
schedule_on_process_test_/0*
schedule_test_message/3*
schedule_test_message/4*
schedule_wasm_call/3*
schedule_wasm_call/4*
simple_wasm_persistent_worker_benchmark_test/0*
slot/3
snapshot/3
store_result/5*Store the resulting state in the cache, potentially with the snapshot key.
test_aos_process/0Generate a process message with a random number, and the dev_wasm device for execution.
test_aos_process/1
test_aos_process/2*
test_base_process/0*Generate a process message with a random number, and no executor.
test_base_process/1*
test_device_compute_test/0*
test_wasm_process/1
test_wasm_process/2*
wasm_compute_from_id_test/0*
wasm_compute_test/0*

Function Details

aos_browsable_state_test_/0 *

aos_browsable_state_test_() -> any()

aos_compute_test_/0 *

aos_compute_test_() -> any()

aos_persistent_worker_benchmark_test_/0 *

aos_persistent_worker_benchmark_test_() -> any()

aos_state_access_via_http_test_/0 *

aos_state_access_via_http_test_() -> any()

aos_state_patch_test_/0 *

aos_state_patch_test_() -> any()

as_process/2

as_process(Msg1, Opts) -> any()

Change the message to for that has the device set as this module. In situations where the key that is run_as returns a message with a transformed device, this is useful.

compute/3

compute(Msg1, Msg2, Opts) -> any()

Compute the result of an assignment applied to the process state, if it is the next message.

compute_slot/5 *

compute_slot(ProcID, State, RawInputMsg, ReqMsg, Opts) -> any()

Compute a single slot for a process, given an initialized state.

compute_to_slot/5 *

compute_to_slot(ProcID, Msg1, Msg2, TargetSlot, Opts) -> any()

Continually get and apply the next assignment from the scheduler until we reach the target slot that the user has requested.

default_device/3 *

default_device(Msg1, Key, Opts) -> any()

Returns the default device for a given piece of functionality. Expects the process/variant key to be set in the message. The execution-device must be set in all processes aside those marked with ao.TN.1 variant. This is in order to ensure that post-mainnet processes do not default to using infrastructure that should not be present on nodes in the future.

default_device_index/1 *

default_device_index(X1) -> any()

dev_test_process/0

dev_test_process() -> any()

Generate a device that has a stack of two dev_tests for execution. This should generate a message state has doubled Already-Seen elements for each assigned slot.

do_test_restore/0

do_test_restore() -> any()

ensure_loaded/3 *

ensure_loaded(Msg1, Msg2, Opts) -> any()

Ensure that the process message we have in memory is live and up-to-date.

ensure_process_key/2

ensure_process_key(Msg1, Opts) -> any()

Helper function to store a copy of the process key in the message.

get_scheduler_slot_test/0 *

get_scheduler_slot_test() -> any()

http_wasm_process_by_id_test/0 *

http_wasm_process_by_id_test() -> any()

info/1

info(Msg1) -> any()

When the info key is called, we should return the process exports.

init/0

init() -> any()

init/3 *

init(Msg1, Msg2, Opts) -> any()

Before computation begins, a boot phase is required. This phase allows devices on the execution stack to initialize themselves. We set the Initialized key to True to indicate that the process has been initialized.

next/3 *

next(Msg1, Msg2, Opts) -> any()

now/3

now(RawMsg1, Msg2, Opts) -> any()

Returns the known state of the process at either the current slot, or the latest slot in the cache depending on the process_now_from_cache option.

now_results_test_/0 *

now_results_test_() -> any()

persistent_process_test/0 *

persistent_process_test() -> any()

prior_results_accessible_test_/0 *

prior_results_accessible_test_() -> any()

process_id/3

process_id(Msg1, Msg2, Opts) -> any()

Returns the process ID of the current process.

push/3

push(Msg1, Msg2, Opts) -> any()

Recursively push messages to the scheduler until we find a message that does not lead to any further messages being scheduled.

recursive_path_resolution_test/0 *

recursive_path_resolution_test() -> any()

restore_test_/0 *

restore_test_() -> any()

Manually test state restoration without using the cache.

run_as/4 *

run_as(Key, Msg1, Msg2, Opts) -> any()

Run a message against Msg1, with the device being swapped out for the device found at Key. After execution, the device is swapped back to the original device if the device is the same as we left it.

schedule/3

schedule(Msg1, Msg2, Opts) -> any()

Wraps functions in the Scheduler device.

schedule_aos_call/2

schedule_aos_call(Msg1, Code) -> any()

schedule_aos_call/3

schedule_aos_call(Msg1, Code, Opts) -> any()

schedule_on_process_test_/0 *

schedule_on_process_test_() -> any()

schedule_test_message/3 *

schedule_test_message(Msg1, Text, Opts) -> any()

schedule_test_message/4 *

schedule_test_message(Msg1, Text, MsgBase, Opts) -> any()

schedule_wasm_call/3 *

schedule_wasm_call(Msg1, FuncName, Params) -> any()

schedule_wasm_call/4 *

schedule_wasm_call(Msg1, FuncName, Params, Opts) -> any()

simple_wasm_persistent_worker_benchmark_test/0 *

simple_wasm_persistent_worker_benchmark_test() -> any()

slot/3

slot(Msg1, Msg2, Opts) -> any()

snapshot/3

snapshot(RawMsg1, Msg2, Opts) -> any()

store_result/5 *

store_result(ProcID, Slot, Msg3, Msg2, Opts) -> any()

Store the resulting state in the cache, potentially with the snapshot key.

test_aos_process/0

test_aos_process() -> any()

Generate a process message with a random number, and the dev_wasm device for execution.

test_aos_process/1

test_aos_process(Opts) -> any()

test_aos_process/2 *

test_aos_process(Opts, Stack) -> any()

test_base_process/0 *

test_base_process() -> any()

Generate a process message with a random number, and no executor.

test_base_process/1 *

test_base_process(Opts) -> any()

test_device_compute_test/0 *

test_device_compute_test() -> any()

test_wasm_process/1

test_wasm_process(WASMImage) -> any()

test_wasm_process/2 *

test_wasm_process(WASMImage, Opts) -> any()

wasm_compute_from_id_test/0 *

wasm_compute_from_id_test() -> any()

wasm_compute_test/0 *

wasm_compute_test() -> any()