Documentation
¶
Index ¶
- Constants
- Variables
- func ConfStateToString(conf *raftpb.ConfState) string
- func InitBlockInterval(blockIntervalSec int64)
- func ParseToUrl(urlstr string) (*url.URL, error)
- func SnapToString(snap *raftpb.Snapshot, snapd *SnapshotData) string
- func Start(c Consensus)
- func Stop(c Consensus)
- type BlockFactory
- type ChainConsensus
- type ChainDB
- type ChainSnapshot
- type ChainWAL
- type ConfChangePropose
- type ConfChangeReply
- type Consensus
- type ConsensusAccessor
- type ConsensusType
- type Constructor
- type EntryType
- type ErrorConsensus
- type Info
- type Member
- func (m *Member) CalculateMemberID(chainID []byte, curTimestamp int64)
- func (m *Member) Clone() *Member
- func (m *Member) Equal(other *Member) bool
- func (m *Member) GetPeerID() types.PeerID
- func (m *Member) HasDuplicatedAttr(x *Member) bool
- func (m *Member) IsCompatible(other *Member) bool
- func (m *Member) IsValid() bool
- func (m *Member) SetAttr(attr *types.MemberAttr)
- func (m *Member) SetMemberID(id uint64)
- func (m *Member) ToString() string
- type MembersByName
- type RaftIdentity
- type SnapshotData
- type TxWriter
- type WalEntry
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 ( WalEntryType_name = map[EntryType]string{ 0: "EntryBlock", 1: "EntryEmpty", 2: "EntryConfChange", } ErrURLInvalidScheme = errors.New("url has invalid scheme") ErrURLInvalidPort = errors.New("url must have host:port style") ErrInvalidMemberID = errors.New("member id of conf change doesn't match") ErrEmptySnapData = errors.New("failed to decode snapshot data. encoded data is empty") )
View Source
var ConsensusName = []string{"dpos", "raft", "sbp"}
View Source
var (
ErrNotSupportedMethod = errors.New("not supported metehod in this consensus")
)
Functions ¶
func ConfStateToString ¶ added in v0.9.0
func InitBlockInterval ¶
func InitBlockInterval(blockIntervalSec int64)
InitBlockInterval initializes block interval parameters.
func SnapToString ¶ added in v0.9.0
func SnapToString(snap *raftpb.Snapshot, snapd *SnapshotData) string
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 TxWriter) error
NeedReorganization(rootNo types.BlockNo) bool
NeedNotify() bool
HasWAL() bool // if consensus has WAL, block has already written in db
Info() string
}
ChainConsensus includes chainstatus and validation API.
type ChainDB ¶ added in v0.9.0
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 ChainSnapshot ¶ added in v0.9.0
func NewChainSnapshot ¶ added in v0.9.0
func NewChainSnapshot(block *types.Block) *ChainSnapshot
func (*ChainSnapshot) Equal ¶ added in v0.9.0
func (csnap *ChainSnapshot) Equal(other *ChainSnapshot) bool
func (*ChainSnapshot) ToString ¶ added in v0.9.0
func (csnap *ChainSnapshot) ToString() string
type ChainWAL ¶ added in v0.9.0
type ChainWAL interface {
ChainDB
IsWALInited() bool
GetBlock(blockHash []byte) (*types.Block, error)
ReadAll() (state raftpb.HardState, ents []raftpb.Entry, err error)
WriteRaftEntry([]*WalEntry, []*types.Block) error
GetRaftEntry(idx uint64) (*WalEntry, error)
HasWal() (bool, error)
GetRaftEntryLastIdx() (uint64, error)
GetHardState() (*raftpb.HardState, error)
WriteHardState(hardstate *raftpb.HardState) error
WriteSnapshot(snap *raftpb.Snapshot) error
GetSnapshot() (*raftpb.Snapshot, error)
WriteIdentity(id *RaftIdentity) error
GetIdentity() (*RaftIdentity, error)
}
type ConfChangePropose ¶ added in v0.9.0
type ConfChangePropose struct {
Ctx context.Context
Cc *raftpb.ConfChange
ReplyC chan *ConfChangeReply
}
type ConfChangeReply ¶ added in v0.9.0
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 v0.9.0
type ConsensusAccessor interface {
ConsensusInfo() *types.ConsensusInfo
ConfChange(req *types.MembershipChange) (*Member, error)
ClusterInfo() ([]*types.MemberAttr, []byte, error)
}
type ConsensusType ¶ added in v0.9.0
type ConsensusType int
const ( ConsensusDPOS ConsensusType = iota ConsensusRAFT ConsensusSBP )
type Constructor ¶ added in v0.9.0
Constructor represents a function returning the Consensus interfactor for each implementation.
type ErrorConsensus ¶
ErrorConsensus is a basic error struct for consensus modules.
func (ErrorConsensus) Error ¶
func (e ErrorConsensus) Error() string
type Info ¶ added in v0.9.0
type Info struct {
Type string
Status *json.RawMessage `json:",omitempty"`
}
Info represents an information for a consensus implementation.
type Member ¶ added in v0.9.0
type Member struct {
types.MemberAttr
}
func (*Member) CalculateMemberID ¶ added in v0.9.0
func (*Member) HasDuplicatedAttr ¶ added in v0.9.0
func (*Member) IsCompatible ¶ added in v0.9.0
IsCompatible checks if name, url and peerid of this member are the same with other member
func (*Member) SetAttr ¶ added in v0.9.0
func (m *Member) SetAttr(attr *types.MemberAttr)
func (*Member) SetMemberID ¶ added in v0.9.0
type MembersByName ¶ added in v0.9.0
type MembersByName []*Member
func (MembersByName) Len ¶ added in v0.9.0
func (mbrs MembersByName) Len() int
func (MembersByName) Less ¶ added in v0.9.0
func (mbrs MembersByName) Less(i, j int) bool
func (MembersByName) Swap ¶ added in v0.9.0
func (mbrs MembersByName) Swap(i, j int)
type RaftIdentity ¶ added in v0.9.0
func (*RaftIdentity) ToString ¶ added in v0.9.0
func (rid *RaftIdentity) ToString() string
type SnapshotData ¶ added in v0.9.0
type SnapshotData struct {
Chain ChainSnapshot `json:"chain"`
Members []*Member `json:"members"`
RemovedMembers []*Member
}
func NewSnapshotData ¶ added in v0.9.0
func NewSnapshotData(members []*Member, rmMembers []*Member, block *types.Block) *SnapshotData
func (*SnapshotData) Decode ¶ added in v0.9.0
func (snapd *SnapshotData) Decode(data []byte) error
func (*SnapshotData) Encode ¶ added in v0.9.0
func (snapd *SnapshotData) Encode() ([]byte, error)
func (*SnapshotData) Equal ¶ added in v0.9.0
func (snapd *SnapshotData) Equal(t *SnapshotData) bool
func (*SnapshotData) ToString ¶ added in v0.9.0
func (snapd *SnapshotData) ToString() string
Click to show internal directories.
Click to hide internal directories.