Documentation ¶
Index ¶
- Constants
- Variables
- func ConfStateToString(conf *raftpb.ConfState) string
- func InitBlockInterval(blockIntervalSec int64)
- func IsDposName(consensus string) bool
- func IsRaftName(consensus string) bool
- func SetCurConsensus(consensus string)
- func SnapToString(snap *raftpb.Snapshot, snapd *SnapshotData) string
- func Start(c Consensus)
- func Stop(c Consensus)
- func UseDpos() bool
- func UseRaft() bool
- type AergoRaftAccessor
- type BlockFactory
- type ChainConsensus
- type ChainConsensusCluster
- type ChainDB
- type ChainSnapshot
- type ChainWAL
- type ConfChangePropose
- type ConfChangeReply
- type Consensus
- type ConsensusAccessor
- type ConsensusType
- type Constructor
- type DummyRaftAccessor
- func (DummyRaftAccessor) GetMemberByID(id uint64) *Member
- func (DummyRaftAccessor) GetMemberByPeerID(peerID types.PeerID) *Member
- func (DummyRaftAccessor) IsIDRemoved(peerID types.PeerID) bool
- func (DummyRaftAccessor) Process(ctx context.Context, peerID types.PeerID, m raftpb.Message) error
- func (DummyRaftAccessor) ReportSnapshot(peerID types.PeerID, status raft.SnapshotStatus)
- func (DummyRaftAccessor) ReportUnreachable(peerID types.PeerID)
- func (DummyRaftAccessor) SaveFromRemote(r io.Reader, id uint64, msg raftpb.Message) (int64, error)
- 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 ¶
const DefaultBlockIntervalSec = int64(1)
DefaultBlockIntervalSec is the default block generation interval in seconds.
Variables ¶
var ( // BlockIntervalSec is the block generation interval in seconds. BlockIntervalSec = DefaultBlockIntervalSec // BlockInterval is the maximum block generation time limit. BlockInterval = time.Second * time.Duration(DefaultBlockIntervalSec) )
var ( WalEntryType_name = map[EntryType]string{ 0: "EntryBlock", 1: "EntryEmpty", 2: "EntryConfChange", } ErrInvalidMemberID = errors.New("member id of conf change doesn't match") ErrEmptySnapData = errors.New("failed to decode snapshot data. encoded data is empty") ErrInvalidMemberAttr = errors.New("invalid member attribute") ErrorMembershipChangeSkip = errors.New("node is not raft leader, so skip membership change request") )
var ConsensusName = []string{"dpos", "raft", "sbp"}
var ConsensusTypes = map[string]ConsensusType{"dpos": ConsensusDPOS, "raft": ConsensusRAFT, "sbp": ConsensusSBP}
var (
ErrNotSupportedMethod = errors.New("not supported method in this consensus")
)
var IllegalArgumentError = errors.New("illegal argument")
Functions ¶
func ConfStateToString ¶
func InitBlockInterval ¶
func InitBlockInterval(blockIntervalSec int64)
InitBlockInterval initializes block interval parameters.
func IsDposName ¶
func IsRaftName ¶
func SetCurConsensus ¶
func SetCurConsensus(consensus string)
func SnapToString ¶
func SnapToString(snap *raftpb.Snapshot, snapd *SnapshotData) string
Types ¶
type AergoRaftAccessor ¶
type AergoRaftAccessor interface { Process(ctx context.Context, peerID types.PeerID, m raftpb.Message) error IsIDRemoved(peerID types.PeerID) bool ReportUnreachable(peerID types.PeerID) ReportSnapshot(peerID types.PeerID, status raft.SnapshotStatus) SaveFromRemote(r io.Reader, id uint64, msg raftpb.Message) (int64, error) GetMemberByID(id uint64) *Member GetMemberByPeerID(peerID types.PeerID) *Member }
AergoRaftAccessor is interface to access raft messaging. It is wrapping raft message with aergo internal types
type BlockFactory ¶
type BlockFactory interface { Start() JobQueue() chan<- interface{} }
BlockFactory is an interface for a block factory implementation.
type ChainConsensus ¶
type ChainConsensus interface { ChainConsensusCluster 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 IsConnectedBlock(block *types.Block) bool IsForkEnable() bool Info() string }
ChainConsensus includes chain status and validation API.
type ChainConsensusCluster ¶
type ChainConsensusCluster interface {
MakeConfChangeProposal(req *types.MembershipChange) (*ConfChangePropose, error)
}
type ChainDB ¶
type ChainDB interface { GetBestBlock() (*types.Block, error) GetBlockByNo(blockNo types.BlockNo) (*types.Block, error) GetHashByNo(blockNo types.BlockNo) ([]byte, error) GetBlock(hash []byte) (*types.Block, error) GetGenesisInfo() *types.Genesis Get(key []byte) []byte NewTx() db.Transaction }
ChainDB is a reader interface for the ChainDB.
type ChainSnapshot ¶
func NewChainSnapshot ¶
func NewChainSnapshot(block *types.Block) *ChainSnapshot
func (*ChainSnapshot) Equal ¶
func (csnap *ChainSnapshot) Equal(other *ChainSnapshot) bool
func (*ChainSnapshot) ToString ¶
func (csnap *ChainSnapshot) ToString() string
type ChainWAL ¶
type ChainWAL interface { ChainDB ClearWAL() ResetWAL(hardStateInfo *types.HardStateInfo) error WriteRaftEntry([]*WalEntry, []*types.Block, []*raftpb.ConfChange) error GetRaftEntry(idx uint64) (*WalEntry, error) HasWal(identity RaftIdentity) (bool, error) GetRaftEntryOfBlock(hash []byte) (*WalEntry, error) GetRaftEntryLastIdx() (uint64, error) GetRaftEntryIndexOfBlock(hash []byte) (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) WriteConfChangeProgress(id uint64, progress *types.ConfChangeProgress) error GetConfChangeProgress(id uint64) (*types.ConfChangeProgress, error) }
type ConfChangePropose ¶
type ConfChangePropose struct { Ctx context.Context Cc *raftpb.ConfChange ReplyC chan *ConfChangeReply }
type ConfChangeReply ¶
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 ¶
type ConsensusAccessor interface { ConsensusInfo() *types.ConsensusInfo ClusterInfo([]byte) *types.GetClusterInfoResponse ConfChange(req *types.MembershipChange) (*Member, error) ConfChangeInfo(requestID uint64) (*types.ConfChangeProgress, error) // RaftAccessor returns AergoRaftAccessor. It is only valid if chain is raft consensus RaftAccessor() AergoRaftAccessor }
type ConsensusType ¶
type ConsensusType int
const ( ConsensusDPOS ConsensusType = iota ConsensusRAFT ConsensusSBP )
var CurConsensusType ConsensusType
type Constructor ¶
Constructor represents a function returning the Consensus interface for each implementation.
type DummyRaftAccessor ¶
type DummyRaftAccessor struct { }
DummyRaftAccessor returns error if process request comes, or silently ignore raft message.
func (DummyRaftAccessor) GetMemberByID ¶
func (DummyRaftAccessor) GetMemberByID(id uint64) *Member
func (DummyRaftAccessor) GetMemberByPeerID ¶
func (DummyRaftAccessor) GetMemberByPeerID(peerID types.PeerID) *Member
func (DummyRaftAccessor) IsIDRemoved ¶
func (DummyRaftAccessor) IsIDRemoved(peerID types.PeerID) bool
func (DummyRaftAccessor) ReportSnapshot ¶
func (DummyRaftAccessor) ReportSnapshot(peerID types.PeerID, status raft.SnapshotStatus)
func (DummyRaftAccessor) ReportUnreachable ¶
func (DummyRaftAccessor) ReportUnreachable(peerID types.PeerID)
func (DummyRaftAccessor) SaveFromRemote ¶
type ErrorConsensus ¶
ErrorConsensus is a basic error struct for consensus modules.
func (ErrorConsensus) Error ¶
func (e ErrorConsensus) Error() string
type Info ¶
type Info struct { Type string Status *json.RawMessage `json:",omitempty"` }
Info represents an information for a consensus implementation.
type Member ¶
type Member struct {
types.MemberAttr
}
func (*Member) CalculateMemberID ¶
func (*Member) HasDuplicatedAttr ¶
func (*Member) IsCompatible ¶
IsCompatible checks if name, url and peerid of this member are the same with other member
func (*Member) SetAttr ¶
func (m *Member) SetAttr(attr *types.MemberAttr)
func (*Member) SetMemberID ¶
type MembersByName ¶
type MembersByName []*Member
func (MembersByName) Len ¶
func (mbrs MembersByName) Len() int
func (MembersByName) Less ¶
func (mbrs MembersByName) Less(i, j int) bool
func (MembersByName) Swap ¶
func (mbrs MembersByName) Swap(i, j int)
type RaftIdentity ¶
type RaftIdentity struct { ClusterID uint64 ID uint64 Name string PeerID string // base58 encoded format }
func (*RaftIdentity) ToString ¶
func (rid *RaftIdentity) ToString() string
type SnapshotData ¶
type SnapshotData struct { Chain ChainSnapshot `json:"chain"` Members []*Member `json:"members"` RemovedMembers []*Member }
func NewSnapshotData ¶
func NewSnapshotData(members []*Member, rmMembers []*Member, block *types.Block) *SnapshotData
func (*SnapshotData) Decode ¶
func (snapd *SnapshotData) Decode(data []byte) error
func (*SnapshotData) Encode ¶
func (snapd *SnapshotData) Encode() ([]byte, error)
func (*SnapshotData) Equal ¶
func (snapd *SnapshotData) Equal(t *SnapshotData) bool
func (*SnapshotData) ToString ¶
func (snapd *SnapshotData) ToString() string