Documentation ¶
Overview ¶
Copyright 2020 ChainSafe Systems (ON) Corp. This file is part of gossamer.
The gossamer library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The gossamer library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the gossamer library. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Constants
- Variables
- func EncodeBlockDataArray(bds []*BlockData) ([]byte, error)
- func ExtrinsicsArrayToBytesArray(exts []Extrinsic) [][]byte
- type Authority
- type AuthorityRaw
- type BABEForcedChange
- type BABEScheduledChange
- type BabeConfiguration
- type BabeHeader
- type Block
- type BlockData
- type Body
- type ChangesTrieRootDigest
- type ConsensusDigest
- type ConsensusEngineID
- type DigestItem
- type EpochInfo
- type Extrinsic
- type GrandpaAuthorityDataRaw
- type GrandpaForcedChange
- type GrandpaScheduledChange
- type Header
- type InherentsData
- type OnDisabled
- type Pause
- type PreRuntimeDigest
- type Resume
- type SealDigest
- type SystemInfo
Constants ¶
const ( // NoNetworkRole runs a node without networking NoNetworkRole = byte(0) // FullNodeRole runs a full node FullNodeRole = byte(1) // LightClientRole runs a light client LightClientRole = byte(2) // AuthorityRole runs the node as a block-producing and finalizing node AuthorityRole = byte(4) )
const RandomnessLength = 32
RandomnessLength is the length of the epoch randomness (32 bytes)
Variables ¶
var ( Timstap0 = []byte("timstap0") Babeslot = []byte("babeslot") Finalnum = []byte("finalnum") Uncles00 = []byte("uncles00") )
nolint
var BabeEngineID = ConsensusEngineID{'B', 'A', 'B', 'E'}
BabeEngineID is the hard-coded babe ID
var ChangesTrieRootDigestType = byte(2)
ChangesTrieRootDigestType is the byte representation of ChangesTrieRootDigest
var ConsensusDigestType = byte(4)
ConsensusDigestType is the byte representation of ConsensusDigest
var ForcedChangeType = byte(2)
ForcedChangeType identifies a ForcedChange consensus digest
var GrandpaEngineID = ConsensusEngineID{'F', 'R', 'N', 'K'}
GrandpaEngineID is the hard-coded grandpa ID
var OnDisabledType = byte(3)
OnDisabledType identifies a DisabledChange consensus digest
var PauseType = byte(4)
PauseType identifies a Pause consensus digest
var PreRuntimeDigestType = byte(6)
PreRuntimeDigestType is the byte representation of PreRuntimeDigest
var ResumeType = byte(5)
ResumeType identifies a Resume consensus digest
var ScheduledChangeType = byte(1)
ScheduledChangeType identifies a ScheduledChange consensus digest
var SealDigestType = byte(5)
SealDigestType is the byte representation of SealDigest
Functions ¶
func EncodeBlockDataArray ¶
EncodeBlockDataArray encodes an array of BlockData using SCALE
func ExtrinsicsArrayToBytesArray ¶
ExtrinsicsArrayToBytesArray converts an array of extrinsics into an array of byte arrays
Types ¶
type Authority ¶ added in v0.2.0
Authority struct to hold authority data
func BABEAuthorityRawToAuthority ¶ added in v0.2.0
func BABEAuthorityRawToAuthority(adr []*AuthorityRaw) ([]*Authority, error)
BABEAuthorityRawToAuthority turns a slice of BABE AuthorityRaw into a slice of Authority
func GrandpaAuthorityDataRawToAuthorityData ¶ added in v0.2.0
func GrandpaAuthorityDataRawToAuthorityData(adr []*GrandpaAuthorityDataRaw) ([]*Authority, error)
GrandpaAuthorityDataRawToAuthorityData turns a slice of GrandpaAuthorityDataRaw into a slice of Authority
func NewAuthority ¶ added in v0.2.0
NewAuthority function to create Authority object
func (*Authority) DecodeSr25519 ¶ added in v0.2.0
DecodeSr25519 sets the Authority to the SCALE decoded input for Authority containing SR25519 Keys.
func (*Authority) Encode ¶ added in v0.2.0
Encode returns the SCALE encoding of the BABEAuthorityData.
func (*Authority) FromRawEd25519 ¶ added in v0.2.0
func (a *Authority) FromRawEd25519(raw *GrandpaAuthorityDataRaw) error
FromRawEd25519 sets the Authority given GrandpaAuthorityDataRaw. It converts the byte representations of the authority public keys into a ed25519.PublicKey.
func (*Authority) FromRawSr25519 ¶ added in v0.2.0
func (a *Authority) FromRawSr25519(raw *AuthorityRaw) error
FromRawSr25519 sets the Authority given AuthorityRaw. It converts the byte representations of the authority public keys into a sr25519.PublicKey.
func (*Authority) ToRaw ¶ added in v0.2.0
func (a *Authority) ToRaw() *AuthorityRaw
ToRaw returns the BABEAuthorityData as BABEAuthorityDataRaw. It encodes the authority public keys.
type AuthorityRaw ¶ added in v0.2.0
type AuthorityRaw struct { Key [sr25519.PublicKeyLength]byte Weight uint64 }
AuthorityRaw struct to hold raw authority data
func (*AuthorityRaw) Decode ¶ added in v0.2.0
func (a *AuthorityRaw) Decode(r io.Reader) (*AuthorityRaw, error)
Decode will decode the Reader into a AuthorityRaw
type BABEForcedChange ¶ added in v0.2.0
type BABEForcedChange struct { Auths []*AuthorityRaw Delay uint32 }
BABEForcedChange represents a BABE forced authority change
func (*BABEForcedChange) Encode ¶ added in v0.2.0
func (fc *BABEForcedChange) Encode() ([]byte, error)
Encode returns a SCALE encoded BABEForcedChange with first type byte
type BABEScheduledChange ¶ added in v0.2.0
type BABEScheduledChange struct { Auths []*AuthorityRaw Delay uint32 }
BABEScheduledChange represents a BABE scheduled authority change
func (*BABEScheduledChange) Encode ¶ added in v0.2.0
func (sc *BABEScheduledChange) Encode() ([]byte, error)
Encode returns a SCALE encoded BABEScheduledChange with first type byte
type BabeConfiguration ¶
type BabeConfiguration struct { SlotDuration uint64 // milliseconds EpochLength uint64 // duration of epoch in slots C1 uint64 // (1-(c1/c2)) is the probability of a slot being empty C2 uint64 GenesisAuthorities []*AuthorityRaw Randomness [32]byte SecondarySlots bool }
BabeConfiguration contains the genesis data for BABE see: https://github.com/paritytech/substrate/blob/426c26b8bddfcdbaf8d29f45b128e0864b57de1c/core/consensus/babe/primitives/src/lib.rs#L132
type BabeHeader ¶
type BabeHeader struct { VrfOutput [sr25519.VrfOutputLength]byte VrfProof [sr25519.VrfProofLength]byte BlockProducerIndex uint64 SlotNumber uint64 }
BabeHeader as defined in Polkadot RE Spec, definition 5.10 in section 5.1.4
func (*BabeHeader) Decode ¶
func (bh *BabeHeader) Decode(in []byte) error
Decode performs SCALE decoding of an encoded BabeHeader
func (*BabeHeader) Encode ¶
func (bh *BabeHeader) Encode() []byte
Encode performs SCALE encoding of a BabeHeader
type Block ¶
Block defines a state block
func NewEmptyBlock ¶
func NewEmptyBlock() *Block
NewEmptyBlock returns a new Block with an initialized but empty Header and Body
func (*Block) MustEncode ¶ added in v0.2.0
MustEncode returns the SCALE encoded block and panics if it fails to encode
type BlockData ¶
type BlockData struct { Hash common.Hash Header *optional.Header Body *optional.Body Receipt *optional.Bytes MessageQueue *optional.Bytes Justification *optional.Bytes }
BlockData is stored within the BlockDB
func DecodeBlockDataArray ¶
DecodeBlockDataArray decodes a SCALE encoded BlockData array
type Body ¶
type Body []byte
Body is the encoded extrinsics inside a state block
func NewBodyFromExtrinsicStrings ¶
NewBodyFromExtrinsicStrings creates a block body given an array of hex-encoded 0x-prefixed strings.
func NewBodyFromExtrinsics ¶
NewBodyFromExtrinsics creates a block body given an array of extrinsics.
func NewBodyFromOptional ¶
NewBodyFromOptional returns a Body given an optional.Body. If the optional.Body is None, an error is returned.
func (*Body) AsExtrinsics ¶
AsExtrinsics decodes the body into an array of extrinsics
func (*Body) AsOptional ¶
AsOptional returns the Body as an optional.Body
type ChangesTrieRootDigest ¶
ChangesTrieRootDigest contains the root of the changes trie at a given block, if the runtime supports it.
func (*ChangesTrieRootDigest) Decode ¶
func (d *ChangesTrieRootDigest) Decode(in []byte) error
Decode will decode into ChangesTrieRootDigest Hash
func (*ChangesTrieRootDigest) Encode ¶
func (d *ChangesTrieRootDigest) Encode() ([]byte, error)
Encode will encode the ChangesTrieRootDigestType into byte array
func (*ChangesTrieRootDigest) Type ¶
func (d *ChangesTrieRootDigest) Type() byte
Type returns the type
type ConsensusDigest ¶
type ConsensusDigest struct { ConsensusEngineID ConsensusEngineID Data []byte }
ConsensusDigest contains messages from the runtime to the consensus engine.
func (*ConsensusDigest) DataType ¶ added in v0.2.0
func (d *ConsensusDigest) DataType() byte
DataType returns the data type of the runtime-to-consensus engine message
func (*ConsensusDigest) Decode ¶
func (d *ConsensusDigest) Decode(in []byte) error
Decode will decode into ConsensusEngineID and Data
func (*ConsensusDigest) Encode ¶
func (d *ConsensusDigest) Encode() ([]byte, error)
Encode will encode ConsensusDigest ConsensusEngineID and Data
func (*ConsensusDigest) Type ¶
func (d *ConsensusDigest) Type() byte
Type returns the ConsensusDigest type
type ConsensusEngineID ¶
type ConsensusEngineID [4]byte
ConsensusEngineID is a 4-character identifier of the consensus engine that produced the digest.
func NewConsensusEngineID ¶
func NewConsensusEngineID(in []byte) (res ConsensusEngineID)
NewConsensusEngineID casts a byte array to ConsensusEngineID if the input is longer than 4 bytes, it takes the first 4 bytes
func (ConsensusEngineID) ToBytes ¶
func (h ConsensusEngineID) ToBytes() []byte
ToBytes turns ConsensusEngineID to a byte array
type DigestItem ¶
type DigestItem interface { Type() byte Encode() ([]byte, error) Decode([]byte) error // Decode assumes the type byte (first byte) has been removed from the encoding. }
DigestItem can be of one of four types of digest: ChangesTrieRootDigest, PreRuntimeDigest, ConsensusDigest, or SealDigest. see https://github.com/paritytech/substrate/blob/f548309478da3935f72567c2abc2eceec3978e9f/primitives/runtime/src/generic/digest.rs#L77
func DecodeDigestItem ¶
func DecodeDigestItem(in []byte) (DigestItem, error)
DecodeDigestItem will decode byte array to DigestItem
type EpochInfo ¶ added in v0.2.0
type EpochInfo struct { Duration uint64 // number of slots in the epoch FirstBlock uint64 // number of the first block in the epoch Randomness [RandomnessLength]byte }
EpochInfo is internal BABE information for a given epoch
type Extrinsic ¶
type Extrinsic []byte
Extrinsic is a generic transaction whose format is verified in the runtime
func BytesArrayToExtrinsics ¶
BytesArrayToExtrinsics converts an array of byte arrays into an array of extrinsics
func NewExtrinsic ¶
NewExtrinsic creates a new Extrinsic given a byte slice
type GrandpaAuthorityDataRaw ¶ added in v0.2.0
type GrandpaAuthorityDataRaw struct { Key [ed25519.PublicKeyLength]byte ID uint64 }
GrandpaAuthorityDataRaw represents a GRANDPA authority where their key is a byte array
func (*GrandpaAuthorityDataRaw) Decode ¶ added in v0.2.0
func (a *GrandpaAuthorityDataRaw) Decode(r io.Reader) (*GrandpaAuthorityDataRaw, error)
Decode will decode the Reader into a GrandpaAuthorityDataRaw
type GrandpaForcedChange ¶ added in v0.2.0
type GrandpaForcedChange struct { Auths []*GrandpaAuthorityDataRaw Delay uint32 }
GrandpaForcedChange represents a GRANDPA forced authority change
func (*GrandpaForcedChange) Encode ¶ added in v0.2.0
func (fc *GrandpaForcedChange) Encode() ([]byte, error)
Encode returns a SCALE encoded GrandpaForcedChange with first type byte
type GrandpaScheduledChange ¶ added in v0.2.0
type GrandpaScheduledChange struct { Auths []*GrandpaAuthorityDataRaw Delay uint32 }
GrandpaScheduledChange represents a GRANDPA scheduled authority change
func (*GrandpaScheduledChange) Encode ¶ added in v0.2.0
func (sc *GrandpaScheduledChange) Encode() ([]byte, error)
Encode returns a SCALE encoded GrandpaScheduledChange with first type byte
type Header ¶
type Header struct { ParentHash common.Hash `json:"parentHash"` Number *big.Int `json:"number"` StateRoot common.Hash `json:"stateRoot"` ExtrinsicsRoot common.Hash `json:"extrinsicsRoot"` Digest [][]byte `json:"digest"` // contains filtered or unexported fields }
Header is a state block header
func NewHeader ¶
func NewHeader(parentHash common.Hash, number *big.Int, stateRoot common.Hash, extrinsicsRoot common.Hash, digest [][]byte) (*Header, error)
NewHeader creates a new block header and sets its hash field
func NewHeaderFromOptional ¶
NewHeaderFromOptional returns a Header given an optional.Header. If the optional.Header is None, an error is returned.
func (*Header) AsOptional ¶
AsOptional returns the Header as an optional.Header
func (*Header) DeepCopy ¶
DeepCopy returns a deep copy of the header to prevent side effects down the road
func (*Header) Hash ¶
Hash returns the hash of the block header If the internal hash field is nil, it hashes the block and sets the hash field. If hashing the header errors, this will panic.
func (*Header) MustEncode ¶ added in v0.2.0
MustEncode returns the SCALE encoded header and panics if it fails to encode
type InherentsData ¶ added in v0.2.0
type InherentsData struct {
// contains filtered or unexported fields
}
InherentsData contains a mapping of inherent keys to values keys must be 8 bytes, values are a scale-encoded byte array
func NewInherentsData ¶ added in v0.2.0
func NewInherentsData() *InherentsData
NewInherentsData returns InherentsData
func (*InherentsData) Encode ¶ added in v0.2.0
func (d *InherentsData) Encode() ([]byte, error)
Encode will encode a given []byte using scale.Encode
func (*InherentsData) SetBigIntInherent ¶ added in v0.2.0
func (d *InherentsData) SetBigIntInherent(key []byte, data *big.Int) error
SetBigIntInherent set as a big.Int (compact int) inherent
func (*InherentsData) SetInt64Inherent ¶ added in v0.2.0
func (d *InherentsData) SetInt64Inherent(key []byte, data uint64) error
SetInt64Inherent set the Int64 scale.Encode for a given data
func (*InherentsData) String ¶ added in v0.2.0
func (d *InherentsData) String() string
type OnDisabled ¶ added in v0.2.0
type OnDisabled struct {
ID uint64
}
OnDisabled represents a GRANDPA authority being disabled
func (*OnDisabled) Encode ¶ added in v0.2.0
func (od *OnDisabled) Encode() ([]byte, error)
Encode returns a SCALE encoded OnDisabled with first type byte
type Pause ¶ added in v0.2.0
type Pause struct {
Delay uint32
}
Pause represents an authority set pause
type PreRuntimeDigest ¶
type PreRuntimeDigest struct { ConsensusEngineID ConsensusEngineID Data []byte }
PreRuntimeDigest contains messages from the consensus engine to the runtime.
func (*PreRuntimeDigest) Decode ¶
func (d *PreRuntimeDigest) Decode(in []byte) error
Decode will decode PreRuntimeDigest ConsensusEngineID and Data
func (*PreRuntimeDigest) Encode ¶
func (d *PreRuntimeDigest) Encode() ([]byte, error)
Encode will encode PreRuntimeDigest ConsensusEngineID and Data
func (*PreRuntimeDigest) Type ¶
func (d *PreRuntimeDigest) Type() byte
Type will return PreRuntimeDigestType
type Resume ¶ added in v0.2.0
type Resume struct {
Delay uint32
}
Resume represents an authority set resume
type SealDigest ¶
type SealDigest struct { ConsensusEngineID ConsensusEngineID Data []byte }
SealDigest contains the seal or signature. This is only used by native code.
func (*SealDigest) Decode ¶
func (d *SealDigest) Decode(in []byte) error
Decode will decode into SealDigest ConsensusEngineID and Data
func (*SealDigest) Encode ¶
func (d *SealDigest) Encode() ([]byte, error)
Encode will encode SealDigest ConsensusEngineID and Data