pub trait Aux {
    type Prepared: AuxPrepared;

    fn prepare(self) -> Option<Self::Prepared>;
    fn rollback(self);
}
Expand description

An auxiliary transaction that gets co-committed with the STM transaction, unless the STM transaction is aborted or has to be retried, in which case the auxiliary transaction is rolled back.

One potential use case is to model the account state as a Sparse Merkle trie backed by a key-value store, and accumulate writes during the execution of a block in-memory, then when the commit comes, instead of flushing the changes to disk, we could keep the changeset in memory until the block is finalised.

To manage the tree of changesets, we can create new instances of the Aux construct before passing it to the block execution, where the instance would be the new leaf, and commit just writes to its in-memory staging area. This way we don’t have to return any value from commit, to represent the changeset.

When a block is finalised, we can take the root of the changeset tree and apply it for real on the database, and discard any orphans.

Required Associated Types

Required Methods

Prepare for commit. If the transaction cannot be committed, roll it back and return None, in which case the STM transaction will be retried. This is an optimisation to delay taking out any exclusive locks.

Rollback the auxiliary transaction if the STM transaction was aborted, or it’s going to be retried.

Implementors