raft

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: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMarginChainDiff = 1
	DefaultTickMS          = time.Millisecond * 30
)

Variables

View Source
var (
	RaftTick           = DefaultTickMS
	RaftSkipEmptyBlock = false
)
View Source
var (
	ErrInvalidRaftID     = errors.New("invalid raft raftID")
	ErrDupRaftUrl        = errors.New("duplicated raft bp urls")
	ErrRaftEmptyTLSFile  = errors.New("cert or key file name is empty")
	ErrNotHttpsURL       = errors.New("url scheme is not https")
	ErrURLInvalidScheme  = errors.New("url has invalid scheme")
	ErrURLInvalidPort    = errors.New("url must have host:port style")
	ErrInvalidRaftBPID   = errors.New("raft bp raftID is not ordered. raftID must start with 1 and be sorted")
	ErrDupBP             = errors.New("raft bp description is duplicated")
	ErrInvalidRaftPeerID = errors.New("peerID of current raft bp is not equals to p2p configure")
)
View Source
var (
	ErrBFQuit = errors.New("block factory quit")
)

Functions

func GetConstructor

GetConstructor build and returns consensus.Constructor from New function.

func GetName

func GetName() string

GetName returns the name of the consensus.

func MaxUint64

func MaxUint64(x, y uint64) uint64

Types

type BlockFactory

type BlockFactory struct {
	*component.ComponentHub
	consensus.ChainDB

	ID string
	// contains filtered or unexported fields
}

BlockFactory implments a raft block factory which generate block each cfg.Consensus.BlockInterval if this node is leader of raft

This can be used for testing purpose.

func New

New returns a BlockFactory.

func (*BlockFactory) BlockFactory

func (bf *BlockFactory) BlockFactory() consensus.BlockFactory

BlockFactory returns r itself.

func (*BlockFactory) ConsensusInfo

func (bf *BlockFactory) ConsensusInfo() *types.ConsensusInfo

func (*BlockFactory) GetType

func (bf *BlockFactory) GetType() consensus.ConsensusType

func (*BlockFactory) Info

func (bf *BlockFactory) Info() string

Info retuns an empty string.

func (*BlockFactory) InitCluster

func (bf *BlockFactory) InitCluster(cfg *config.Config) error

func (*BlockFactory) IsBlockValid

func (bf *BlockFactory) IsBlockValid(block *types.Block, bestBlock *types.Block) error

IsBlockValid checks the consensus level validity of a block.

func (*BlockFactory) IsTransactionValid

func (bf *BlockFactory) IsTransactionValid(tx *types.Tx) bool

IsTransactionValid checks the onsensus level validity of a transaction

func (*BlockFactory) JobQueue

func (bf *BlockFactory) JobQueue() chan<- interface{}

JobQueue returns the queue for block production triggering.

func (*BlockFactory) NeedReorganization

func (bf *BlockFactory) NeedReorganization(rootNo types.BlockNo) bool

NeedReorganization has nothing to do.

func (*BlockFactory) QueueJob

func (bf *BlockFactory) QueueJob(now time.Time, jq chan<- interface{})

QueueJob send a block triggering information to jq.

func (*BlockFactory) QuitChan

func (bf *BlockFactory) QuitChan() chan interface{}

QuitChan returns the channel from which consensus-related goroutines check when shutdown is initiated.

func (*BlockFactory) Save

func (bf *BlockFactory) Save(tx db.Transaction) error

Save has nothging to do.

func (*BlockFactory) Start

func (bf *BlockFactory) Start()

Start run a raft block factory service.

func (*BlockFactory) Ticker

func (bf *BlockFactory) Ticker() *time.Ticker

Ticker returns a time.Ticker for the main consensus loop.

func (*BlockFactory) Update

func (bf *BlockFactory) Update(block *types.Block)

Update has nothging to do.

func (*BlockFactory) VerifySign

func (bf *BlockFactory) VerifySign(block *types.Block) error

VerifySign checks the consensus level validity of a block.

func (*BlockFactory) VerifyTimestamp

func (bf *BlockFactory) VerifyTimestamp(*types.Block) bool

VerifyTimestamp checks the validity of the block timestamp.

type Cluster

type Cluster struct {
	component.ICompSyncRequester

	sync.Mutex

	ID     uint64
	Size   uint16
	Member map[uint64]*blockProducer
	Index  map[peer.ID]uint64 // peer ID to raft ID mapping

	BPUrls []string //for raft server
	// contains filtered or unexported fields
}

raft cluster membership copy from dpos/bp TODO refactoring Cluster represents a cluster of block producers.

func NewCluster

func NewCluster(bf *BlockFactory, raftID uint64, size uint16) *Cluster

func (*Cluster) Quorum

func (cl *Cluster) Quorum() uint16

type LeaderStatus

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

type RaftInfo

type RaftInfo struct {
	Leader string
	Total  string
	RaftId string
	Status *json.RawMessage
}

type RaftLogger

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

Logger is a logging unit. It controls the flow of messages to a given (swappable) backend.

func NewRaftLogger

func NewRaftLogger(logger *log.Logger) *RaftLogger

func (*RaftLogger) Debug

func (l *RaftLogger) Debug(args ...interface{})

func (*RaftLogger) Debugf

func (l *RaftLogger) Debugf(format string, args ...interface{})

func (*RaftLogger) Error

func (l *RaftLogger) Error(args ...interface{})

func (*RaftLogger) Errorf

func (l *RaftLogger) Errorf(format string, args ...interface{})

func (RaftLogger) Fatal

func (l RaftLogger) Fatal(args ...interface{})

func (*RaftLogger) Fatalf

func (l *RaftLogger) Fatalf(format string, args ...interface{})

func (*RaftLogger) Info

func (l *RaftLogger) Info(args ...interface{})

func (*RaftLogger) Infof

func (l *RaftLogger) Infof(format string, args ...interface{})

func (*RaftLogger) Panic

func (l *RaftLogger) Panic(args ...interface{})

func (*RaftLogger) Panicf

func (l *RaftLogger) Panicf(format string, args ...interface{})

func (*RaftLogger) Warning

func (l *RaftLogger) Warning(args ...interface{})

func (*RaftLogger) Warningf

func (l *RaftLogger) Warningf(format string, args ...interface{})

Jump to

Keyboard shortcuts

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