manager

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const WaitHeightTolerance = uint32(1)

Variables

This section is empty.

Functions

func NewDispatcherAndIllegalMonitor

func NewDispatcherAndIllegalMonitor(consensus Consensus, eventMonitor *log.EventMonitor, network DposNetwork, manager DposManager, dposAccount account.DposAccount) (ProposalDispatcher, IllegalBehaviorMonitor)

Types

type AbnormalRecovering

type AbnormalRecovering interface {
	CollectConsensusStatus(height uint32, status *msg.ConsensusStatus) error
	RecoverFromConsensusStatus(status *msg.ConsensusStatus) error
}

type Consensus

type Consensus interface {
	AbnormalRecovering

	IsRunning() bool
	SetRunning()
	IsReady() bool
	SetReady()

	IsOnDuty() bool
	SetOnDuty(onDuty bool)

	IsArbitratorOnDuty(arbitrator string) bool
	GetOnDutyArbitrator() string

	StartConsensus(b *types.Block)
	ProcessBlock(b *types.Block)

	ChangeView()
	TryChangeView() bool
	GetViewOffset() uint32
}

func NewConsensus

func NewConsensus(manager DposManager, tolerance time.Duration, viewListener ViewListener) Consensus

type ConsensusBlockCache

type ConsensusBlockCache struct {
	ConsensusBlocks    map[common.Uint256]*types.Block
	ConsensusBlockList []common.Uint256

	Listener ConsensusBlockCacheListener
}

func (*ConsensusBlockCache) AddValue

func (c *ConsensusBlockCache) AddValue(key common.Uint256, value *types.Block)

func (*ConsensusBlockCache) GetFirstArrivedBlockHash

func (c *ConsensusBlockCache) GetFirstArrivedBlockHash() (common.Uint256, bool)

func (*ConsensusBlockCache) Reset

func (c *ConsensusBlockCache) Reset()

func (*ConsensusBlockCache) TryGetValue

func (c *ConsensusBlockCache) TryGetValue(key common.Uint256) (*types.Block, bool)

type ConsensusBlockCacheListener

type ConsensusBlockCacheListener interface {
	OnBlockAdded(b *types.Block)
}

type DposEventConditionHandler

type DposEventConditionHandler interface {
	TryStartNewConsensus(b *types.Block) bool

	ChangeView(firstBlockHash *common.Uint256)

	StartNewProposal(p types.DPosProposal)

	ProcessAcceptVote(id peer.PID, p types.DPosProposalVote)
	ProcessRejectVote(id peer.PID, p types.DPosProposalVote)
}

type DposHandlerSwitch

type DposHandlerSwitch interface {
	ViewListener
	DposEventConditionHandler

	Initialize(dispatcher ProposalDispatcher, consensus Consensus)
	SwitchTo(isOnDuty bool)

	FinishConsensus()

	RequestAbnormalRecovering()
	HelpToRecoverAbnormal(id peer.PID, height uint32)
	RecoverAbnormal(status *msg2.ConsensusStatus)

	ResponseGetBlocks(id peer.PID, startBlockHeight, endBlockHeight uint32)
}

func NewHandler

func NewHandler(network DposNetwork, manager DposManager, monitor *log.EventMonitor) DposHandlerSwitch

type DposManager

type DposManager interface {
	NetworkEventListener

	GetPublicKey() string
	GetBlockCache() *ConsensusBlockCache
	GetArbitrators() interfaces.Arbitrators

	Initialize(handler DposHandlerSwitch, dispatcher ProposalDispatcher, consensus Consensus, network DposNetwork, illegalMonitor IllegalBehaviorMonitor, blockPool *mempool.BlockPool, txPool *mempool.TxPool, node protocol.Noder)

	Recover()

	ProcessHigherBlock(b *types.Block)
	ConfirmBlock()

	ChangeConsensus(onDuty bool)

	AppendConfirm(confirm *types.DPosProposalVoteSlot) (bool, bool, error)
	AppendToTxnPool(txn *types.Transaction) errors.ErrCode
	Relay(from protocol.Noder, message interface{}) error
}

func NewManager

func NewManager(name string, arbitrators interfaces.Arbitrators) DposManager

type DposNetwork

type DposNetwork interface {
	Initialize(dnConfig DposNetworkConfig)

	Start()
	Stop() error

	SendMessageToPeer(id peer.PID, msg elap2p.Message) error
	BroadcastMessage(msg elap2p.Message)

	UpdatePeers(arbitrators [][]byte) error
	ChangeHeight(height uint32) error

	GetActivePeer() *peer.PID
}

type DposNetworkConfig

type DposNetworkConfig struct {
	ProposalDispatcher ProposalDispatcher
	Store              interfaces.IDposStore
}

type DposNormalHandler

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

func (DposNormalHandler) AddListeners

func (h DposNormalHandler) AddListeners(listeners ...log.EventListener)

func (*DposNormalHandler) ChangeView

func (h *DposNormalHandler) ChangeView(firstBlockHash *common.Uint256)

func (DposNormalHandler) FinishConsensus

func (h DposNormalHandler) FinishConsensus()

func (DposNormalHandler) HelpToRecoverAbnormal

func (h DposNormalHandler) HelpToRecoverAbnormal(id peer.PID, height uint32)

func (DposNormalHandler) Initialize

func (h DposNormalHandler) Initialize(dispatcher ProposalDispatcher, consensus Consensus)

func (DposNormalHandler) OnViewChanged

func (h DposNormalHandler) OnViewChanged(isOnDuty bool)

func (*DposNormalHandler) ProcessAcceptVote

func (h *DposNormalHandler) ProcessAcceptVote(id peer.PID, p types.DPosProposalVote)

func (*DposNormalHandler) ProcessRejectVote

func (h *DposNormalHandler) ProcessRejectVote(id peer.PID, p types.DPosProposalVote)

func (DposNormalHandler) RecoverAbnormal

func (h DposNormalHandler) RecoverAbnormal(status *msg2.ConsensusStatus)

func (DposNormalHandler) RequestAbnormalRecovering

func (h DposNormalHandler) RequestAbnormalRecovering()

func (DposNormalHandler) ResponseGetBlocks

func (h DposNormalHandler) ResponseGetBlocks(id peer.PID, startBlockHeight, endBlockHeight uint32)

func (*DposNormalHandler) StartNewProposal

func (h *DposNormalHandler) StartNewProposal(p types.DPosProposal)

func (DposNormalHandler) SwitchTo

func (h DposNormalHandler) SwitchTo(onDuty bool)

func (*DposNormalHandler) TryStartNewConsensus

func (h *DposNormalHandler) TryStartNewConsensus(b *types.Block) bool

type DposOnDutyHandler

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

func (DposOnDutyHandler) AddListeners

func (h DposOnDutyHandler) AddListeners(listeners ...log.EventListener)

func (*DposOnDutyHandler) ChangeView

func (h *DposOnDutyHandler) ChangeView(firstBlockHash *common.Uint256)

func (DposOnDutyHandler) FinishConsensus

func (h DposOnDutyHandler) FinishConsensus()

func (DposOnDutyHandler) HelpToRecoverAbnormal

func (h DposOnDutyHandler) HelpToRecoverAbnormal(id peer.PID, height uint32)

func (DposOnDutyHandler) Initialize

func (h DposOnDutyHandler) Initialize(dispatcher ProposalDispatcher, consensus Consensus)

func (DposOnDutyHandler) OnViewChanged

func (h DposOnDutyHandler) OnViewChanged(isOnDuty bool)

func (*DposOnDutyHandler) ProcessAcceptVote

func (h *DposOnDutyHandler) ProcessAcceptVote(id peer.PID, p types.DPosProposalVote)

func (*DposOnDutyHandler) ProcessRejectVote

func (h *DposOnDutyHandler) ProcessRejectVote(id peer.PID, p types.DPosProposalVote)

func (DposOnDutyHandler) RecoverAbnormal

func (h DposOnDutyHandler) RecoverAbnormal(status *msg2.ConsensusStatus)

func (DposOnDutyHandler) RequestAbnormalRecovering

func (h DposOnDutyHandler) RequestAbnormalRecovering()

func (DposOnDutyHandler) ResponseGetBlocks

func (h DposOnDutyHandler) ResponseGetBlocks(id peer.PID, startBlockHeight, endBlockHeight uint32)

func (*DposOnDutyHandler) StartNewProposal

func (h *DposOnDutyHandler) StartNewProposal(p types.DPosProposal)

func (DposOnDutyHandler) SwitchTo

func (h DposOnDutyHandler) SwitchTo(onDuty bool)

func (*DposOnDutyHandler) TryStartNewConsensus

func (h *DposOnDutyHandler) TryStartNewConsensus(b *types.Block) bool

type IllegalBehaviorMonitor

type IllegalBehaviorMonitor interface {
	IsBlockValid(block *types.Block) bool

	AddProposal(proposal types.DPosProposal)
	Reset(changeView bool)

	IsLegalProposal(p *types.DPosProposal) (*types.DPosProposal, bool)
	ProcessIllegalProposal(first, second *types.DPosProposal)

	ProcessIllegalVote(first, second *types.DPosProposalVote)
	IsLegalVote(v *types.DPosProposalVote) (*types.DPosProposalVote, bool)

	AddProposalEvidence(evidence *types.DposIllegalProposals)
	AddVoteEvidence(evidence *types.DposIllegalVotes)
	AddBlockEvidence(evidence *types.DposIllegalBlocks)
}

type NetworkEventListener

type NetworkEventListener interface {
	StatusSyncEventListener

	OnProposalReceived(id peer.PID, p types.DPosProposal)
	OnVoteReceived(id peer.PID, p types.DPosProposalVote)
	OnVoteRejected(id peer.PID, p types.DPosProposalVote)

	OnChangeView()
	OnBadNetwork()

	OnBlockReceived(b *types.Block, confirmed bool)
	OnConfirmReceived(p *types.DPosProposalVoteSlot)
	OnIllegalBlocksReceived(i *types.DposIllegalBlocks)
}

type ProposalDispatcher

type ProposalDispatcher interface {
	AbnormalRecovering

	//status
	GetProcessingBlock() *types.Block
	GetProcessingProposal() *types.DPosProposal
	IsProcessingBlockEmpty() bool
	CurrentHeight() uint32

	//proposal
	StartProposal(b *types.Block)
	CleanProposals(changeView bool)
	FinishProposal()
	TryStartSpeculatingProposal(b *types.Block)
	ProcessProposal(d types.DPosProposal)

	FinishConsensus()

	ProcessVote(v types.DPosProposalVote, accept bool)
	AddPendingVote(v types.DPosProposalVote)

	OnAbnormalStateDetected()
	RequestAbnormalRecovering()
	TryAppendAndBroadcastConfirmBlockMsg() bool
}

type StatusSyncEventListener

type StatusSyncEventListener interface {
	OnPing(id peer.PID, height uint32)
	OnPong(id peer.PID, height uint32)
	OnBlock(id peer.PID, block *types.Block)
	OnInv(id peer.PID, blockHash common.Uint256)
	OnGetBlock(id peer.PID, blockHash common.Uint256)
	OnGetBlocks(id peer.PID, startBlockHeight, endBlockHeight uint32)
	OnResponseBlocks(id peer.PID, blockConfirms []*types.DposBlock)
	OnRequestConsensus(id peer.PID, height uint32)
	OnResponseConsensus(id peer.PID, status *msg.ConsensusStatus)
	OnRequestProposal(id peer.PID, hash common.Uint256)
	OnIllegalProposalReceived(id peer.PID, proposals *types.DposIllegalProposals)
	OnIllegalVotesReceived(id peer.PID, votes *types.DposIllegalVotes)
}

type ViewListener

type ViewListener interface {
	OnViewChanged(isOnDuty bool)
}

Jump to

Keyboard shortcuts

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