tendermint

package
v0.0.9-Bytes Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeoutPropose   = time.Duration(10) * time.Second
	TimeoutPreVote   = time.Duration(10) * time.Second
	TimeoutPreCommit = time.Duration(10) * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicMessage

type BasicMessage struct {
	SourceId    int
	HeightRound HeightRound
}

type ChangeStateEvent

type ChangeStateEvent struct {
	NewStepType StepType
	HeightRound HeightRound
}

type DefaultPartner

type DefaultPartner struct {
	PartnerBase
	CurrentHR HeightRound // Partner's current Height/Round

	N     int       // total number of participants
	F     int       // max number of Byzantines
	Peers []Partner // All peers

	States map[HeightRound]*HeightRoundState // for line 55, record state for every HeightRound
	// contains filtered or unexported fields
}

DefaultPartner implements a Tendermint client according to "The latest gossip on BFT consensus" Destroy and use a new one upon peers changing.

func NewPartner

func NewPartner(nbParticipants int, id int, blockTime time.Duration) *DefaultPartner

func (*DefaultPartner) Broadcast

func (p *DefaultPartner) Broadcast(messageType MessageType, hr HeightRound, content Proposal, validRound int)

Multicast announce messages to all partners

func (*DefaultPartner) EventLoop

func (p *DefaultPartner) EventLoop()

func (*DefaultPartner) GetId

func (p *DefaultPartner) GetId() int

func (*DefaultPartner) GetIncomingMessageChannel

func (p *DefaultPartner) GetIncomingMessageChannel() chan Message

func (*DefaultPartner) GetOutgoingMessageChannel

func (p *DefaultPartner) GetOutgoingMessageChannel() chan Message

func (*DefaultPartner) GetValue

func (p *DefaultPartner) GetValue() Proposal

GetValue generates the value requiring consensus

func (*DefaultPartner) GetWaiterTimeoutChannel

func (p *DefaultPartner) GetWaiterTimeoutChannel() chan *WaiterRequest

func (*DefaultPartner) OnTimeoutPreCommit

func (p *DefaultPartner) OnTimeoutPreCommit(context WaiterContext)

OnTimeoutPreCommit is the callback after staying too long on precommit step

func (*DefaultPartner) OnTimeoutPreVote

func (p *DefaultPartner) OnTimeoutPreVote(context WaiterContext)

OnTimeoutPreVote is the callback after staying too long on prevote step

func (*DefaultPartner) OnTimeoutPropose

func (p *DefaultPartner) OnTimeoutPropose(context WaiterContext)

OnTimeoutPropose is the callback after staying too long on propose step

func (*DefaultPartner) Proposer

func (p *DefaultPartner) Proposer(hr HeightRound) int

Proposer returns current round proposer. Now simply round robin

func (*DefaultPartner) SetPeers

func (p *DefaultPartner) SetPeers(peers []Partner)

func (*DefaultPartner) StartNewEra

func (p *DefaultPartner) StartNewEra(height int, round int)

StartNewEra is called once height or round needs to be changed.

func (*DefaultPartner) WaitStepTimeout

func (p *DefaultPartner) WaitStepTimeout(stepType StepType, timeout time.Duration, hr HeightRound, timeoutCallback func(WaiterContext))

WaitStepTimeout waits for a centain time if stepType stays too long

func (*DefaultPartner) WipeOldStates

func (p *DefaultPartner) WipeOldStates()

type HeightRound

type HeightRound struct {
	Height int
	Round  int
}

HeightRound is the current progress of the consensus. Height is the block height, round is the sub-progress if no consensus can be easily reached

func (*HeightRound) IsAfter

func (h *HeightRound) IsAfter(o HeightRound) bool

IsAfter judges whether self is a higher HeightRound

func (*HeightRound) IsAfterOrEqual

func (h *HeightRound) IsAfterOrEqual(o HeightRound) bool

IsAfterOrEqual judges whether self is a higher or equal HeightRound

func (*HeightRound) IsBefore

func (h *HeightRound) IsBefore(o HeightRound) bool

IsAfterOrEqual judges whether self is a lower HeightRound

func (*HeightRound) String

func (h *HeightRound) String() string

type HeightRoundState

type HeightRoundState struct {
	MessageProposal                       *MessageProposal // the proposal received in this round
	LockedValue                           Proposal
	LockedRound                           int
	ValidValue                            Proposal
	ValidRound                            int
	Decision                              interface{}          // final decision of mine in this round
	PreVotes                              []*MessageCommonVote // other peers' PreVotes
	PreCommits                            []*MessageCommonVote // other peers' PreCommits
	Sources                               map[int]bool         // for line 55, who send future round so that I may advance?
	StepTypeEqualPreVoteTriggered         bool                 // for line 34, FIRST time trigger
	StepTypeEqualOrLargerPreVoteTriggered bool                 // for line 36, FIRST time trigger
	StepTypeEqualPreCommitTriggered       bool                 // for line 47, FIRST time trigger
	Step                                  StepType             // current step in this round
}

HeightRoundState is the structure for each Height/Round Always keep this state that is higher than current in Partner.States map in order not to miss future things

func NewHeightRoundState

func NewHeightRoundState(total int) *HeightRoundState

type Message

type Message struct {
	Type    MessageType
	Payload interface{}
}

func (*Message) String

func (m *Message) String() string

type MessageCommonVote

type MessageCommonVote struct {
	BasicMessage
	Idv string // ID of the proposal, usually be the hash of the proposal
}

type MessageProposal

type MessageProposal struct {
	BasicMessage
	Value      Proposal
	ValidRound int
}

type MessageType

type MessageType int
const (
	MessageTypeProposal MessageType = iota
	MessageTypePreVote
	MessageTypePreCommit
)

func (MessageType) String

func (m MessageType) String() string

type Partner

type Partner interface {
	EventLoop()
	StartNewEra(height int, round int)
	SetPeers(peers []Partner)
	GetIncomingMessageChannel() chan Message
	GetOutgoingMessageChannel() chan Message
	GetWaiterTimeoutChannel() chan *WaiterRequest
	GetId() int
}

Partner is a participant in the consensus.

type PartnerBase

type PartnerBase struct {
	Id                     int
	IncomingMessageChannel chan Message
	OutgoingMessageChannel chan Message
	WaiterTimeoutChannel   chan *WaiterRequest
}

type Proposal

type Proposal interface {
	Equal(Proposal) bool
	GetId() string
}

type StepType

type StepType int
const (
	StepTypePropose StepType = iota
	StepTypePreVote
	StepTypePreCommit
)

func (StepType) IsAfter

func (m StepType) IsAfter(o StepType) bool

func (StepType) String

func (m StepType) String() string

type StringProposal

type StringProposal string

func (StringProposal) Equal

func (s StringProposal) Equal(o Proposal) bool

func (StringProposal) GetId

func (s StringProposal) GetId() string

type TendermintContext

type TendermintContext struct {
	HeightRound HeightRound
	StepType    StepType
}

func (*TendermintContext) Equal

func (t *TendermintContext) Equal(w WaiterContext) bool

func (*TendermintContext) IsAfter

func (t *TendermintContext) IsAfter(w WaiterContext) bool

type ValueIdMatchType

type ValueIdMatchType int
const (
	MatchTypeAny ValueIdMatchType = iota
	MatchTypeByValue
	MatchTypeNil
)

type Waiter

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

Waiter provides a way to wait for some context to be changed in a certain time. If the context is not changed, callback function will be triggered.

func NewWaiter

func NewWaiter(callbackEventChannel chan *WaiterRequest) *Waiter

func (*Waiter) StartEventLoop

func (w *Waiter) StartEventLoop()

func (*Waiter) UpdateContext

func (w *Waiter) UpdateContext(context WaiterContext)

func (*Waiter) UpdateRequest

func (w *Waiter) UpdateRequest(req *WaiterRequest)

type WaiterContext

type WaiterContext interface {
	Equal(WaiterContext) bool
	IsAfter(WaiterContext) bool
}

type WaiterRequest

type WaiterRequest struct {
	WaitTime        time.Duration
	Context         WaiterContext
	TimeoutCallback func(WaiterContext)
}

Jump to

Keyboard shortcuts

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