consensus

package
v2.10.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 22 Imported by: 16

Documentation

Overview

Package consensus is a generated GoMock package.

Package consensus is a generated GoMock package.

Package consensus is a generated GoMock package.

Package consensus is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var NotFoundBlock = errors.New("block not found")

Functions

This section is empty.

Types

type APIReader

type APIReader interface {
	ReadVoteMap(t time.Time) ([]*VoteDetails, *ledger.HashHeight, error)
	ReadSuccessRate(start, end uint64) ([]map[types.Address]*cdb.Content, error)
}

APIReader is just provided for RPC api

type APISnapshot

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

APISnapshot is the interface that can query snapshot consensus info.

func (*APISnapshot) ReadSuccessRate

func (api *APISnapshot) ReadSuccessRate(start, end uint64) ([]map[types.Address]*cdb.Content, error)

ReadSuccessRate query success rate for every SBP.

func (*APISnapshot) ReadVoteMap

func (api *APISnapshot) ReadVoteMap(ti time.Time) ([]*VoteDetails, *ledger.HashHeight, error)

ReadVoteMap query the vote result by time.

type ByBalance

type ByBalance []*VoteDetails

ByBalance sorts a slice of VoteDetails in decreasing order. Sorts by name for equal balance

func (ByBalance) Len

func (a ByBalance) Len() int

func (ByBalance) Less

func (a ByBalance) Less(i, j int) bool

func (ByBalance) Swap

func (a ByBalance) Swap(i, j int)

type Chain

type Chain interface {
	GetGenesisSnapshotBlock() *ledger.SnapshotBlock
	GetLatestSnapshotBlock() *ledger.SnapshotBlock

	/*
	*	Event Manager
	 */
	Register(listener chain.EventListener)
	UnRegister(listener chain.EventListener)

	GetConsensusGroupList(snapshotHash types.Hash) ([]*types.ConsensusGroupInfo, error)                                                 // Get all consensus group
	GetRegisterList(snapshotHash types.Hash, gid types.Gid) ([]*types.Registration, error)                                              // Get register for consensus group
	GetAllRegisterList(snapshotHash types.Hash, gid types.Gid) ([]*types.Registration, error)                                           // Get register for consensus group
	GetVoteList(snapshotHash types.Hash, gid types.Gid) ([]*types.VoteInfo, error)                                                      // Get the candidate's vote
	GetConfirmedBalanceList(addrList []types.Address, tokenID types.TokenTypeId, sbHash types.Hash) (map[types.Address]*big.Int, error) // Get balance for addressList
	GetSnapshotHeaderBeforeTime(timestamp *time.Time) (*ledger.SnapshotBlock, error)

	GetContractMeta(contractAddress types.Address) (meta *ledger.ContractMeta, err error)

	GetSnapshotBlockByHeight(height uint64) (*ledger.SnapshotBlock, error)
	GetSnapshotBlockByHash(hash types.Hash) (*ledger.SnapshotBlock, error)
	GetSnapshotHeadersAfterOrEqualTime(endHashHeight *ledger.HashHeight, startTime *time.Time, producer *types.Address) ([]*ledger.SnapshotBlock, error)
	IsGenesisSnapshotBlock(hash types.Hash) bool
	GetRandomSeed(snapshotHash types.Hash, n int) uint64
	GetLastUnpublishedSeedSnapshotHeader(producer types.Address, beforeTime time.Time) (*ledger.SnapshotBlock, error)
	NewDb(dbDir string) (*leveldb.DB, error)
}

Chain refer to chain.Chain

type Consensus

type Consensus interface {
	Verifier
	Subscriber
	Reader
	Life
	API() APIReader
	SBPReader() core.SBPStatReader
}

Consensus include all interface for consensus

func NewConsensus

func NewConsensus(ch Chain, rollback lock.ChainRollback) Consensus

NewConsensus instantiates a new consensus object

type DposReader

type DposReader interface {
	ElectionIndex(index uint64) (*electionResult, error)
	GetInfo() *core.GroupInfo
	Time2Index(t time.Time) uint64
	Index2Time(i uint64) (time.Time, time.Time)
	GenProofTime(t uint64) time.Time
	VerifyProducer(address types.Address, t time.Time) (bool, error)
}

type DposVerifier

type DposVerifier interface {
}

type Event

type Event struct {
	Gid     types.Gid
	Address types.Address
	Stime   time.Time
	Etime   time.Time

	Timestamp         time.Time // add to block
	SnapshotTimeStamp time.Time // add to block

	VoteTime    time.Time // voteTime
	PeriodStime time.Time // start time for period
	PeriodEtime time.Time // end time for period
}

Event will trigger when the snapshot block needs production

type Life

type Life interface {
	Start()
	Init() error
	Stop()
}

Life define the life cycle for consensus component

type LinkedArray

type LinkedArray interface {
	core.TimeIndex
	GetByIndex(index uint64) (*cdb.Point, error)
	GetByIndexWithProof(index uint64, proofHash types.Hash) (*cdb.Point, error)
}

LinkedArray can read SBP statistics of day, hour, period

type MockChain

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

MockChain is a mock of Chain interface

func NewMockChain

func NewMockChain(ctrl *gomock.Controller) *MockChain

NewMockChain creates a new mock instance

func (*MockChain) EXPECT

func (m *MockChain) EXPECT() *MockChainMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockChain) GetAllRegisterList

func (m *MockChain) GetAllRegisterList(arg0 types.Hash, arg1 types.Gid) ([]*types.Registration, error)

GetAllRegisterList mocks base method

func (*MockChain) GetConfirmedBalanceList

func (m *MockChain) GetConfirmedBalanceList(arg0 []types.Address, arg1 types.TokenTypeId, arg2 types.Hash) (map[types.Address]*big.Int, error)

GetConfirmedBalanceList mocks base method

func (*MockChain) GetConsensusGroupList

func (m *MockChain) GetConsensusGroupList(arg0 types.Hash) ([]*types.ConsensusGroupInfo, error)

GetConsensusGroupList mocks base method

func (*MockChain) GetContractMeta

func (m *MockChain) GetContractMeta(arg0 types.Address) (*ledger.ContractMeta, error)

GetContractMeta mocks base method

func (*MockChain) GetGenesisSnapshotBlock

func (m *MockChain) GetGenesisSnapshotBlock() *ledger.SnapshotBlock

GetGenesisSnapshotBlock mocks base method

func (*MockChain) GetLastUnpublishedSeedSnapshotHeader

func (m *MockChain) GetLastUnpublishedSeedSnapshotHeader(arg0 types.Address, arg1 time.Time) (*ledger.SnapshotBlock, error)

GetLastUnpublishedSeedSnapshotHeader mocks base method

func (*MockChain) GetLatestSnapshotBlock

func (m *MockChain) GetLatestSnapshotBlock() *ledger.SnapshotBlock

GetLatestSnapshotBlock mocks base method

func (*MockChain) GetRandomSeed

func (m *MockChain) GetRandomSeed(arg0 types.Hash, arg1 int) uint64

GetRandomSeed mocks base method

func (*MockChain) GetRegisterList

func (m *MockChain) GetRegisterList(arg0 types.Hash, arg1 types.Gid) ([]*types.Registration, error)

GetRegisterList mocks base method

func (*MockChain) GetSnapshotBlockByHash

func (m *MockChain) GetSnapshotBlockByHash(arg0 types.Hash) (*ledger.SnapshotBlock, error)

GetSnapshotBlockByHash mocks base method

func (*MockChain) GetSnapshotBlockByHeight

func (m *MockChain) GetSnapshotBlockByHeight(arg0 uint64) (*ledger.SnapshotBlock, error)

GetSnapshotBlockByHeight mocks base method

func (*MockChain) GetSnapshotHeaderBeforeTime

func (m *MockChain) GetSnapshotHeaderBeforeTime(arg0 *time.Time) (*ledger.SnapshotBlock, error)

GetSnapshotHeaderBeforeTime mocks base method

func (*MockChain) GetSnapshotHeadersAfterOrEqualTime

func (m *MockChain) GetSnapshotHeadersAfterOrEqualTime(arg0 *ledger.HashHeight, arg1 *time.Time, arg2 *types.Address) ([]*ledger.SnapshotBlock, error)

GetSnapshotHeadersAfterOrEqualTime mocks base method

func (*MockChain) GetVoteList

func (m *MockChain) GetVoteList(arg0 types.Hash, arg1 types.Gid) ([]*types.VoteInfo, error)

GetVoteList mocks base method

func (*MockChain) IsGenesisSnapshotBlock

func (m *MockChain) IsGenesisSnapshotBlock(arg0 types.Hash) bool

IsGenesisSnapshotBlock mocks base method

func (*MockChain) NewDb

func (m *MockChain) NewDb(arg0 string) (*leveldb.DB, error)

NewDb mocks base method

func (*MockChain) Register

func (m *MockChain) Register(arg0 chain.EventListener)

Register mocks base method

func (*MockChain) UnRegister

func (m *MockChain) UnRegister(arg0 chain.EventListener)

UnRegister mocks base method

type MockChainMockRecorder

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

MockChainMockRecorder is the mock recorder for MockChain

func (*MockChainMockRecorder) GetAllRegisterList

func (mr *MockChainMockRecorder) GetAllRegisterList(arg0, arg1 interface{}) *gomock.Call

GetAllRegisterList indicates an expected call of GetAllRegisterList

func (*MockChainMockRecorder) GetConfirmedBalanceList

func (mr *MockChainMockRecorder) GetConfirmedBalanceList(arg0, arg1, arg2 interface{}) *gomock.Call

GetConfirmedBalanceList indicates an expected call of GetConfirmedBalanceList

func (*MockChainMockRecorder) GetConsensusGroupList

func (mr *MockChainMockRecorder) GetConsensusGroupList(arg0 interface{}) *gomock.Call

GetConsensusGroupList indicates an expected call of GetConsensusGroupList

func (*MockChainMockRecorder) GetContractMeta

func (mr *MockChainMockRecorder) GetContractMeta(arg0 interface{}) *gomock.Call

GetContractMeta indicates an expected call of GetContractMeta

func (*MockChainMockRecorder) GetGenesisSnapshotBlock

func (mr *MockChainMockRecorder) GetGenesisSnapshotBlock() *gomock.Call

GetGenesisSnapshotBlock indicates an expected call of GetGenesisSnapshotBlock

func (*MockChainMockRecorder) GetLastUnpublishedSeedSnapshotHeader

func (mr *MockChainMockRecorder) GetLastUnpublishedSeedSnapshotHeader(arg0, arg1 interface{}) *gomock.Call

GetLastUnpublishedSeedSnapshotHeader indicates an expected call of GetLastUnpublishedSeedSnapshotHeader

func (*MockChainMockRecorder) GetLatestSnapshotBlock

func (mr *MockChainMockRecorder) GetLatestSnapshotBlock() *gomock.Call

GetLatestSnapshotBlock indicates an expected call of GetLatestSnapshotBlock

func (*MockChainMockRecorder) GetRandomSeed

func (mr *MockChainMockRecorder) GetRandomSeed(arg0, arg1 interface{}) *gomock.Call

GetRandomSeed indicates an expected call of GetRandomSeed

func (*MockChainMockRecorder) GetRegisterList

func (mr *MockChainMockRecorder) GetRegisterList(arg0, arg1 interface{}) *gomock.Call

GetRegisterList indicates an expected call of GetRegisterList

func (*MockChainMockRecorder) GetSnapshotBlockByHash

func (mr *MockChainMockRecorder) GetSnapshotBlockByHash(arg0 interface{}) *gomock.Call

GetSnapshotBlockByHash indicates an expected call of GetSnapshotBlockByHash

func (*MockChainMockRecorder) GetSnapshotBlockByHeight

func (mr *MockChainMockRecorder) GetSnapshotBlockByHeight(arg0 interface{}) *gomock.Call

GetSnapshotBlockByHeight indicates an expected call of GetSnapshotBlockByHeight

func (*MockChainMockRecorder) GetSnapshotHeaderBeforeTime

func (mr *MockChainMockRecorder) GetSnapshotHeaderBeforeTime(arg0 interface{}) *gomock.Call

GetSnapshotHeaderBeforeTime indicates an expected call of GetSnapshotHeaderBeforeTime

func (*MockChainMockRecorder) GetSnapshotHeadersAfterOrEqualTime

func (mr *MockChainMockRecorder) GetSnapshotHeadersAfterOrEqualTime(arg0, arg1, arg2 interface{}) *gomock.Call

GetSnapshotHeadersAfterOrEqualTime indicates an expected call of GetSnapshotHeadersAfterOrEqualTime

func (*MockChainMockRecorder) GetVoteList

func (mr *MockChainMockRecorder) GetVoteList(arg0, arg1 interface{}) *gomock.Call

GetVoteList indicates an expected call of GetVoteList

func (*MockChainMockRecorder) IsGenesisSnapshotBlock

func (mr *MockChainMockRecorder) IsGenesisSnapshotBlock(arg0 interface{}) *gomock.Call

IsGenesisSnapshotBlock indicates an expected call of IsGenesisSnapshotBlock

func (*MockChainMockRecorder) NewDb

func (mr *MockChainMockRecorder) NewDb(arg0 interface{}) *gomock.Call

NewDb indicates an expected call of NewDb

func (*MockChainMockRecorder) Register

func (mr *MockChainMockRecorder) Register(arg0 interface{}) *gomock.Call

Register indicates an expected call of Register

func (*MockChainMockRecorder) UnRegister

func (mr *MockChainMockRecorder) UnRegister(arg0 interface{}) *gomock.Call

UnRegister indicates an expected call of UnRegister

type MockDposReader

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

MockDposReader is a mock of DposReader interface

func NewMockDposReader

func NewMockDposReader(ctrl *gomock.Controller) *MockDposReader

NewMockDposReader creates a new mock instance

func (*MockDposReader) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockDposReader) ElectionIndex

func (m *MockDposReader) ElectionIndex(arg0 uint64) (*electionResult, error)

ElectionIndex mocks base method

func (*MockDposReader) GenVoteTime

func (m *MockDposReader) GenVoteTime(arg0 uint64) time.Time

GenProofTime mocks base method

func (*MockDposReader) GetInfo

func (m *MockDposReader) GetInfo() *core.GroupInfo

GetInfo mocks base method

func (*MockDposReader) Index2Time

func (m *MockDposReader) Index2Time(arg0 uint64) (time.Time, time.Time)

Index2Time mocks base method

func (*MockDposReader) Time2Index

func (m *MockDposReader) Time2Index(arg0 time.Time) uint64

Time2Index mocks base method

func (*MockDposReader) VerifyProducer

func (m *MockDposReader) VerifyProducer(arg0 types.Address, arg1 time.Time) (bool, error)

VerifyProducer mocks base method

type MockDposReaderMockRecorder

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

MockDposReaderMockRecorder is the mock recorder for MockDposReader

func (*MockDposReaderMockRecorder) ElectionIndex

func (mr *MockDposReaderMockRecorder) ElectionIndex(arg0 interface{}) *gomock.Call

ElectionIndex indicates an expected call of ElectionIndex

func (*MockDposReaderMockRecorder) GenVoteTime

func (mr *MockDposReaderMockRecorder) GenVoteTime(arg0 interface{}) *gomock.Call

GenProofTime indicates an expected call of GenProofTime

func (*MockDposReaderMockRecorder) GetInfo

func (mr *MockDposReaderMockRecorder) GetInfo() *gomock.Call

GetInfo indicates an expected call of GetInfo

func (*MockDposReaderMockRecorder) Index2Time

func (mr *MockDposReaderMockRecorder) Index2Time(arg0 interface{}) *gomock.Call

Index2Time indicates an expected call of Index2Time

func (*MockDposReaderMockRecorder) Time2Index

func (mr *MockDposReaderMockRecorder) Time2Index(arg0 interface{}) *gomock.Call

Time2Index indicates an expected call of Time2Index

func (*MockDposReaderMockRecorder) VerifyProducer

func (mr *MockDposReaderMockRecorder) VerifyProducer(arg0, arg1 interface{}) *gomock.Call

VerifyProducer indicates an expected call of VerifyProducer

type MockLinkedArray

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

MockLinkedArray is a mock of LinkedArray interface

func NewMockLinkedArray

func NewMockLinkedArray(ctrl *gomock.Controller) *MockLinkedArray

NewMockLinkedArray creates a new mock instance

func (*MockLinkedArray) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockLinkedArray) GetByIndex

func (m *MockLinkedArray) GetByIndex(arg0 uint64) (*cdb.Point, error)

GetByIndex mocks base method

func (*MockLinkedArray) GetByIndexWithProof

func (m *MockLinkedArray) GetByIndexWithProof(arg0 uint64, arg1 types.Hash) (*cdb.Point, error)

GetByIndexWithProof mocks base method

func (*MockLinkedArray) Index2Time

func (m *MockLinkedArray) Index2Time(arg0 uint64) (time.Time, time.Time)

Index2Time mocks base method

func (*MockLinkedArray) Time2Index

func (m *MockLinkedArray) Time2Index(arg0 time.Time) uint64

Time2Index mocks base method

type MockLinkedArrayMockRecorder

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

MockLinkedArrayMockRecorder is the mock recorder for MockLinkedArray

func (*MockLinkedArrayMockRecorder) GetByIndex

func (mr *MockLinkedArrayMockRecorder) GetByIndex(arg0 interface{}) *gomock.Call

GetByIndex indicates an expected call of GetByIndex

func (*MockLinkedArrayMockRecorder) GetByIndexWithProof

func (mr *MockLinkedArrayMockRecorder) GetByIndexWithProof(arg0, arg1 interface{}) *gomock.Call

GetByIndexWithProof indicates an expected call of GetByIndexWithProof

func (*MockLinkedArrayMockRecorder) Index2Time

func (mr *MockLinkedArrayMockRecorder) Index2Time(arg0 interface{}) *gomock.Call

Index2Time indicates an expected call of Index2Time

func (*MockLinkedArrayMockRecorder) Time2Index

func (mr *MockLinkedArrayMockRecorder) Time2Index(arg0 interface{}) *gomock.Call

Time2Index indicates an expected call of Time2Index

type MockRollbackProof

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

MockRollbackProof is a mock of RollbackProof interface

func NewMockRollbackProof

func NewMockRollbackProof(ctrl *gomock.Controller) *MockRollbackProof

NewMockRollbackProof creates a new mock instance

func (*MockRollbackProof) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRollbackProof) Proof

func (m *MockRollbackProof) Proof(arg0 types.Hash, arg1 time.Time) (*ledger.SnapshotBlock, error)

Proof mocks base method

func (*MockRollbackProof) ProofEmpty

func (m *MockRollbackProof) ProofEmpty(arg0, arg1 time.Time) (bool, error)

ProofEmpty mocks base method

func (*MockRollbackProof) ProofHash

func (m *MockRollbackProof) ProofHash(arg0 time.Time) (types.Hash, error)

ProofHash mocks base method

type MockRollbackProofMockRecorder

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

MockRollbackProofMockRecorder is the mock recorder for MockRollbackProof

func (*MockRollbackProofMockRecorder) Proof

func (mr *MockRollbackProofMockRecorder) Proof(arg0, arg1 interface{}) *gomock.Call

Proof indicates an expected call of Proof

func (*MockRollbackProofMockRecorder) ProofEmpty

func (mr *MockRollbackProofMockRecorder) ProofEmpty(arg0, arg1 interface{}) *gomock.Call

ProofEmpty indicates an expected call of ProofEmpty

func (*MockRollbackProofMockRecorder) ProofHash

func (mr *MockRollbackProofMockRecorder) ProofHash(arg0 interface{}) *gomock.Call

ProofHash indicates an expected call of ProofHash

type ProducersEvent added in v1.2.0

type ProducersEvent struct {
	Addrs []types.Address
	Index uint64
	Gid   types.Gid
}

ProducersEvent describes all SBP in one period

type Reader

type Reader interface {
	ReadByIndex(gid types.Gid, index uint64) ([]*Event, uint64, error)
	VoteTimeToIndex(gid types.Gid, t2 time.Time) (uint64, error)
	VoteIndexToTime(gid types.Gid, i uint64) (*time.Time, *time.Time, error)
}

Reader can read consensus result

type RollbackProof

type RollbackProof interface {
	Proof(hash types.Hash, t time.Time) (*ledger.SnapshotBlock, error)
	ProofEmpty(stime time.Time, etime time.Time) (bool, error)
	ProofHash(t time.Time) (types.Hash, error)
}

type SBPInfo

type SBPInfo struct {
	ExpectedNum int32
	FactualNum  int32
}

SBPInfo provide expected and factual block information

type Subscriber

type Subscriber interface {
	Subscribe(gid types.Gid, id string, addr *types.Address, fn func(Event))
	UnSubscribe(gid types.Gid, id string)
	SubscribeProducers(gid types.Gid, id string, fn func(event ProducersEvent))
}

Subscriber provide an interface to consensus event

type Verifier

type Verifier interface {
	VerifyAccountProducer(block *ledger.AccountBlock) (bool, error)
	VerifyABsProducer(abs map[types.Gid][]*ledger.AccountBlock) ([]*ledger.AccountBlock, error)
	VerifySnapshotProducer(block *ledger.SnapshotBlock) (bool, error)
}

Verifier is the interface that can verify block consensus.

type VoteDetails

type VoteDetails struct {
	core.Vote
	CurrentAddr  types.Address
	RegisterList []types.Address
	Addr         map[types.Address]*big.Int
}

VoteDetails is an extension for core.Vote

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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