cas

package
v0.0.0-...-5630099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCASFailure  = errors.New("CAS failure")
	ErrKeyNotFound = errors.New("key not found")
)

Errors related to the state.

Functions

This section is empty.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application implements the Tendermint ABCI.

func NewApplication

func NewApplication(initial io.Reader, persist io.WriteCloser, logger log.Logger) (*Application, error)

NewApplication returns a Tendermint application server, implementing the ABCI. If initial is non-nil, initial state is populated from it. If persist is non-nil, state is persisted there on each Tendermint commit.

func (*Application) BeginBlock

BeginBlock implements ABCI and demarcates the start of a block (of transactions) in the chain.

func (*Application) CheckTx

func (a *Application) CheckTx(p []byte) (response tendermintabci.ResponseCheckTx)

CheckTx implements ABCI and is invoked before DeliverTx. Invalid transactions can be rejected before they're persisted or gossiped. This is an optimization step: simply returning OK won't affect correctness.

func (*Application) Commit

func (a *Application) Commit() (response tendermintabci.ResponseCommit)

Commit implements ABCI and persists the current state. A hash of that state is returned to the caller, i.e. the Tendermint core machinery.

func (*Application) DeliverTx

func (a *Application) DeliverTx(p []byte) (response tendermintabci.ResponseDeliverTx)

DeliverTx implements ABCI and is used for all writes.

func (*Application) EndBlock

EndBlock implements ABCI and demarcates the end of a block (of transactions) in the chain.

func (*Application) Info

Info implements ABCI and is called by Tendermint prior to InitChain as a sort of handshake.

When either the app or Tendermint restarts, they need to sync to a common chain height. When an ABCI connection is first established, Tendermint will call Info on the Query connection. The response should contain the LastBlockHeight and LastBlockAppHash; the former is the last block for which the app ran Commit successfully, and the latter is the response from that Commit.

Using this information, Tendermint will determine what needs to be replayed, if anything, against the app, to ensure both Tendermint and the app are synced to the latest block height. If the app returns a LastBlockHeight of 0, Tendermint will just replay all blocks.

The data and version fields may contain arbitrary app-specific information.

func (*Application) InitChain

InitChain implements ABCI and is called once, at genesis.

Certain request parameters come from the genesis file. The time is the genesis time; if this is relevant to the application, it must be preferred to system time. Chain ID uniquely identifies the blockchain. AppStateBytes is the Amino/JSON-serialized initial application state.

ConsensusParams describe attributes of Tendermint behavior. If the application wants to change any of them, it can include modified values in its response. Those modifications must be deterministic, all nodes must return the same params for the same InitChain.

If the application returns an empty validator set, the initial validator set will be the validators proposed in the request. If the application returns a nonempty validator set, the initial validator set will be those validators, regardless of what was proposed in the request. This allows the app to decide if it wants to accept the initial validators proposed by Tendermint or if it wants to use a different one. For example, validators may be computed based on some application-specific information in the genesis file.

func (*Application) Query

Query implements ABCI and is used for reads. In this application, we interpret the data as the key, and return the current value.

func (*Application) SetOption

SetOption implements ABCI and configures non-consensus-critical (i.e. non-deterministic) aspects of the application. For example, min-fee: 100fermion could set the minimum fee required for CheckTx; but not DeliverTx, as that would be consensus critical.

type State

type State struct {
	// contains filtered or unexported fields
}

State provides a key-value store with compare-and-swap mutability. Persistence is achieved by manually invoking Commit (and Restore).

func NewState

func NewState() *State

NewState returns a new, empty state. Load persisted data, if any, via Restore.

func (*State) Commit

func (s *State) Commit(wc io.WriteCloser) (err error)

Commit the current state to the WriteCloser. On success, close the WriteCloser, increment the commit count, and update the last commit hash.

func (*State) Commits

func (s *State) Commits() int64

Commits returns the number of successful commits. This value is persisted.

func (*State) CompareAndSwap

func (s *State) CompareAndSwap(key string, old, new []byte) error

CompareAndSwap sets key to new if and only if its current value is old. Returns ErrCASFailure if the current value is not old.

func (*State) Get

func (s *State) Get(key string) ([]byte, error)

Get the value associated with the key. Returns ErrKeyNotFound if not found.

func (*State) Hash

func (s *State) Hash() []byte

Hash returns a SHA256 hash of the state at time of last commit. This value is not persisted, but is recalculated on Restore.

func (*State) Restore

func (s *State) Restore(r io.Reader) (err error)

Restore state from the Reader, overwriting any current state. On success, update commit count from the serialized data, and writes the last commit hash based on its own computation of a hash.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL