bftsmart.tom.server.defaultservices

## Class StateLog

- java.lang.Object
- - bftsmart.tom.server.defaultservices.StateLog

Direct Known Subclasses:
  DiskStateLog

    public class StateLog
    extends java.lang.Object

This classes serves as a log for the state associated with the last checkpoint, and the message batches received since the same checkpoint until the present. The state associated with the last checkpoint together with all the batches of messages received so far, comprises this replica current state

### Constructor Summary

Constructors
Constructor and Description
`StateLog(int id, byte[] initialState, byte[] initialHash)`
`StateLog(int id, int k)` Constructs a State log
`StateLog(int id, int k, byte[] initialState, byte[] initialHash)` Constructs a State log

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addMessageBatch(byte[][] commands, MessageContext[] msgCtx, int lastConsensusId)` Adds a message batch to the log.
`DefaultApplicationState` `getApplicationState(int cid, boolean setState)` Constructs a TransferableState using this log information
`int` `getLastCheckpointCID()` Retrieves the consensus ID for the last checkpoint
`int` `getLastCID()` Retrieves the consensus ID for the last messages batch delivered to the application
`CommandsInfo` `getMessageBatch(int cid)` Returns a batch of messages, given its correspondent consensus ID
`CommandsInfo[]` `getMessageBatches()` Retrieves all the stored batches kept since the last checkpoint
`int` `getNumBatches()` Retrieves the total number of stored batches kept since the last checkpoint
`byte[]` `getState()` Retrieves the state associated with the last checkpoint
`byte[]` `getStateHash()` Retrieves the hash of the state associated with the last checkpoint
`void` `newCheckpoint(byte[] state, byte[] stateHash, int lastConsensusId)` Sets the state associated with the last checkpoint, and updates the consensus ID associated with it
`void` `setLastCheckpointCID(int lastCheckpointCID)` Sets the consensus ID for the last checkpoint
`void` `setLastCID(int lastCID)` Sets the consensus ID for the last messages batch delivered to the application
`void` `update(DefaultApplicationState transState)` Updates this log, according to the information contained in the TransferableState object

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### StateLog

    public StateLog(int id,
                    int k,
                    byte[] initialState,
                    byte[] initialHash)

Constructs a State log

Parameters:
  `id` -
  `k` - The checkpoint period
  `initialState` -
  `initialHash` -

#### StateLog

    public StateLog(int id,
                    int k)

Constructs a State log

Parameters:
  `id` -
  `k` - The checkpoint period

#### StateLog

    public StateLog(int id,
                    byte[] initialState,
                    byte[] initialHash)

### Method Detail

#### newCheckpoint

    public void newCheckpoint(byte[] state,
                              byte[] stateHash,
                              int lastConsensusId)

Sets the state associated with the last checkpoint, and updates the consensus ID associated with it

Parameters:
  `state` - State associated with the last checkpoint
  `stateHash` -
  `lastConsensusId` -

#### setLastCheckpointCID

    public void setLastCheckpointCID(int lastCheckpointCID)

Sets the consensus ID for the last checkpoint

Parameters:
  `lastCheckpointCID` - Consensus ID for the last checkpoint

#### getLastCheckpointCID

    public int getLastCheckpointCID()

Retrieves the consensus ID for the last checkpoint

Returns:
  Consensus ID for the last checkpoint, or -1 if none was obtained

#### setLastCID

    public void setLastCID(int lastCID)

Sets the consensus ID for the last messages batch delivered to the application

Parameters:
  `lastCID` - the consensus ID for the last messages batch delivered to the application

#### getLastCID

    public int getLastCID()

Retrieves the consensus ID for the last messages batch delivered to the application

Returns:
  Consensus ID for the last messages batch delivered to the application

#### getState

    public byte[] getState()

Retrieves the state associated with the last checkpoint

Returns:
  State associated with the last checkpoint

#### getStateHash

    public byte[] getStateHash()

Retrieves the hash of the state associated with the last checkpoint

Returns:
  Hash of the state associated with the last checkpoint

#### addMessageBatch

    public void addMessageBatch(byte[][] commands,
                                MessageContext[] msgCtx,
                                int lastConsensusId)

Adds a message batch to the log. This batches should be added to the log in the same order in which they are delivered to the application. Only the 'k' batches received after the last checkpoint are supposed to be kept

Parameters:
  `commands` - The batch of messages to be kept.
  `msgCtx` - The message contexts related to the commands
  `lastConsensusId` -

#### getMessageBatch

    public CommandsInfo getMessageBatch(int cid)

Returns a batch of messages, given its correspondent consensus ID

Parameters:
  `cid` - Consensus ID associated with the batch to be fetched
Returns:
  The batch of messages associated with the batch correspondent consensus ID

#### getMessageBatches

    public CommandsInfo[] getMessageBatches()

Retrieves all the stored batches kept since the last checkpoint

Returns:
  All the stored batches kept since the last checkpoint

#### getNumBatches

    public int getNumBatches()

Retrieves the total number of stored batches kept since the last checkpoint

Returns:
  The total number of stored batches kept since the last checkpoint

#### getApplicationState

    public DefaultApplicationState getApplicationState(int cid,
                                                       boolean setState)

Constructs a TransferableState using this log information

Parameters:
  `cid` - Consensus ID correspondent to desired state
  `setState` -
Returns:
  TransferableState Object containing this log information

#### update

    public void update(DefaultApplicationState transState)

Updates this log, according to the information contained in the TransferableState object

Parameters:
  `transState` - TransferableState object containing the information which is used to updated this log