dpos

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: GPL-3.0 Imports: 30 Imported by: 5

Documentation

Index

Constants

View Source
const (
	ConsensusReady = iota
	ConsensusRunning
)
View Source
const (
	ETNewPeer          events.EventType = 1000
	ETDonePeer         events.EventType = 1001
	ETStopRoutes       events.EventType = 1002
	ETElaMsg           events.EventType = 1003
	ETAnnounceAddr     events.EventType = 1004
	ETNextProducers    events.EventType = 1005
	ETOnSPVHeight      events.EventType = 1006
	ETSmallCroTx       events.EventType = 1007
	ETFailedWithdrawTx events.EventType = 1008
	ETUpdateProducers  events.EventType = 1009
	ETOnDutyEvent      events.EventType = 1010
)

Constants for the type of a notification message.

Variables

This section is empty.

Functions

func CheckConfirm

func CheckConfirm(confirm *payload.Confirm, minSignCount int) error

func CheckProposal

func CheckProposal(proposal *payload.DPOSProposal) error

func CheckVote

func CheckVote(vote *payload.DPOSProposalVote) error

func Debug

func Debug(a ...interface{})

func Debugf

func Debugf(format string, a ...interface{})

func Error

func Error(a ...interface{})

func Errorf

func Errorf(format string, a ...interface{})

func Fatal

func Fatal(a ...interface{})

func Fatalf

func Fatalf(format string, a ...interface{})

func GetBridgeAccount added in v0.2.0

func GetBridgeAccount(keystorePath string, password []byte) (crypto.Keypair, error)

func GetDposAccount

func GetDposAccount(keystorePath string, password []byte) (daccount.Account, error)

func Info

func Info(a ...interface{})

func Infof

func Infof(format string, a ...interface{})

func InitLog

func InitLog(level uint8, maxPerLogSizeMb, maxLogsSizeMb int64, path string)

func StartProposal

func StartProposal(ac account.Account, blockHash common.Uint256, viewOffset uint32) (*payload.DPOSProposal, error)

func StartVote

func StartVote(ProposalHash *common.Uint256, isAcceipt bool, ac account.Account) (*payload.DPOSProposalVote, error)

func Warn

func Warn(a ...interface{})

func Warnf

func Warnf(format string, a ...interface{})

Types

type BlockPool

type BlockPool struct {
	sync.RWMutex

	VerifyConfirm func(confirm *payload.Confirm, elaHeight uint64) error
	VerifyBlock   func(block DBlock) error
	SealHash      func(block DBlock) (common.Uint256, error)
	// contains filtered or unexported fields
}

func NewBlockPool

func NewBlockPool(verifyConfirm func(confirm *payload.Confirm, elaHeight uint64) error,
	verifyBlock func(block DBlock) error,
	sealHash func(block DBlock) (common.Uint256, error)) *BlockPool

func (*BlockPool) AddBadBlock

func (bm *BlockPool) AddBadBlock(block DBlock) error

func (*BlockPool) AddToBlockMap

func (bm *BlockPool) AddToBlockMap(block DBlock)

func (*BlockPool) AddToConfirmMap

func (bm *BlockPool) AddToConfirmMap(confirm *payload.Confirm)

func (*BlockPool) AppendConfirm

func (bm *BlockPool) AppendConfirm(confirm *payload.Confirm) error

func (*BlockPool) AppendDposBlock

func (bm *BlockPool) AppendDposBlock(dposBlock DBlock) error

func (*BlockPool) AppendFutureBlock

func (bm *BlockPool) AppendFutureBlock(dposBlock DBlock) error

func (*BlockPool) CleanFinalConfirmedBlock

func (bm *BlockPool) CleanFinalConfirmedBlock(height uint64)

func (*BlockPool) ConfirmBlock

func (bm *BlockPool) ConfirmBlock(hash common.Uint256) error

func (*BlockPool) GetBlock

func (bm *BlockPool) GetBlock(hash common.Uint256) (DBlock, bool)

func (*BlockPool) GetConfirm

func (bm *BlockPool) GetConfirm(hash common.Uint256) (*payload.Confirm, bool)

func (*BlockPool) GetConfirmByHeight

func (bm *BlockPool) GetConfirmByHeight(height uint64) (*payload.Confirm, bool)

func (*BlockPool) HandleParentBlock

func (bm *BlockPool) HandleParentBlock(parent DBlock) bool

func (*BlockPool) HasBlock

func (bm *BlockPool) HasBlock(hash common.Uint256) bool

func (*BlockPool) HashConfirmed

func (bm *BlockPool) HashConfirmed(number uint64) bool

func (*BlockPool) IsBadBlockProposal

func (bm *BlockPool) IsBadBlockProposal(proposal *payload.DPOSProposal) bool

func (*BlockPool) IsFutureBlock

func (bm *BlockPool) IsFutureBlock(hash common.Uint256) bool

func (*BlockPool) RemoveConfirm

func (bm *BlockPool) RemoveConfirm(hash common.Uint256)

type Config

type Config struct {
	// The PID of this peer if it is an producer.
	PID []byte

	// The network address of this arbiter.
	Addr string

	// TimeSource is the median time source of the P2P network.
	TimeSource dtime.MedianTimeSource

	// Sign the addr message of this arbiter.
	Sign func(data []byte) (signature []byte)

	// IsCurrent returns whether BlockChain synced to best height.
	IsCurrent func() bool

	// RelayAddr relays the addresses inventory to the P2P network.
	RelayAddr func(iv *msg.InvVect, data interface{})

	// OnCipherAddr will be invoked when an address cipher received.
	OnCipherAddr func(pid peer.PID, cipher []byte)
}

Config defines the parameters to create a Route instance.

type ConfirmInfo

type ConfirmInfo struct {
	Confirm *payload.Confirm
	Height  uint64
}

type ConsensusView

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

func NewConsensusView

func NewConsensusView(tolerance time.Duration, account []byte,
	producers *Producers, viewListener ViewListener) *ConsensusView

func (*ConsensusView) ChangeCurrentProducers added in v0.1.4

func (v *ConsensusView) ChangeCurrentProducers(changeHeight uint64, spvHeight uint64)

func (*ConsensusView) ChangeView

func (v *ConsensusView) ChangeView(now time.Time, force bool, parentTime uint64)

func (*ConsensusView) DumpInfo

func (v *ConsensusView) DumpInfo()

func (*ConsensusView) GetCRMajorityCount added in v0.1.4

func (v *ConsensusView) GetCRMajorityCount() int

func (*ConsensusView) GetChangeViewTime

func (v *ConsensusView) GetChangeViewTime() time.Time

func (*ConsensusView) GetDutyIndex added in v0.1.4

func (v *ConsensusView) GetDutyIndex() uint32

func (*ConsensusView) GetMajorityCount

func (v *ConsensusView) GetMajorityCount() int

func (*ConsensusView) GetMajorityCountByTotalSigners added in v0.1.4

func (v *ConsensusView) GetMajorityCountByTotalSigners(totalSigner int) int

func (*ConsensusView) GetNextNeedConnectArbiters added in v0.2.1

func (v *ConsensusView) GetNextNeedConnectArbiters() []peer.PID

func (*ConsensusView) GetProducers

func (v *ConsensusView) GetProducers() [][]byte

func (*ConsensusView) GetSpvHeight added in v0.1.4

func (v *ConsensusView) GetSpvHeight() uint64

func (*ConsensusView) GetTotalArbiterCount added in v0.2.0

func (v *ConsensusView) GetTotalArbiterCount() int

func (*ConsensusView) GetTotalProducersCount added in v0.2.0

func (v *ConsensusView) GetTotalProducersCount() int

func (*ConsensusView) GetViewInterval

func (v *ConsensusView) GetViewInterval() time.Duration

func (*ConsensusView) GetViewOffset

func (v *ConsensusView) GetViewOffset() uint32

func (*ConsensusView) GetViewStartTime

func (v *ConsensusView) GetViewStartTime() time.Time

func (*ConsensusView) HasArbitersMinorityCount

func (v *ConsensusView) HasArbitersMinorityCount(count int) bool

func (*ConsensusView) HasProducerMajorityCount

func (v *ConsensusView) HasProducerMajorityCount(count int) bool

func (*ConsensusView) IsCurrentProducers added in v0.1.4

func (v *ConsensusView) IsCurrentProducers(curProducers [][]byte) bool

func (*ConsensusView) IsMajorityAgree

func (v *ConsensusView) IsMajorityAgree(count int) bool

func (*ConsensusView) IsMajorityRejected

func (v *ConsensusView) IsMajorityRejected(count int) bool

func (*ConsensusView) IsOnduty

func (v *ConsensusView) IsOnduty() bool

func (*ConsensusView) IsProducers

func (v *ConsensusView) IsProducers(account []byte) bool

func (*ConsensusView) IsReady

func (v *ConsensusView) IsReady() bool

func (*ConsensusView) IsRunning

func (v *ConsensusView) IsRunning() bool

func (*ConsensusView) IsSameProducers added in v0.1.4

func (v *ConsensusView) IsSameProducers(curProducers [][]byte) bool

func (*ConsensusView) ProducerIndex added in v0.2.0

func (v *ConsensusView) ProducerIndex(signer []byte) int

func (*ConsensusView) ProducerIsOnDuty

func (v *ConsensusView) ProducerIsOnDuty(account []byte) bool

func (*ConsensusView) ResetView

func (v *ConsensusView) ResetView(parentTime uint64)

func (*ConsensusView) SetChangViewTime

func (v *ConsensusView) SetChangViewTime(parentTime uint64)

func (*ConsensusView) SetReady

func (v *ConsensusView) SetReady()

func (*ConsensusView) SetRunning

func (v *ConsensusView) SetRunning()

func (*ConsensusView) SetWorkingHeight added in v0.1.4

func (v *ConsensusView) SetWorkingHeight(workingHeight uint64)

func (*ConsensusView) TryChangeView

func (v *ConsensusView) TryChangeView(now time.Time)

func (*ConsensusView) UpdateDutyIndex

func (v *ConsensusView) UpdateDutyIndex(height uint64)

func (*ConsensusView) UpdateNextProducers added in v0.1.4

func (v *ConsensusView) UpdateNextProducers(producers []peer.PID, totalCount int)

func (*ConsensusView) UpdateProducers added in v0.1.4

func (v *ConsensusView) UpdateProducers(producers [][]byte, totalCount int, spvHeight uint64)

type DBlock

type DBlock interface {
	GetHash() common.Uint256
	GetHeight() uint64
	Nonce() uint64
}

type DPOSNetwork

type DPOSNetwork interface {
	Start()
	Stop() error

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

	UpdatePeers(peers []dpeer.PID)
	GetActivePeers() []p2p.Peer
}

type Dispatcher

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

func NewDispatcher

func NewDispatcher(producers [][]byte, onConfirm func(confirm *payload.Confirm) error,
	unConfirm func(confirm *payload.Confirm) error, tolerance time.Duration, publicKey []byte,
	medianTime dtime.MedianTimeSource, viewListener ViewListener, dposStartHeight uint64) *Dispatcher

func (*Dispatcher) AcceptProposal

func (d *Dispatcher) AcceptProposal(proposal *payload.DPOSProposal, ac account.Account) *msg.Vote

func (*Dispatcher) AddPendingVote

func (d *Dispatcher) AddPendingVote(v *payload.DPOSProposalVote)

func (*Dispatcher) CleanProposals

func (d *Dispatcher) CleanProposals(changeView bool)

func (*Dispatcher) FinishedProposal

func (d *Dispatcher) FinishedProposal(height uint64, sealHash common.Uint256,
	headerTime uint64)

func (*Dispatcher) GetConsensusView

func (d *Dispatcher) GetConsensusView() *ConsensusView

func (*Dispatcher) GetCurrentNeedConnectArbiters added in v0.2.1

func (d *Dispatcher) GetCurrentNeedConnectArbiters() []peer.PID

func (*Dispatcher) GetFinishedBlockSealHash

func (d *Dispatcher) GetFinishedBlockSealHash() common.Uint256

func (*Dispatcher) GetFinishedHeight

func (d *Dispatcher) GetFinishedHeight() uint64

func (*Dispatcher) GetFinishedProposal

func (d *Dispatcher) GetFinishedProposal() common.Uint256

func (*Dispatcher) GetNextNeedConnectArbiters added in v0.2.1

func (d *Dispatcher) GetNextNeedConnectArbiters() []peer.PID

func (*Dispatcher) GetNowTime

func (d *Dispatcher) GetNowTime() time.Time

func (*Dispatcher) GetProcessingProposal

func (d *Dispatcher) GetProcessingProposal() *payload.DPOSProposal

func (*Dispatcher) GetProposalProcessFinished

func (d *Dispatcher) GetProposalProcessFinished() bool

func (*Dispatcher) GetResetViewReqCount added in v0.2.1

func (d *Dispatcher) GetResetViewReqCount() int

func (*Dispatcher) HelpToRecoverAbnormal

func (d *Dispatcher) HelpToRecoverAbnormal(id peer.PID, height uint64, currentHeight uint64) *dmsg.ConsensusStatus

func (*Dispatcher) IsProducer

func (d *Dispatcher) IsProducer(account []byte) bool

func (*Dispatcher) OnChangeView

func (d *Dispatcher) OnChangeView()

func (*Dispatcher) OnResponseResetViewReceived added in v0.2.1

func (d *Dispatcher) OnResponseResetViewReceived(msg *msg.ResetView) error

func (*Dispatcher) ProcessProposal

func (d *Dispatcher) ProcessProposal(id peer.PID, proposal *payload.DPOSProposal) (err error, isSendReject bool, handled bool)

func (*Dispatcher) ProcessVote

func (d *Dispatcher) ProcessVote(vote *payload.DPOSProposalVote) (succeed bool, finished bool, err error)

func (*Dispatcher) ProducerIsOnDuty

func (d *Dispatcher) ProducerIsOnDuty() bool

func (*Dispatcher) RecordViewRequest added in v0.2.1

func (d *Dispatcher) RecordViewRequest(sponsor []byte)

func (*Dispatcher) RecoverAbnormal

func (d *Dispatcher) RecoverAbnormal(status *dmsg.ConsensusStatus, medianTime int64)

func (*Dispatcher) RecoverFromConsensusStatus

func (d *Dispatcher) RecoverFromConsensusStatus(status *dmsg.ConsensusStatus) error

func (*Dispatcher) RejectProposal

func (d *Dispatcher) RejectProposal(proposal *payload.DPOSProposal, ac account.Account) *msg.Vote

func (*Dispatcher) ResetAcceptVotes

func (d *Dispatcher) ResetAcceptVotes()

func (*Dispatcher) ResetConsensus added in v0.2.1

func (d *Dispatcher) ResetConsensus(height uint64)

func (*Dispatcher) ResetView

func (d *Dispatcher) ResetView(parentTime uint64)

func (*Dispatcher) ResetViewRequestIsContain added in v0.2.1

func (d *Dispatcher) ResetViewRequestIsContain(sponsor []byte) bool

func (*Dispatcher) SetProposalProcessFinished

func (d *Dispatcher) SetProposalProcessFinished()

func (*Dispatcher) UpdatePrecociousProposals

func (d *Dispatcher) UpdatePrecociousProposals() *payload.DPOSProposal

type ElaMsg

type ElaMsg struct {
	Type ElaMsgType
	Msg  []byte
}

func (*ElaMsg) Deserialize

func (em *ElaMsg) Deserialize(r io.Reader) error

func (*ElaMsg) Serialize

func (em *ElaMsg) Serialize(w io.Writer) error

type ElaMsgType

type ElaMsgType byte
const (
	Inv ElaMsgType = iota
	GetData
	DAddr
)

type IPeer

type IPeer interface {
	Disconnect()
	SendELAMessage(msg *ElaMsg)
}

type MsgEvent

type MsgEvent struct {
	ElaMsg *ElaMsg
	Peer   IPeer
}

type Network

type Network struct {
	GetCurrentHeight func(pid peer.PID) uint64
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork(cfg *NetworkConfig) (*Network, error)

func (*Network) AddDirectLinkAddr

func (n *Network) AddDirectLinkAddr(pid peer.PID, addr string)

func (*Network) BroadcastMessage

func (n *Network) BroadcastMessage(msg elap2p.Message)

func (*Network) DumpPeersInfo

func (n *Network) DumpPeersInfo() []*p2p.PeerInfo

DumpPeersInfo returns an array consisting of all peers state in connect list.

This function is safe for concurrent access and is part of the IServer interface implementation.

func (*Network) GetActivePeers

func (n *Network) GetActivePeers() []p2p.Peer

func (*Network) PostChangeViewTask

func (n *Network) PostChangeViewTask()

func (*Network) PostRecoverTask

func (n *Network) PostRecoverTask()

func (*Network) SendMessageToPeer

func (n *Network) SendMessageToPeer(id peer.PID, msg elap2p.Message) error

func (*Network) Start

func (n *Network) Start()

func (*Network) Stop

func (n *Network) Stop() error

func (*Network) UpdatePeers

func (n *Network) UpdatePeers(currentPeers []peer.PID, nextPeers []peer.PID)

type NetworkConfig

type NetworkConfig struct {
	IPAddress         string
	Magic             uint32
	DefaultPort       uint16
	MaxNodePerHost    uint32
	DPoSV2StartHeight uint32

	Account    account.Account
	MedianTime dtime.MedianTimeSource
	Listener   NetworkEventListener
	DataPath   string

	NodeVersion        string
	GetCurrentHeight   func(pid peer.PID) uint64
	ProposalDispatcher *Dispatcher
	PublicKey          []byte
	AnnounceAddr       func()
}

type NetworkEventListener

type NetworkEventListener interface {
	StatusSyncEventListener

	OnProposalReceived(id dpeer.PID, proposal *payload.DPOSProposal)
	OnVoteAccepted(id dpeer.PID, proposal *payload.DPOSProposalVote)
	OnVoteRejected(id dpeer.PID, proposal *payload.DPOSProposalVote)

	OnChangeView()
	OnBadNetwork()
	OnRecover()
	OnResponseResetViewReceived(msg *msg.ResetView)

	OnBlockReceived(id dpeer.PID, b *dmsg.BlockMsg, confirmed bool)
	OnConfirmReceived(id dpeer.PID, c *payload.Confirm, height uint64)

	OnSmallCroTxReceived(id dpeer.PID, c *dmsg.SmallCroTx)
	OnFailedWithdrawTxReceived(id dpeer.PID, c *dmsg.FailedWithdrawTx)

	OnLayer2Msg(id dpeer.PID, c elap2p.Message)
}

type Producers

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

func NewProducers

func NewProducers(producers [][]byte, startHeight uint64) *Producers

func (*Producers) ChangeCurrentProducers added in v0.1.4

func (p *Producers) ChangeCurrentProducers(changeHeight uint64, spvHeight uint64)

func (*Producers) GetCRMajorityCount added in v0.1.4

func (p *Producers) GetCRMajorityCount() int

func (*Producers) GetMajorityCount

func (p *Producers) GetMajorityCount() int

func (*Producers) GetMajorityCountByTotalSigners added in v0.1.4

func (p *Producers) GetMajorityCountByTotalSigners(totalSigner int) int

func (*Producers) GetNeedConnectArbiters added in v0.1.4

func (p *Producers) GetNeedConnectArbiters() []peer.PID

func (*Producers) GetNextNeedConnectArbiters added in v0.2.1

func (p *Producers) GetNextNeedConnectArbiters() []peer.PID

func (*Producers) GetNextOnDutyProducer

func (p *Producers) GetNextOnDutyProducer(offset uint32) []byte

func (*Producers) GetProducers

func (p *Producers) GetProducers() [][]byte

func (*Producers) GetProducersCount

func (p *Producers) GetProducersCount() int

func (*Producers) HasArbitersMinorityCount

func (p *Producers) HasArbitersMinorityCount(num int) bool

func (*Producers) HasProducerMajorityCount

func (p *Producers) HasProducerMajorityCount(num int) bool

func (*Producers) IsMajorityAgree

func (p *Producers) IsMajorityAgree(count int) bool

func (*Producers) IsMajorityRejected

func (p *Producers) IsMajorityRejected(count int) bool

func (*Producers) IsProducers

func (p *Producers) IsProducers(signer []byte) bool

func (*Producers) ProducerIndex added in v0.2.0

func (p *Producers) ProducerIndex(signer []byte) int

func (*Producers) SetWorkingHeight added in v0.1.4

func (p *Producers) SetWorkingHeight(changeHeight uint64)

func (*Producers) UpdateDutyIndex

func (p *Producers) UpdateDutyIndex(height uint64) uint32

func (*Producers) UpdateNextProducers added in v0.1.4

func (p *Producers) UpdateNextProducers(producers []peer.PID, totalCount int) error

func (*Producers) UpdateProducers

func (p *Producers) UpdateProducers(producers [][]byte, totalCount int, spvHeight uint64) error

type Routes

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

func New

func New(cfg *Config) *Routes

New creates and return a Routes instance.

func (*Routes) AnnounceAddr

func (r *Routes) AnnounceAddr()

AnnounceAddr schedules an local address announce to the P2P network, it used to re-announce the local address when DPoS network go bad.

func (*Routes) DonePeer

func (r *Routes) DonePeer(peer IPeer)

DonePeer notifies the disconnected peer.

func (*Routes) ElaMsg

func (r *Routes) ElaMsg(msgEvent *MsgEvent)

func (*Routes) NewPeer

func (r *Routes) NewPeer(peer IPeer)

NewPeer notifies the new connected peer.

func (*Routes) OnGetData

func (r *Routes) OnGetData(p IPeer, m *msg.GetData)

OnGetData handles the passed GetData message of the peer.

func (*Routes) PeersChanged

func (r *Routes) PeersChanged(peers []peer.PID)

func (*Routes) QueueInv

func (r *Routes) QueueInv(p IPeer, m *msg.Inv)

QueueInv adds the passed Inv message and peer to the addr handling queue.

func (*Routes) Start

func (r *Routes) Start()

Start starts the Routes instance to sync DPOS addresses.

func (*Routes) Stop

func (r *Routes) Stop()

Stop quits the syncing address handler.

type StatusSyncEventListener

type StatusSyncEventListener interface {
	OnPing(id dpeer.PID, height uint32)
	OnPong(id dpeer.PID, height uint32)
	OnBlock(id dpeer.PID, block *dmsg.BlockMsg)
	OnInv(id dpeer.PID, blockHash common.Uint256)
	OnGetBlock(id dpeer.PID, blockHash common.Uint256)
	OnGetBlocks(id dpeer.PID, startBlockHeight, endBlockHeight uint32)
	OnResponseBlocks(id dpeer.PID, blockConfirms []*dmsg.BlockMsg)
	OnRequestConsensus(id dpeer.PID, height uint64)
	OnResponseConsensus(id dpeer.PID, status *dmsg.ConsensusStatus)
	OnRequestProposal(id dpeer.PID, hash common.Uint256)
	OnIllegalProposalReceived(id dpeer.PID, proposals *payload.DPOSIllegalProposals)
	OnIllegalVotesReceived(id dpeer.PID, votes *payload.DPOSIllegalVotes)
}

type ViewListener

type ViewListener interface {
	OnViewChanged(isOnDuty bool, force bool)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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