consensus

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBlockIntervalSec = int64(1)

DefaultBlockIntervalSec is the default block generation interval in seconds.

Variables

View Source
var (
	// BlockIntervalSec is the block genration interval in seconds.
	BlockIntervalSec = DefaultBlockIntervalSec

	// BlockInterval is the maximum block generation time limit.
	BlockInterval = time.Second * time.Duration(DefaultBlockIntervalSec)
)
View Source
var ConsensusName = []string{"dpos", "raft", "sbp"}

Functions

func InitBlockInterval

func InitBlockInterval(blockIntervalSec int64)

InitBlockInterval initializes block interval parameters.

func Start

func Start(c Consensus)

Start run a selected consesus service.

func Stop

func Stop(c Consensus)

Stop shutdown consensus service.

Types

type BlockFactory

type BlockFactory interface {
	Start()
	JobQueue() chan<- interface{}
}

BlockFactory is an interface for a block factory implementation.

type ChainConsensus

type ChainConsensus interface {
	GetType() ConsensusType
	IsTransactionValid(tx *types.Tx) bool
	VerifyTimestamp(block *types.Block) bool
	VerifySign(block *types.Block) error
	IsBlockValid(block *types.Block, bestBlock *types.Block) error
	Update(block *types.Block)
	Save(tx db.Transaction) error
	NeedReorganization(rootNo types.BlockNo) bool
	Info() string
}

ChainConsensus includes chainstatus and validation API.

type ChainDB added in v0.9.4

type ChainDB interface {
	GetBestBlock() (*types.Block, error)
	GetBlockByNo(blockNo types.BlockNo) (*types.Block, error)
	GetGenesisInfo() *types.Genesis
	Get(key []byte) []byte
	NewTx() db.Transaction
}

ChainDB is a reader interface for the ChainDB.

type Consensus

type Consensus interface {
	ChainConsensus
	ConsensusAccessor
	Ticker() *time.Ticker
	QueueJob(now time.Time, jq chan<- interface{})
	BlockFactory() BlockFactory
	QuitChan() chan interface{}
}

Consensus is an interface for a consensus implementation.

type ConsensusAccessor added in v1.0.0

type ConsensusAccessor interface {
	ConsensusInfo() *types.ConsensusInfo
}

type ConsensusType added in v1.0.0

type ConsensusType int
const (
	ConsensusDPOS ConsensusType = iota
	ConsensusRAFT
	ConsensusSBP
)

type Constructor added in v0.9.4

type Constructor func() (Consensus, error)

Constructor represents a function returning the Consensus interfactor for each implementation.

type ErrorConsensus

type ErrorConsensus struct {
	Msg string
	Err error
}

ErrorConsensus is a basic error struct for consensus modules.

func (ErrorConsensus) Error

func (e ErrorConsensus) Error() string

type Info added in v1.0.0

type Info struct {
	Type   string
	Status *json.RawMessage `json:",omitempty"`
}

Info represents an information for a consensus implementation.

func NewInfo added in v1.0.0

func NewInfo(name string) *Info

NewInfo returns a new Info with name.

func (*Info) AsJSON added in v1.0.0

func (i *Info) AsJSON() string

AsJSON() returns i as a JSON string

Directories

Path Synopsis
sbp

Jump to

Keyboard shortcuts

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