Class SelectorsStateManager

java.lang.Object
org.hyperledger.besu.plugin.services.txselection.SelectorsStateManager

public class SelectorsStateManager extends Object
Manages the state of transaction selectors (including the plugin transaction selector PluginTransactionSelector) during the block creation process. Some selectors have a state, for example the amount of gas used by selected pending transactions so far, and changes made to the state must be only commited after the evaluated pending transaction has been definitely selected for inclusion, until that point it will be always possible to rollback the changes to the state and return the previous commited state.
  • Constructor Details

    • SelectorsStateManager

      public SelectorsStateManager()
      Create an empty selectors state manager, here to make javadoc linter happy.
  • Method Details

    • createSelectorState

      public <S, D extends SelectorsStateManager.StateDuplicator<S>> void createSelectorState(TransactionSelector selector, S initialState, D duplicator)
      Create, initialize and track the state for a selector.

      Call to this method must be performed before the block selection is stated with blockSelectionStarted(), otherwise it fails.

      Type Parameters:
      S - the type of the selector state
      D - the type of the state duplicator
      Parameters:
      selector - the selector
      initialState - the initial value of the state
      duplicator - the state duplicator
    • blockSelectionStarted

      public void blockSelectionStarted()
      Called at the start of block selection, when the initialization is done, to prepare a new working state based on the initial state.

      After this method is called, it is not possible to call anymore createSelectorState(TransactionSelector, Object, StateDuplicator)

    • getSelectorWorkingState

      public <T> T getSelectorWorkingState(TransactionSelector selector)
      Get the working state for the specified selector
      Type Parameters:
      T - the type of the selector state
      Parameters:
      selector - the selector
      Returns:
      the working state of the selector
    • setSelectorWorkingState

      public <T> void setSelectorWorkingState(TransactionSelector selector, T newState)
      set the working state for the specified selector
      Type Parameters:
      T - the type of the selector state
      Parameters:
      selector - the selector
      newState - the new state
    • getSelectorCommittedState

      public <T> T getSelectorCommittedState(TransactionSelector selector)
      Get the commited state for the specified selector
      Type Parameters:
      T - the type of the selector state
      Parameters:
      selector - the selector
      Returns:
      the commited state of the selector
    • commit

      public void commit()
      Commit the current working state and prepare a new working state based on the just commited state
    • rollback

      public void rollback()
      Discards the current working state and prepare a new working state based on the just commited state