consensus

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const DataDirName = "consensus"

Variables

This section is empty.

Functions

func Init

func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error

Types

type Config

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

Config is general consensus node config.

Default values:

- rpcListenPort 26657 - p2pListenPort 26656 - proxyAppName lightchain

func NewConfig

func NewConfig(dataDir string, rpcListenPort uint, p2pListenPort uint, proxyAppName string, metrics bool) (Config, error)

func (Config) RPCListenPort

func (c Config) RPCListenPort() uint

func (Config) TendermintConfigFilePath

func (c Config) TendermintConfigFilePath() string

type Node

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

func NewNode

func NewNode(cfg *Config, registry *prometheus.Registry) (*Node, error)

func (*Node) IsRunning added in v1.2.0

func (n *Node) IsRunning() bool

func (*Node) Start

func (n *Node) Start(ethRPCClient *ethRpc.Client, db *database.Database) error

func (*Node) Stop

func (n *Node) Stop() error

type TendermintABCI

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

TendermintABCI is the main hook of application layer (blockchain) for connecting to consensus (Tendermint) using ABCI.

Tendermint ABCI requires three connections to the application to handle the different message types. Connections:

Consensus Connection - InitChain, BeginBlock, DeliverTx, EndBlock, Commit
Mempool Connection - CheckTx
Info Connection - Info, SetOption, Query

Flow:

  1. BeginBlock
  2. CheckTx
  3. DeliverTx*
  4. EndBlock
  5. Commit
  6. CheckTx (clean mempool from TXs not included in committed block)

Tendermint runs CheckTx and DeliverTx concurrently with each other, though on distinct ABCI connections - the mempool connection and the consensus connection.

Full ABCI specs: https://tendermint.com/docs/spec/abci/abci.html

func NewTendermintABCI

func NewTendermintABCI(db *database.Database, ethRPCClient *rpc.Client, metrics metrics.Metrics) (*TendermintABCI, error)

func (*TendermintABCI) BeginBlock

BeginBlock signals the beginning of a new block.

The header contains the height, timestamp, and more - it exactly matches the Tendermint block header. The `req.LastCommitInfo` and `req.ByzantineValidators` attributes can be used to determine rewards and punishments for the validators.

Response:

  • Optional Key-Value tags for filtering and indexing

func (*TendermintABCI) CheckTx

func (abci *TendermintABCI) CheckTx(txBytes []byte) tmtAbciTypes.ResponseCheckTx

CheckTx validates a mempool transaction, prior to broadcasting or proposing.

CheckTx should perform stateful but light-weight checks of the validity of the transaction (like checking signatures and account balances), but need not execute in full (like running a smart contract).

The application should maintain a separate state to support CheckTx. This state can be reset to the latest committed state during Persist. Before calling Persist, Tendermint will lock and flush the mempool, ensuring that all existing CheckTx are responded to and no new ones can begin. After Persist, the mempool will rerun CheckTx for all remaining transactions, throwing out any that are no longer valid. Then the mempool will unlock and start sending CheckTx again.

Response:

  • Response code
  • Optional Key-Value tags for filtering and indexing

func (*TendermintABCI) Commit

Commit persists the application state.

Response:

  • Return a Merkle root hash of the application state. It's critical that all application instances return the same hash. If not, they will not be able to agree on the next block, because the hash is included in the next block!

func (*TendermintABCI) DeliverTx

func (abci *TendermintABCI) DeliverTx(txBytes []byte) tmtAbciTypes.ResponseDeliverTx

DeliverTx executes the transaction against Ethereum block's work state.

Response:

  • If the transaction is valid, returns CodeType.OK
  • Keys and values in Tags must be UTF-8 encoded strings E.g: ("account.owner": "Bob", "balance": "100.0", "time": "2018-01-02T12:30:00Z")

func (*TendermintABCI) EndBlock

EndBlock signals the end of a block.

An opportunity to propose changes to a validator set.

Response:

  • Validator updates returned for block H
  • apply to the NextValidatorsHash of block H+1
  • apply to the ValidatorsHash (and thus the validator set) for block H+2
  • apply to the RequestBeginBlock.LastCommitInfo (ie. the last validator set) for block H+3
  • Consensus params returned for block H apply for block H+1

func (*TendermintABCI) Info

Info returns information about the last height and app_hash to the tmtCfg engine

func (*TendermintABCI) InitChain

InitChain is called upon genesis.

Can be used to define validators set and consensus params on the application side.

Response:

  • If `ResponseInitChain.Validators` is empty, the initial validator set will be the `RequestInitChain.Validators`

func (*TendermintABCI) Query

Query for data from the application at current or past height.

func (*TendermintABCI) ResetBlockState added in v0.10.0

func (abci *TendermintABCI) ResetBlockState() error

ResetBlockState resets the in-memory block's processing state.

func (*TendermintABCI) RewardReceiver added in v0.10.0

func (abci *TendermintABCI) RewardReceiver() common.Address

RewardReceiver returns the receiving address based on the selected strategy

func (*TendermintABCI) SetOption

SetOption sets non-consensus critical application specific options.

E.g. Key="min-fee", Value="100fermion" could set the minimum fee required for CheckTx (but not DeliverTx - that would be consensus critical).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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