Infernet
SDK
Reference
Inbox

Inbox

Git Source (opens in a new tab)

Inherits: Coordinated

Optionally stores container compute responses

Inherits Coordinated to use onlyCoordinator modifier for coordinator-permissioned functions

Allows Coordinator to store compute responses for lazy consumption with associated Subscription(s)

Allows any address to store compute responses for lazy consumptions without associated Subscription(s)

Structs

InboxItem

An inbox item contains data about a compute response

An inbox item must have an associated immutable timestamp of when it was first recorded

An inbox item must have a subscriptionId and an interval if it is storing the response to a Subscription

An inbox item may optionally have an input, output, and proof (compute response parameters)

Tightly-packed struct:

  • [timestamp, subscriptionId, interval]: [32, 32, 32] = 96
struct InboxItem {
    uint32 timestamp;
    uint32 subscriptionId;
    uint32 interval;
    bytes input;
    bytes output;
    bytes proof;
}

State Variables

items

containerId => delivering node address => array of delivered compute responses

Notice that validation of an InboxItem corresponding to a containerId is left to a downstream consumer

Even though we have a read function for items, we keep visbility public because it may be useful to collect InboxItem[] length

mapping(bytes32 => mapping(address => InboxItem[])) public items;

Functions

constructor

Initializes new Inbox

constructor(Registry registry) Coordinated(registry);

Parameters

NameTypeDescription
registryRegistryregistry contract

_write

Allows pushing an InboxItem to items

function _write(
    bytes32 containerId,
    address node,
    uint32 subscriptionId,
    uint32 interval,
    bytes calldata input,
    bytes calldata output,
    bytes calldata proof
) internal returns (uint256);

Parameters

NameTypeDescription
containerIdbytes32compute container ID
nodeaddressdelivering node address
subscriptionIduint32optional associated subscription ID (0 if none)
intervaluint32optional associated subscription interval (0 if none)
inputbytesoptional compute container input
outputbytesoptional compute container output
proofbytesoptional compute container proof

Returns

NameTypeDescription
<none>uint256index of newly-added inbox item

write

Allows any address to optimistically deliver compute responses

Zeroes out subscriptionId and interval since compute response is not associated to a subscription request

function write(bytes32 containerId, bytes calldata input, bytes calldata output, bytes calldata proof)
    external
    returns (uint256);

Parameters

NameTypeDescription
containerIdbytes32compute container ID
inputbytesoptional compute container input
outputbytesoptional compute container output
proofbytesoptional compute container proof

Returns

NameTypeDescription
<none>uint256index of newly-added inbox item

writeViaCoordinator

Allows Coordinator to store container compute response during deliverCompute() execution

node address is explicitly passed because tx.origin may not be accurate

msg.sender must be address(COORDINATOR) for authenticated write (storing subscriptionId, interval)

function writeViaCoordinator(
    bytes32 containerId,
    address node,
    uint32 subscriptionId,
    uint32 interval,
    bytes calldata input,
    bytes calldata output,
    bytes calldata proof
) external onlyCoordinator returns (uint256);

Parameters

NameTypeDescription
containerIdbytes32compute container ID
nodeaddressdelivering node address
subscriptionIduint32optional associated subscription ID (0 if none)
intervaluint32optional associated subscription interval (0 if none)
inputbytesoptional compute container input
outputbytesoptional compute container output
proofbytesoptional compute container proof

Returns

NameTypeDescription
<none>uint256index of newly-added inbox item

read

Read a stored InboxItem

By default, structs as values in public mappings return destructured parameters

This function allows returning a coerced InboxItem type instead of destructured parameters

function read(bytes32 containerId, address node, uint256 index) external view returns (InboxItem memory);

Parameters

NameTypeDescription
containerIdbytes32compute container ID
nodeaddressdelivering node address
indexuint256item index

Returns

NameTypeDescription
<none>InboxIteminbox item

Events

NewInboxItem

Emitted when a new InboxItem is added

event NewInboxItem(bytes32 indexed containerId, address indexed node, uint256 index);

Parameters

NameTypeDescription
containerIdbytes32compute container ID
nodeaddressdelivering node address
indexuint256index of newly-added inbox item