Skip to main content

MarloweLoad sub-protocol

The MarloweLoad sub-protocol is defined here:

Below is a state diagram for the MarloweLoad sub-protocol:

The MarloweLoad sub-protocol is used to incrementally push a contract into the contract store. It uses a stack-based representation of contracts which allows them to be built one node at a time in a depth-first traversal. The client is instructed to push N contract nodes by the server. The client sends up to N Push* messages and either stops to request more pushes or terminates when the contract is complete. Upon completion, the server sends the hash of the deeply merkleized version of the contract which can be used to lookup the contract in the store.

Sub-protocol states

Protocol stateAgencyParameterDescription
1. Processing nodeServerThe server is processing previous nodes from the client.
nodeThe stack of parent nodes that have been pushed.
2. CanPush n nodeClientThe client is pushing nodes to the server.
nThe number of pushes the client can still perform before requesting more.
nodeThe stack of parent nodes that have been pushed.
3. CompleteServerThe client has finished pushing nodes.
4. DoneNobodyThe protocol session is done.

node types

A node is a location in a contract that requires sub-contracts to be pushed. The following node types are defined:

NameDescription
RootThe root node. Requires one contract to be pushed to it.
Pay parentA pay node under some parent node. Requires one contract to be pushed to it.
IfL parentAn if node under some parent node focused on the left (then) clause. Requires two contracts to be pushed to it (then and else).
IfR parentAn if node under some parent node focused on the right (else) clause. Requires one contract to be pushed to it.
When parentA when node under some parent node. Accepts zero or more case and then requires one contingency contract to be pushed to it.
Case parentA case node under the parent node of its parent when node. Requires one contract to be pushed to it.
Let parentA let node under some parent node. Requires one contract to be pushed to it.
Assert parentAn assert node under some parent node. Requires one contract to be pushed to it.

Pop pseudo-state

There is a pseudo-state called Pop which is actually a function that resolves to one of the four states listed above depending on the current parent stack. The rules for computing the state Pop n node are as follows:

In case node isTransition toBecause
RootCompleteThere are no more empty locations in the contract to fill, so it is complete.
Pay parentPop n parentThe single continuation for the pay node has already been filled.
IfL parentCanPush n (IfR parent)Only the first sub-contract (then-clause) of the if node has been filled.
IfR parentPop n parentBoth sub-contracts of the if node have been filled.
When parentPop n parentThe contingency of the when node has been filled.
Case parentCanPush n (When parent)The parent of a case node is always a when, and it can receive more cases or a contingency clause.
Let parentPop n parentThe single continuation for the let node has already been filled.
Assert parentPop n parentThe single continuation for the assert node has already been filled.

The Pop state is used to compute the target state of a PushClose message.

Messages

MessageBegin stateEnd stateParameterDescription
1. Resume nProcessing nodeCanPush n nodeThe server clears the client to push n more nodes.
nThe number of nodes the client is allowed to push.
2. PushCloseCanPush (n + 1) nodePop n nodeThe client pushes a close node onto the stack, popping it to the next location that can receive more nodes.
3. PushPay account payee token valueCanPush (n + 1) nodeCanPush n (Pay node)The client pushes a pay node onto the stack.
accountThe account that sends the funds.
payeeThe account or party that receives the funds.
tokenThe currency and token name to send.
valueThe quantity to send expressed as a marlowe value expression.
4. PushIf condCanPush (n + 1) nodeCanPush n (IfL node)The client pushes an if node onto the stack.
condThe condition that determines which branch of the contract will be in effect.
5. PushWhen timeoutCanPush (n + 1) nodeCanPush n (When node)The client pushes a when node onto the stack.
timeoutThe time starting from which the contingency branch is in effect.
6. PushCase actionCanPush (n + 1) (When node)CanPush n (Case node)The client pushes a case node onto a parent when node.
actionThe action that would cause this branch to come into effect if no prior branches match.
7. PushLet id valueCanPush (n + 1) nodeCanPush n (Let node)The client pushes a let node onto the stack.
idThe name to give to the value.
valueThe value to evaluate.
8. PushAssert obsCanPush (n + 1) nodeCanPush n (Assert node)The client pushes an assert node onto the stack.
obsThe observation to evaluate.
9. RequestResumeCanPush 0 nodeProcessing nodeThe client has no pushes left and is requesting more.
10. AbortCanPush n nodeDoneThe client is prematurely ending the session.
11. Complete hashCompleteDoneThe server sends the hash of the contract and closes the session.
hashThe hash of the deeply-merkleized contract.