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
Name | Type | Description |
---|---|---|
registry | Registry | registry 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
Name | Type | Description |
---|---|---|
containerId | bytes32 | compute container ID |
node | address | delivering node address |
subscriptionId | uint32 | optional associated subscription ID (0 if none) |
interval | uint32 | optional associated subscription interval (0 if none) |
input | bytes | optional compute container input |
output | bytes | optional compute container output |
proof | bytes | optional compute container proof |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | index 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
Name | Type | Description |
---|---|---|
containerId | bytes32 | compute container ID |
input | bytes | optional compute container input |
output | bytes | optional compute container output |
proof | bytes | optional compute container proof |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | index 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
Name | Type | Description |
---|---|---|
containerId | bytes32 | compute container ID |
node | address | delivering node address |
subscriptionId | uint32 | optional associated subscription ID (0 if none) |
interval | uint32 | optional associated subscription interval (0 if none) |
input | bytes | optional compute container input |
output | bytes | optional compute container output |
proof | bytes | optional compute container proof |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | index 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
Name | Type | Description |
---|---|---|
containerId | bytes32 | compute container ID |
node | address | delivering node address |
index | uint256 | item index |
Returns
Name | Type | Description |
---|---|---|
<none> | InboxItem | inbox item |
Events
NewInboxItem
Emitted when a new InboxItem is added
event NewInboxItem(bytes32 indexed containerId, address indexed node, uint256 index);
Parameters
Name | Type | Description |
---|---|---|
containerId | bytes32 | compute container ID |
node | address | delivering node address |
index | uint256 | index of newly-added inbox item |