Skip to content

Backup & Rollback States for each function

2 methods to solve this

Method 1: Rollback

  1. Before executing the first line of code in a function, backup all state variable's values to backup variables
  2. Change nothing, allow function to change the state variables directly
  3. If a require statement fails
    1. Go to a rollback state
    2. Revert all state variables to the values in the backup variables
    3. Go to FunctionFailedEndState, then go to the LoopState
  4. if the function completes successfully, then go to FunctionSuccessEndState and then to the LoopState

Method 2: Commit

  1. Change the function to write to temporary state variables (similar to the backup variables)
  2. Copy the current state variables into the temporary variables
  3. If a require statement fails
    1. Go to FunctionFailedEndState, then go to the LoopState
  4. if the function completes successfully
    1. Go to the commit state
    2. Copy all temporary variables to the state variables
    3. Go to FunctionSuccessEndState and then to the LoopState
Edited by Jon Shahen