grandpa

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockDoesNotExist = errors.New("block does not exist")

ErrBlockDoesNotExist is returned when trying to validate a vote for a block that doesn't exist

View Source
var ErrCannotDecodeSubround = errors.New("cannot decode invalid subround value")

ErrCannotDecodeSubround is returned when a subround value cannot be decoded

View Source
var ErrCatchUpResponseNotCompletable = errors.New("catch up response is not completable")

ErrCatchUpResponseNotCompletable is returned when the round represented by the catch up response is not completable

View Source
var ErrDescendantNotFound = blocktree.ErrDescendantNotFound

ErrDescendantNotFound is returned when trying to validate a vote for a block that isn't a descendant of the last finalized block

View Source
var ErrEquivocation = errors.New("vote is equivocatory")

ErrEquivocation is returned when trying to validate a vote for that is equivocatory

View Source
var ErrGHOSTlessCatchUp = errors.New("catch up response does not contain grandpa-GHOST")

ErrGHOSTlessCatchUp is returned when a catch up response does not contain a valid grandpa-GHOST (ie. finalized block)

View Source
var ErrInvalidCatchUpResponseRound = errors.New("catch up response is not for previous round")

ErrInvalidCatchUpResponseRound is returned when a catch-up response is received with an invalid round

View Source
var ErrInvalidCatchUpRound = errors.New("catch up request is for future round")

ErrInvalidCatchUpRound is returned when a catch-up message is received with an invalid round

View Source
var ErrInvalidMessageType = errors.New("cannot decode invalid message type")

ErrInvalidMessageType is returned when a network.Message cannot be decoded

View Source
var ErrInvalidSignature = errors.New("signature is not valid")

ErrInvalidSignature is returned when trying to validate a vote message with an invalid signature

View Source
var ErrMinVotesNotMet = errors.New("minimum number of votes not met in a Justification")

ErrMinVotesNotMet is returned when the number of votes is less than the required minimum in a Justification

View Source
var ErrNilBlockState = errors.New("cannot have nil BlockState")

ErrNilBlockState is returned when BlockState is nil

View Source
var ErrNilDigestHandler = errors.New("cannot have nil DigestHandler")

ErrNilDigestHandler is returned when DigestHandler is nil

View Source
var ErrNilKeypair = errors.New("cannot have nil keypair")

ErrNilKeypair is returned when the keypair is nil

View Source
var ErrNilNetwork = errors.New("cannot have nil Network")

ErrNilNetwork is returned when the Network is nil

View Source
var ErrNoGHOST = errors.New("cannot determine grandpa-GHOST")

ErrNoGHOST is returned when there is no GHOST. the only case where this could happen is if there are no votes at all, so it shouldn't ever happen.

View Source
var ErrNoJustification = errors.New("no justification found for block")

ErrNoJustification is returned when no justification can be found for a block, ie. it has not been finalized

View Source
var ErrNoPreVotedBlock = errors.New("cannot get pre-voted block")

ErrNoPreVotedBlock is returned when there is no pre-voted block for a round. this can only happen in the case of > 1/3 byzantine nodes (ie > 1/3 nodes equivocate or don't submit valid votes)

View Source
var ErrNotFinalizationMessage = errors.New("cannot get finalized hash from VoteMessage")

ErrNotFinalizationMessage is returned when calling GetFinalizedHash on a message that isn't a FinalizationMessage

View Source
var ErrRoundMismatch = errors.New("rounds do not match")

ErrRoundMismatch is returned when trying to validate a vote message that isn't for the current round

View Source
var ErrServicePaused = errors.New("service is paused")

ErrServicePaused is returned if the service is paused and waiting for catch up messages

View Source
var ErrSetIDMismatch = errors.New("set IDs do not match")

ErrSetIDMismatch is returned when trying to validate a vote message with an invalid voter set ID, or when receiving a catch up message with a different set ID

View Source
var ErrVoterNotFound = errors.New("voter is not in voter set")

ErrVoterNotFound is returned when trying to validate a vote for a voter that isn't in the voter set

Functions

This section is empty.

Types

type BlockState

type BlockState interface {
	GenesisHash() common.Hash
	HasHeader(hash common.Hash) (bool, error)
	GetHeader(hash common.Hash) (*types.Header, error)
	GetHeaderByNumber(num *big.Int) (*types.Header, error)
	IsDescendantOf(parent, child common.Hash) (bool, error)
	HighestCommonAncestor(a, b common.Hash) (common.Hash, error)
	HasFinalizedBlock(round, setID uint64) (bool, error)
	GetFinalizedHeader(uint64, uint64) (*types.Header, error)
	SetFinalizedHash(common.Hash, uint64, uint64) error
	BestBlockHeader() (*types.Header, error)
	BestBlockHash() common.Hash
	Leaves() []common.Hash
	BlocktreeAsString() string
	RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
	UnregisterImportedChannel(id byte)
	RegisterFinalizedChannel(ch chan<- *types.Header) (byte, error)
	UnregisterFinalizedChannel(id byte)
	SetJustification(hash common.Hash, data []byte) error
	HasJustification(hash common.Hash) (bool, error)
	GetJustification(hash common.Hash) ([]byte, error)
}

BlockState is the interface required by GRANDPA into the block state

type Config added in v0.2.0

type Config struct {
	LogLvl        log.Lvl
	BlockState    BlockState
	DigestHandler DigestHandler
	Network       Network
	Voters        []*Voter
	SetID         uint64
	Keypair       *ed25519.Keypair
	Authority     bool
}

Config represents a GRANDPA service configuration

type ConsensusMessage added in v0.2.0

type ConsensusMessage = network.ConsensusMessage

ConsensusMessage is an alias for network.ConsensusMessage

type DigestHandler added in v0.2.0

type DigestHandler interface {
	NextGrandpaAuthorityChange() uint64
}

DigestHandler is the interface required by GRANDPA for the digest handler

type FinalizationMessage

type FinalizationMessage struct {
	Round         uint64
	Vote          *Vote
	Justification []*Justification
}

FinalizationMessage represents a network finalization message

func (*FinalizationMessage) ToConsensusMessage added in v0.2.0

func (f *FinalizationMessage) ToConsensusMessage() (*ConsensusMessage, error)

ToConsensusMessage converts the FinalizationMessage into a network-level consensus message

func (*FinalizationMessage) Type added in v0.2.0

func (f *FinalizationMessage) Type() byte

Type returns finalizationType

type FullJustification added in v0.2.0

type FullJustification []*Justification

FullJustification represents an array of Justifications, used to respond to catch up requests

func (FullJustification) Decode added in v0.2.0

Decode returns a SCALE decoded FullJustification

func (FullJustification) Encode added in v0.2.0

func (j FullJustification) Encode() ([]byte, error)

Encode returns the SCALE encoding of a FullJustification

type FullVote

type FullVote struct {
	Stage subround
	Vote  *Vote
	Round uint64
	SetID uint64
}

FullVote represents a vote with additional information about the state this is encoded and signed and the signature is included in SignedMessage

type GrandpaHandshake added in v0.3.0

type GrandpaHandshake struct {
	Roles byte
}

GrandpaHandshake is exchanged by nodes that are beginning the grandpa protocol

func (*GrandpaHandshake) Decode added in v0.3.0

func (hs *GrandpaHandshake) Decode(in []byte) error

Decode the message into a GrandpaHandshake

func (*GrandpaHandshake) Encode added in v0.3.0

func (hs *GrandpaHandshake) Encode() ([]byte, error)

Encode encodes a GrandpaHandshake message using SCALE

func (*GrandpaHandshake) Hash added in v0.3.0

func (hs *GrandpaHandshake) Hash() common.Hash

Hash ...

func (*GrandpaHandshake) IsHandshake added in v0.3.0

func (hs *GrandpaHandshake) IsHandshake() bool

IsHandshake returns true

func (*GrandpaHandshake) String added in v0.3.0

func (hs *GrandpaHandshake) String() string

String formats a BlockAnnounceHandshake as a string

func (*GrandpaHandshake) SubProtocol added in v0.3.0

func (hs *GrandpaHandshake) SubProtocol() string

SubProtocol returns the grandpa sub-protocol

func (*GrandpaHandshake) Type added in v0.3.0

func (hs *GrandpaHandshake) Type() byte

Type ...

type GrandpaMessage added in v0.3.0

type GrandpaMessage interface {
	ToConsensusMessage() (*network.ConsensusMessage, error)
	Type() byte
}

GrandpaMessage is implemented by all GRANDPA network messages

type Handshake added in v0.3.0

type Handshake = network.Handshake

Handshake is an alias for network.Handshake

type Justification

type Justification struct {
	Vote        *Vote
	Signature   [64]byte
	AuthorityID ed25519.PublicKeyBytes
}

Justification represents a justification for a finalized block

func (*Justification) Decode added in v0.2.0

func (j *Justification) Decode(r io.Reader) (*Justification, error)

Decode returns the SCALE decoded Justification

func (*Justification) Encode added in v0.2.0

func (j *Justification) Encode() ([]byte, error)

Encode returns the SCALE encoded Justification

type Message added in v0.3.0

type Message = network.Message

Message is an alias for network.Message

type MessageHandler added in v0.2.0

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

MessageHandler handles GRANDPA consensus messages

func NewMessageHandler added in v0.2.0

func NewMessageHandler(grandpa *Service, blockState BlockState) *MessageHandler

NewMessageHandler returns a new MessageHandler

type Network added in v0.3.0

type Network interface {
	SendMessage(msg network.NotificationsMessage)
	RegisterNotificationsProtocol(sub protocol.ID,
		messageID byte,
		handshakeGetter network.HandshakeGetter,
		handshakeDecoder network.HandshakeDecoder,
		handshakeValidator network.HandshakeValidator,
		messageDecoder network.MessageDecoder,
		messageHandler network.NotificationsMessageHandler,
	) error
}

Network is the interface required by GRANDPA for the network

type NotificationsMessage added in v0.3.0

type NotificationsMessage = network.NotificationsMessage

NotificationsMessage is an alias for network.NotificationsMessage

type Service

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

Service represents the current state of the grandpa protocol

func NewService

func NewService(cfg *Config) (*Service, error)

NewService returns a new GRANDPA Service instance.

func (*Service) Authorities added in v0.2.0

func (s *Service) Authorities() []*types.Authority

Authorities returns the current grandpa authorities

func (*Service) Start added in v0.2.0

func (s *Service) Start() error

Start begins the GRANDPA finality service

func (*Service) Stop added in v0.2.0

func (s *Service) Stop() error

Stop stops the GRANDPA finality service

func (*Service) UpdateAuthorities added in v0.2.0

func (s *Service) UpdateAuthorities(ad []*types.Authority)

UpdateAuthorities schedules an update to the grandpa voter set and increments the setID at the end of the current round

type SignedMessage

type SignedMessage struct {
	Hash        common.Hash
	Number      uint64
	Signature   [64]byte // ed25519.SignatureLength
	AuthorityID ed25519.PublicKeyBytes
}

SignedMessage represents a block hash and number signed by an authority

func (*SignedMessage) String added in v0.2.0

func (m *SignedMessage) String() string

String returns the SignedMessage as a string

type State

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

State represents a GRANDPA state

func NewState

func NewState(voters []*Voter, setID, round uint64) *State

NewState returns a new GRANDPA state

type Vote

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

Vote represents a vote for a block with the given hash and number

func NewVote

func NewVote(hash common.Hash, number uint64) *Vote

NewVote returns a new Vote given a block hash and number

func NewVoteFromHash

func NewVoteFromHash(hash common.Hash, blockState BlockState) (*Vote, error)

NewVoteFromHash returns a new Vote given a hash and a blockState

func NewVoteFromHeader

func NewVoteFromHeader(h *types.Header) *Vote

NewVoteFromHeader returns a new Vote for a given header

func (*Vote) Decode added in v0.2.0

func (v *Vote) Decode(r io.Reader) (*Vote, error)

Decode returns the SCALE decoded Vote

func (*Vote) Encode added in v0.2.0

func (v *Vote) Encode() ([]byte, error)

Encode returns the SCALE encoding of a Vote

func (*Vote) String

func (v *Vote) String() string

String returns the Vote as a string

type VoteMessage

type VoteMessage struct {
	Round   uint64
	SetID   uint64
	Stage   subround // 0 for pre-vote, 1 for pre-commit
	Message *SignedMessage
}

VoteMessage represents a network-level vote message https://github.com/paritytech/substrate/blob/master/client/finality-grandpa/src/communication/gossip.rs#L336

func (*VoteMessage) ToConsensusMessage added in v0.2.0

func (v *VoteMessage) ToConsensusMessage() (*ConsensusMessage, error)

ToConsensusMessage converts the VoteMessage into a network-level consensus message

func (*VoteMessage) Type added in v0.2.0

func (v *VoteMessage) Type() byte

Type returns voteType or precommitType

type Voter

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

Voter represents a GRANDPA voter

func NewVotersFromAuthorities added in v0.3.0

func NewVotersFromAuthorities(ad []*types.Authority) []*Voter

NewVotersFromAuthorities returns an array of Voters given an array of GrandpaAuthorities

func (*Voter) PublicKeyBytes added in v0.2.0

func (v *Voter) PublicKeyBytes() ed25519.PublicKeyBytes

PublicKeyBytes returns the voter key as PublicKeyBytes

func (*Voter) String added in v0.2.0

func (v *Voter) String() string

String returns a formatted Voter string

type Voters added in v0.2.0

type Voters []*Voter

Voters represents []*Voter

func (Voters) String added in v0.2.0

func (v Voters) String() string

String returns a formatted Voters string

Jump to

Keyboard shortcuts

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