Skip to content

Instantly share code, notes, and snippets.

@jamii
Created February 8, 2012 14:37
Show Gist options
  • Save jamii/1770128 to your computer and use it in GitHub Desktop.
Save jamii/1770128 to your computer and use it in GitHub Desktop.

Entities

An entity is an account, order, market, contract, deposit or withdrawal. Every entity has a unique uid. Once created entities are never deleted.

Error handling conventions

We distinguish between recoverable errors and failures.

Recoverable errors are exceptions of type Invalid_transition. If this exception reaches the top level then piston will return an rpc error and continue processing. Any other exceptions will cause piston to die. Deepred will then mark the offending event as unprocessable and replay from a snapshot.

Functions in Account, Order, Market, Contract, Deposit and Withdrawal must be atomic ie they either:

  • mutate one or more entities and complete successfully
  • mutate one or more entities and fail, crashing the process
  • undo their changes and raise Invalid_transition

The sole exception to this is tombstone values - entities which are created during the function and are marked as failed eg Market.order_create may create an order, mark it as rejected and raise Invalid_transition

Multiple atomic actions may be combined using Transition.recover_with or Transition.unrecoverable. The first allows registering a cleanup function to be executed in case of an Invalid_transition. The second converts Invalid_transition to Failure, crashing the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment