Documentation
¶
Index ¶
- Constants
- func Sign(m Message, privKey ecdsa.PrivateKey) error
- func Verify(m Message) error
- type Blockchain
- type Broadcaster
- type Inbox
- func (inbox *Inbox) F() int
- func (inbox *Inbox) Insert(message Message) (n int, firstTime, firstTimeExceedingF, firstTimeExceeding2F, ... bool)
- func (inbox Inbox) MarshalBinary() ([]byte, error)
- func (inbox Inbox) MarshalJSON() ([]byte, error)
- func (inbox *Inbox) MessageType() MessageType
- func (inbox *Inbox) QueryByHeightRound(height block.Height, round block.Round) (n int)
- func (inbox *Inbox) QueryByHeightRoundBlockHash(height block.Height, round block.Round, blockHash id.Hash) (n int)
- func (inbox *Inbox) QueryByHeightRoundSignatory(height block.Height, round block.Round, sig id.Signatory) Message
- func (inbox *Inbox) QueryMessagesByHeightRound(height block.Height, round block.Round) []Message
- func (inbox *Inbox) QueryMessagesByHeightWithHighestRound(height block.Height) []Message
- func (inbox *Inbox) Reset(height block.Height)
- func (inbox *Inbox) UnmarshalBinary(data []byte) error
- func (inbox *Inbox) UnmarshalJSON(data []byte) error
- type LatestCommit
- type Message
- type MessageType
- type Messages
- type NilReasons
- type Observer
- type Precommit
- func (precommit *Precommit) BlockHash() id.Hash
- func (precommit *Precommit) Height() block.Height
- func (precommit Precommit) MarshalBinary() ([]byte, error)
- func (precommit Precommit) MarshalJSON() ([]byte, error)
- func (precommit *Precommit) Round() block.Round
- func (precommit *Precommit) Sig() id.Signature
- func (precommit *Precommit) SigHash() id.Hash
- func (precommit *Precommit) Signatory() id.Signatory
- func (precommit *Precommit) String() string
- func (precommit *Precommit) Type() MessageType
- func (precommit *Precommit) UnmarshalBinary(data []byte) error
- func (precommit *Precommit) UnmarshalJSON(data []byte) error
- type Precommits
- type Prevote
- func (prevote *Prevote) BlockHash() id.Hash
- func (prevote *Prevote) Height() block.Height
- func (prevote Prevote) MarshalBinary() ([]byte, error)
- func (prevote Prevote) MarshalJSON() ([]byte, error)
- func (prevote *Prevote) NilReasons() NilReasons
- func (prevote *Prevote) Round() block.Round
- func (prevote *Prevote) Sig() id.Signature
- func (prevote *Prevote) SigHash() id.Hash
- func (prevote *Prevote) Signatory() id.Signatory
- func (prevote *Prevote) String() string
- func (prevote *Prevote) Type() MessageType
- func (prevote *Prevote) UnmarshalBinary(data []byte) error
- func (prevote *Prevote) UnmarshalJSON(data []byte) error
- type Prevotes
- type Process
- func (p *Process) HandleMessage(m Message)
- func (p Process) MarshalBinary() ([]byte, error)
- func (p Process) MarshalJSON() ([]byte, error)
- func (p *Process) Start()
- func (p *Process) StartRound(round block.Round)
- func (p *Process) UnmarshalBinary(data []byte) error
- func (p *Process) UnmarshalJSON(data []byte) error
- type Processes
- type Propose
- func (propose *Propose) Block() block.Block
- func (propose *Propose) BlockHash() id.Hash
- func (propose *Propose) Height() block.Height
- func (propose Propose) MarshalBinary() ([]byte, error)
- func (propose Propose) MarshalJSON() ([]byte, error)
- func (propose *Propose) Round() block.Round
- func (propose *Propose) Sig() id.Signature
- func (propose *Propose) SigHash() id.Hash
- func (propose *Propose) Signatory() id.Signatory
- func (propose *Propose) String() string
- func (propose *Propose) Type() MessageType
- func (propose *Propose) UnmarshalBinary(data []byte) error
- func (propose *Propose) UnmarshalJSON(data []byte) error
- func (propose *Propose) ValidRound() block.Round
- type Proposer
- type Proposes
- type Scheduler
- type State
- type Step
- type Timer
- type Validator
Constants ¶
const ( // NilMessageType is invalid and must not be used. NilMessageType = 0 // ProposeMessageType is used by messages that propose blocks for consensus. ProposeMessageType = 1 // PrevoteMessageType is used by messages that are prevoting for block // hashes (or nil prevoting). PrevoteMessageType = 2 // PrecommitMessageType is used by messages that are precommitting for block // hashes (or nil precommitting). PrecommitMessageType = 3 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Blockchain ¶
type Blockchain interface {
InsertBlockAtHeight(block.Height, block.Block)
BlockAtHeight(block.Height) (block.Block, bool)
BlockExistsAtHeight(block.Height) bool
}
A Blockchain defines a storage interface for Blocks that is based around Height.
type Broadcaster ¶
type Broadcaster interface {
Broadcast(Message)
}
A Broadcaster sends a Message to as many Processes in the network as possible.
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
An Inbox is storage container for one type message. Any type of message can be stored, but an attempt to store messages of different types in one inbox will cause a panic. Inboxes are used extensively by the consensus algorithm to track how many messages (of particular types) have been received, and under what conditions. For example, inboxes are used to track when `2F+1` prevote messages have been received for a specific block hash for the first time.
func NewInbox ¶
func NewInbox(f int, messageType MessageType) *Inbox
NewInbox returns an inbox for one type of message. It assumes at most `F` adversaries are present.
func (*Inbox) Insert ¶
func (inbox *Inbox) Insert(message Message) (n int, firstTime, firstTimeExceedingF, firstTimeExceeding2F, firstTimeExceeding2FOnBlockHash bool)
Insert a message into the inbox. It returns:
- `n` the number of unique messages at the height and round of the inserted message (not necessarily for the same block hash),
- `firstTime` whether, or not, this is the first time this message has been seen,
- `firstTimeExceedingF` whether, or not, `n` has exceeded `F` for the first time as a result of this message being inserted,
- `firstTimeExceeding2F` whether, or not, `n` has exceeded `2F` for the first time as a result of this message being inserted, and
- `firstTimeExceeding2FOnBlockHash` whether, or not, this is the first time that more than `2F` unique messages have been seen for the same block.
This method is used extensively for tracking the different conditions under which the state machine is allowed to transition between various states. Its correctness is fundamental to the correctness of the overall implementation.
func (Inbox) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `Inbox` type.
func (Inbox) MarshalJSON ¶
MarshalJSON implements the `json.Marshaler` interface for the `Inbox` type.
func (*Inbox) MessageType ¶
func (inbox *Inbox) MessageType() MessageType
func (*Inbox) QueryByHeightRound ¶
QueryByHeightRound returns the number of unique messages that have been received at the specified height and round. The specific block hash of the messages are ignored and might be different from each other.
func (*Inbox) QueryByHeightRoundBlockHash ¶
func (inbox *Inbox) QueryByHeightRoundBlockHash(height block.Height, round block.Round, blockHash id.Hash) (n int)
QueryByHeightRoundBlockHash returns the number of unique messages that have been received at the specified height and round. Only messages that reference the specified block hash are considered.
func (*Inbox) QueryByHeightRoundSignatory ¶
func (inbox *Inbox) QueryByHeightRoundSignatory(height block.Height, round block.Round, sig id.Signatory) Message
QueryByHeightRoundSignatory the message (or nil) sent by a specific signatory at a specific height and round.
func (*Inbox) QueryMessagesByHeightRound ¶ added in v0.3.2
QueryMessagesByHeightRound returns all unique messages that have been received at the specified height and round. The specific block hash of the messages are ignored and might be different from each other.
func (*Inbox) QueryMessagesByHeightWithHighestRound ¶ added in v0.3.2
QueryMessagesByHeightWithHighestRound returns all unique messages that have been received at the specified height and at the heighest round observed (for the specified height). The specific block hash of the messages are ignored and might be different from each other.
func (*Inbox) Reset ¶
Reset the inbox to a specific height. All messages for height lower than the specified height are dropped. This is necessary to ensure that, over time, the storage space of the inbox is bounded.
func (*Inbox) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `Inbox` type. See the `UnmarshalJSON` method for more information.
func (*Inbox) UnmarshalJSON ¶
UnmarshalJSON implements the `json.Unmarshaler` interface for the `Inbox` type. Before unmarshaling into an inbox, you must initialise it. Unmarshaling will panic if the inbox in not initialised, or if it is initialised with the wrong message type.
type LatestCommit ¶
The LatestCommit can be attached to a proposal. It stores the latest committed block, and a set of precommits that prove this block was committed. This is useful for allowing processes that have fallen out-of-sync to fast forward. See https://github.com/renproject/hyperdrive/wiki/Consensus for more information about fast fowarding.
type Message ¶
type Message interface {
fmt.Stringer
json.Marshaler
json.Unmarshaler
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
// The Signatory that sent the message.
Signatory() id.Signatory
// The SigHash that is expected to by signed by the signatory. This is used
// to authenticate the claimed signatory.
SigHash() id.Hash
// The Signature produced by the signatory signing the sighash. This is used
// to authenticate the claimed signatory.
Sig() id.Signature
// The Height of the blockchain in which this message was broadcast.
Height() block.Height
// The Round of consensus in which this message was broadcast.
Round() block.Round
// The BlockHash of the block to this message concerns. Proposals will be
// proposing the block identified by this hash, prevotes will be prevoting
// for the block identified by this hash (nil prevotes will use
// `InvalidBlockHash`), and precommits will be precommitting for block
// identified by this hash (nil precommits will also use
// `InvalidBlockHash`).
BlockHash() id.Hash
// Type returns the message type of this message. This is useful for
// marshaling/unmarshaling when type information is elided.
Type() MessageType
}
The Message interface defines the common behaviour of all messages that are broadcast throughout the network during consensus rounds.
type MessageType ¶
type MessageType uint64
MessageType distinguished between the three valid (and one invalid) messages types that are supported during consensus rounds.
type NilReasons ¶ added in v0.3.2
NilReasons can be used to provide contextual information alongside an error upon validating blocks.
func (NilReasons) MarshalBinary ¶ added in v0.3.2
func (nilReasons NilReasons) MarshalBinary() ([]byte, error)
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `NilReasons` type.
func (*NilReasons) UnmarshalBinary ¶ added in v0.3.2
func (nilReasons *NilReasons) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `NilReasons` type.
type Observer ¶
type Observer interface {
DidCommitBlock(block.Height)
DidReceiveSufficientNilPrevotes(messages Messages, f int)
}
An Observer is notified when note-worthy events happen for the first time.
type Precommit ¶
type Precommit struct {
// contains filtered or unexported fields
}
Precommit a block hash.
func NewPrecommit ¶
func (Precommit) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `Precommit` type.
func (Precommit) MarshalJSON ¶
MarshalJSON implements the `json.Marshaler` interface for the `Precommit` type.
func (*Precommit) Type ¶
func (precommit *Precommit) Type() MessageType
func (*Precommit) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `Precommit` type.
func (*Precommit) UnmarshalJSON ¶
UnmarshalJSON implements the `json.Unmarshaler` interface for the `Precommit` type.
type Precommits ¶
type Precommits []Precommit
Precommits is a wrapper around the `[]Precommit` type.
type Prevote ¶
type Prevote struct {
// contains filtered or unexported fields
}
Prevote for a block hash.
func NewPrevote ¶
func (Prevote) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `Prevote` type.
func (Prevote) MarshalJSON ¶
MarshalJSON implements the `json.Marshaler` interface for the `Prevote` type.
func (*Prevote) NilReasons ¶ added in v0.3.2
func (prevote *Prevote) NilReasons() NilReasons
func (*Prevote) Type ¶
func (prevote *Prevote) Type() MessageType
func (*Prevote) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `Prevote` type.
func (*Prevote) UnmarshalJSON ¶
UnmarshalJSON implements the `json.Unmarshaler` interface for the `Prevote` type.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
A Process defines a state machine in the distributed replicated state machine. See https://arxiv.org/pdf/1807.04938.pdf for more information.
func New ¶
func New(logger logrus.FieldLogger, signatory id.Signatory, blockchain Blockchain, state State, proposer Proposer, validator Validator, observer Observer, broadcaster Broadcaster, scheduler Scheduler, timer Timer) *Process
New Process initialised to the default state, starting in the first round.
func (*Process) HandleMessage ¶
HandleMessage is safe for concurrent use. See https://arxiv.org/pdf/1807.04938.pdf for more information.
func (Process) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Process type, by marshaling its isolated State.
func (Process) MarshalJSON ¶
MarshalJSON implements the `json.Marshaler` interface for the Process type, by marshaling its isolated State.
func (*Process) StartRound ¶
StartRound is safe for concurrent use. See https://arxiv.org/pdf/1807.04938.pdf for more information.
func (*Process) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Process type, by unmarshaling its isolated State.
func (*Process) UnmarshalJSON ¶
UnmarshalJSON implements the `json.Unmarshaler` interface for the Process type, by unmarshaling its isolated State.
type Processes ¶
type Processes []Process
Processes defines a wrapper type around the []Process type.
type Propose ¶
type Propose struct {
// contains filtered or unexported fields
}
Propose a block for committment.
func NewPropose ¶
func (Propose) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `Propose` type.
func (Propose) MarshalJSON ¶
MarshalJSON implements the `json.Marshaler` interface for the `Propose` type.
func (*Propose) Type ¶
func (propose *Propose) Type() MessageType
func (*Propose) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `Propose` type.
func (*Propose) UnmarshalJSON ¶
UnmarshalJSON implements the `json.Unmarshaler` interface for the `Propose` type.
func (*Propose) ValidRound ¶
type Scheduler ¶
A Scheduler determines which `id.Signatory` should be broadcasting proposals in at a given `block.Height` and `block.Round`.
type State ¶
type State struct {
CurrentHeight block.Height `json:"currentHeight"`
CurrentRound block.Round `json:"currentRound"`
CurrentStep Step `json:"currentStep"`
LockedBlock block.Block `json:"lockedBlock"` // the most recent block for which a precommit message has been sent
LockedRound block.Round `json:"lockedRound"` // the last round in which the process sent a precommit message that is not nil.
ValidBlock block.Block `json:"validBlock"` // store the most recent possible decision value
ValidRound block.Round `json:"validRound"` // is the last round in which valid value is updated
Proposals *Inbox `json:"proposals"`
Prevotes *Inbox `json:"prevotes"`
Precommits *Inbox `json:"precommits"`
}
The State of a Process. It is isolated from the Process so that it can be easily marshaled to/from JSON.
func DefaultState ¶
DefaultState returns a State with all values set to the default. See https://arxiv.org/pdf/1807.04938.pdf for more information.
func (State) MarshalBinary ¶
MarshalBinary implements the `encoding.BinaryMarshaler` interface for the `State` type.
func (*State) Reset ¶
Reset the State (not all values are reset). See https://arxiv.org/pdf/1807.04938.pdf for more information.
func (*State) UnmarshalBinary ¶
UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the `State` type.