process

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NilMessageType       = 0
	ProposeMessageType   = 1
	PrevoteMessageType   = 2
	PrecommitMessageType = 3
)

Variables

This section is empty.

Functions

func Sign

func Sign(m Message, privKey ecdsa.PrivateKey) error

func Verify

func Verify(m Message) error

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
}

func NewInbox

func NewInbox(f int, messageType MessageType) *Inbox

func (*Inbox) F

func (inbox *Inbox) F() int

func (*Inbox) Insert

func (inbox *Inbox) Insert(message Message) (n int, firstTime, firstTimeExceedingF, firstTimeExceeding2F, firstTimeExceeding2FOnBlockHash bool)

func (Inbox) MarshalBinary

func (inbox Inbox) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Inbox type.

func (Inbox) MarshalJSON

func (inbox Inbox) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Inbox type.

func (*Inbox) MessageType

func (inbox *Inbox) MessageType() MessageType

func (*Inbox) QueryByHeightRound

func (inbox *Inbox) QueryByHeightRound(height block.Height, round block.Round) (n int)

func (*Inbox) QueryByHeightRoundBlockHash

func (inbox *Inbox) QueryByHeightRoundBlockHash(height block.Height, round block.Round, blockHash id.Hash) (n int)

func (*Inbox) QueryByHeightRoundSignatory

func (inbox *Inbox) QueryByHeightRoundSignatory(height block.Height, round block.Round, sig id.Signatory) Message

func (*Inbox) QueryMessagesByHeightWithHigestRound

func (inbox *Inbox) QueryMessagesByHeightWithHigestRound(height block.Height) []Message

func (*Inbox) Reset

func (inbox *Inbox) Reset(height block.Height)

func (*Inbox) UnmarshalBinary

func (inbox *Inbox) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Inbox type.

func (*Inbox) UnmarshalJSON

func (inbox *Inbox) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Inbox type. Note : you need to be really careful when doing unmarshaling, specifically you need to initialize the inbox with the expected messageType. Otherwise it would panic.

type LatestCommit

type LatestCommit struct {
	Block      block.Block
	Precommits []Precommit
}

type Message

type Message interface {
	fmt.Stringer
	json.Marshaler
	json.Unmarshaler
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	Signatory() id.Signatory
	SigHash() id.Hash
	Sig() id.Signature

	Height() block.Height
	Round() block.Round
	BlockHash() id.Hash

	Type() MessageType
}

type MessageType

type MessageType uint64

type Messages

type Messages []Message

type Observer

type Observer interface {
	DidCommitBlock(block.Height)
}

An Observer is notified when note-worthy events happen for the first time.

type Precommit

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

func NewPrecommit

func NewPrecommit(height block.Height, round block.Round, blockHash id.Hash) *Precommit

func (*Precommit) BlockHash

func (precommit *Precommit) BlockHash() id.Hash

func (*Precommit) Height

func (precommit *Precommit) Height() block.Height

func (Precommit) MarshalBinary

func (precommit Precommit) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Precommit type.

func (Precommit) MarshalJSON

func (precommit Precommit) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Precommit type.

func (*Precommit) Round

func (precommit *Precommit) Round() block.Round

func (*Precommit) Sig

func (precommit *Precommit) Sig() id.Signature

func (*Precommit) SigHash

func (precommit *Precommit) SigHash() id.Hash

func (*Precommit) Signatory

func (precommit *Precommit) Signatory() id.Signatory

func (*Precommit) String

func (precommit *Precommit) String() string

func (*Precommit) Type

func (precommit *Precommit) Type() MessageType

func (*Precommit) UnmarshalBinary

func (precommit *Precommit) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Precommit type.

func (*Precommit) UnmarshalJSON

func (precommit *Precommit) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Precommit type.

type Precommits

type Precommits []Precommit

type Prevote

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

func NewPrevote

func NewPrevote(height block.Height, round block.Round, blockHash id.Hash) *Prevote

func (*Prevote) BlockHash

func (prevote *Prevote) BlockHash() id.Hash

func (*Prevote) Height

func (prevote *Prevote) Height() block.Height

func (Prevote) MarshalBinary

func (prevote Prevote) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Prevote type.

func (Prevote) MarshalJSON

func (prevote Prevote) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Prevote type.

func (*Prevote) Round

func (prevote *Prevote) Round() block.Round

func (*Prevote) Sig

func (prevote *Prevote) Sig() id.Signature

func (*Prevote) SigHash

func (prevote *Prevote) SigHash() id.Hash

func (*Prevote) Signatory

func (prevote *Prevote) Signatory() id.Signatory

func (*Prevote) String

func (prevote *Prevote) String() string

func (*Prevote) Type

func (prevote *Prevote) Type() MessageType

func (*Prevote) UnmarshalBinary

func (prevote *Prevote) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Prevote type.

func (*Prevote) UnmarshalJSON

func (prevote *Prevote) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Prevote type.

type Prevotes

type Prevotes []Prevote

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

func (p *Process) HandleMessage(m Message)

HandleMessage is safe for concurrent use. See https://arxiv.org/pdf/1807.04938.pdf for more information.

func (Process) MarshalBinary

func (p Process) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Process type, by marshaling its isolated State.

func (Process) MarshalJSON

func (p Process) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Process type, by marshaling its isolated State.

func (*Process) Start

func (p *Process) Start()

Start the process

func (*Process) StartRound

func (p *Process) StartRound(round block.Round)

StartRound is safe for concurrent use. See https://arxiv.org/pdf/1807.04938.pdf for more information.

func (*Process) UnmarshalBinary

func (p *Process) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Process type, by unmarshaling its isolated State.

func (*Process) UnmarshalJSON

func (p *Process) UnmarshalJSON(data []byte) error

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
}

func NewPropose

func NewPropose(height block.Height, round block.Round, block block.Block, validRound block.Round) *Propose

func (*Propose) Block

func (propose *Propose) Block() block.Block

func (*Propose) BlockHash

func (propose *Propose) BlockHash() id.Hash

func (*Propose) Height

func (propose *Propose) Height() block.Height

func (Propose) MarshalBinary

func (propose Propose) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the Propose type.

func (Propose) MarshalJSON

func (propose Propose) MarshalJSON() ([]byte, error)

MarshalJSON implements the `json.Marshaler` interface for the Propose type.

func (*Propose) Round

func (propose *Propose) Round() block.Round

func (*Propose) Sig

func (propose *Propose) Sig() id.Signature

func (*Propose) SigHash

func (propose *Propose) SigHash() id.Hash

func (*Propose) Signatory

func (propose *Propose) Signatory() id.Signatory

func (*Propose) String

func (propose *Propose) String() string

func (*Propose) Type

func (propose *Propose) Type() MessageType

func (*Propose) UnmarshalBinary

func (propose *Propose) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the Propose type.

func (*Propose) UnmarshalJSON

func (propose *Propose) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the `json.Unmarshaler` interface for the Propose type.

func (*Propose) ValidRound

func (propose *Propose) ValidRound() block.Round

type Proposer

type Proposer interface {
	BlockProposal(block.Height, block.Round) block.Block
}

A Proposer builds a `block.Block` for proposals.

type Proposes

type Proposes []Propose

type Scheduler

type Scheduler interface {
	Schedule(block.Height, block.Round) id.Signatory
}

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

func DefaultState(f int) State

DefaultState returns a State with all values set to the default. See https://arxiv.org/pdf/1807.04938.pdf for more information.

func (*State) Equal

func (state *State) Equal(other State) bool

Equal compares one State with another.

func (State) MarshalBinary

func (state State) MarshalBinary() ([]byte, error)

MarshalBinary implements the `encoding.BinaryMarshaler` interface for the State type.

func (*State) Reset

func (state *State) Reset(height block.Height)

Reset the State (not all values are reset). See https://arxiv.org/pdf/1807.04938.pdf for more information.

func (*State) UnmarshalBinary

func (state *State) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the `encoding.BinaryUnmarshaler` interface for the State type.

type Step

type Step uint8

Step in the consensus algorithm.

const (
	StepNil Step = iota
	StepPropose
	StepPrevote
	StepPrecommit
)

Define all Steps.

type Timer

type Timer interface {
	Timeout(step Step, round block.Round) time.Duration
}

A Timer determines the timeout duration at a given Step and `block.Round`.

type Validator

type Validator interface {
	IsBlockValid(block block.Block, checkHistory bool) error
}

A Validator validates a `block.Block` that has been proposed.

Jump to

Keyboard shortcuts

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