Documentation ¶
Index ¶
- Variables
- type BlockState
- type Config
- type ConsensusMessage
- type DigestHandler
- type FinalizationMessage
- type FullJustification
- type FullVote
- type GrandpaHandshake
- func (hs *GrandpaHandshake) Decode(in []byte) error
- func (hs *GrandpaHandshake) Encode() ([]byte, error)
- func (hs *GrandpaHandshake) Hash() common.Hash
- func (hs *GrandpaHandshake) IsHandshake() bool
- func (hs *GrandpaHandshake) String() string
- func (hs *GrandpaHandshake) SubProtocol() string
- func (hs *GrandpaHandshake) Type() byte
- type GrandpaMessage
- type Handshake
- type Justification
- type Message
- type MessageHandler
- type Network
- type NotificationsMessage
- type Service
- type SignedMessage
- type State
- type Vote
- type VoteMessage
- type Voter
- type Voters
Constants ¶
This section is empty.
Variables ¶
var ErrBlockDoesNotExist = errors.New("block does not exist")
ErrBlockDoesNotExist is returned when trying to validate a vote for a block that doesn't exist
var ErrCannotDecodeSubround = errors.New("cannot decode invalid subround value")
ErrCannotDecodeSubround is returned when a subround value cannot be decoded
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
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
var ErrEquivocation = errors.New("vote is equivocatory")
ErrEquivocation is returned when trying to validate a vote for that is equivocatory
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)
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
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
var ErrInvalidMessageType = errors.New("cannot decode invalid message type")
ErrInvalidMessageType is returned when a network.Message cannot be decoded
var ErrInvalidSignature = errors.New("signature is not valid")
ErrInvalidSignature is returned when trying to validate a vote message with an invalid signature
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
var ErrNilBlockState = errors.New("cannot have nil BlockState")
ErrNilBlockState is returned when BlockState is nil
var ErrNilDigestHandler = errors.New("cannot have nil DigestHandler")
ErrNilDigestHandler is returned when DigestHandler is nil
var ErrNilKeypair = errors.New("cannot have nil keypair")
ErrNilKeypair is returned when the keypair is nil
var ErrNilNetwork = errors.New("cannot have nil Network")
ErrNilNetwork is returned when the Network is nil
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.
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
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)
var ErrNotFinalizationMessage = errors.New("cannot get finalized hash from VoteMessage")
ErrNotFinalizationMessage is returned when calling GetFinalizedHash on a message that isn't a FinalizationMessage
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
var ErrServicePaused = errors.New("service is paused")
ErrServicePaused is returned if the service is paused and waiting for catch up messages
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
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
func (j FullJustification) Decode(r io.Reader) (FullJustification, error)
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 ¶
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
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 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 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 ¶
NewService returns a new GRANDPA Service instance.
func (*Service) Authorities ¶ added in v0.2.0
Authorities returns the current grandpa authorities
func (*Service) UpdateAuthorities ¶ added in v0.2.0
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
type Vote ¶
type Vote struct {
// contains filtered or unexported fields
}
Vote represents a vote for a block with the given 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 ¶
NewVoteFromHeader returns a new Vote for a given header
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
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