istanbul

package
v1.8.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsensusMsg           = 0x11
	QueryEnodeMsg          = 0x12
	ValEnodesShareMsg      = 0x13
	FwdMsg                 = 0x14
	DelegateSignMsg        = 0x15
	VersionCertificatesMsg = 0x16
	EnodeCertificateMsg    = 0x17
	ValidatorHandshakeMsg  = 0x18
)

Message codes for istanbul related messages If you want to add a code, you need to increment the protocolLengths Array size and update the IsIstanbulMsg function below!

View Source
const (
	DEPRECATED_MsgPreprepare uint64 = iota // Moved to V2
	MsgPrepare
	MsgCommit
	DEPRECATED_MsgRoundChange // Moved to V2
	MsgRoundChangeV2
	MsgPreprepareV2
)
View Source
const (
	// Supported versions
	Celo67 = 67 // incorporates changes from eth/66 (EIP-2481)
)

Constants to match up protocol versions and messages

View Source
const (
	//MinEpochSize represents the minimum permissible epoch size
	MinEpochSize = 3
)
View Source
const ProtocolName = "istanbul"

protocolName is the official short name of the protocol used during capability negotiation.

Variables

View Source
var (
	// ErrUnauthorizedAddress is returned when given address cannot be found in
	// current validator set.
	ErrUnauthorizedAddress = errors.New("not an elected validator")
	// ErrInvalidSigner is returned if a message's signature does not correspond to the address in msg.Address
	ErrInvalidSigner = errors.New("signed by incorrect validator")
	// ErrStoppedEngine is returned if the engine is stopped
	ErrStoppedEngine = errors.New("stopped engine")
	// ErrStartedEngine is returned if the engine is already started
	ErrStartedEngine = errors.New("started engine")
	// ErrStoppedAnnounce is returned if announce is stopped
	ErrStoppedAnnounce = errors.New("stopped announce")
	// ErrStartedAnnounce is returned if announce is already started
	ErrStartedAnnounce = errors.New("started announce")
	// ErrStoppedProxiedValidatorEngine is returned if proxied validator engine is stopped
	ErrStoppedProxiedValidatorEngine = errors.New("stopped proxied validator engine")
	// ErrStartedProxiedValidatorEngine is returned if proxied validator engine is already started
	ErrStartedProxiedValidatorEngine = errors.New("started proxied validator engine")
	// ErrStoppedVPHThread is returned if validator peer handler thread is stopped
	ErrStoppedVPHThread = errors.New("stopped validator peer handler thread")
	// ErrStartedVPHThread is returned if validator peer handler thread is already started
	ErrStartedVPHThread = errors.New("started validator peer handler thread")
	// ErrValidatorNotProxied is returned if the validator is not configured to be proxied
	ErrValidatorNotProxied = errors.New("validator not proxied")
	// ErrInvalidEnodeCertMsgMapOldVersion is returned if a validator sends old enode certificate message
	ErrInvalidEnodeCertMsgMapOldVersion = errors.New("invalid enode certificate message map because of old version")
)
View Source
var DefaultConfig = &Config{
	RequestTimeout:                 3000,
	TimeoutBackoffFactor:           1000,
	MinResendRoundChangeTimeout:    15 * 1000,
	MaxResendRoundChangeTimeout:    2 * 60 * 1000,
	BlockPeriod:                    5,
	ProposerPolicy:                 ShuffledRoundRobin,
	Epoch:                          30000,
	DefaultLookbackWindow:          12,
	ReplicaStateDBPath:             "replicastate",
	ValidatorEnodeDBPath:           "validatorenodes",
	VersionCertificateDBPath:       "versioncertificates",
	RoundStateDBPath:               "roundstates",
	Validator:                      false,
	Replica:                        false,
	Proxy:                          false,
	Proxied:                        false,
	AnnounceQueryEnodeGossipPeriod: 300,
	AnnounceAggressiveQueryEnodeGossipOnEnablement: true,
	AnnounceAdditionalValidatorsToGossip:           10,
	LoadTestCSVFile:                                "",
}

DefaultConfig for istanbul consensus engine

View Source
var ProtocolLengths = map[uint]uint64{Celo67: 25}

protocolLengths are the number of implemented message corresponding to different protocol versions. celo/67, uses as the last message the 0x18, so it has 25 messages (including the 0x00)

View Source
var ProtocolVersions = []uint{Celo67}

ProtocolVersions are the supported versions of the istanbul protocol (first is primary). (First is primary in the sense that it's the most current one supported)

Functions

func ApplyParamsChainConfigToConfig

func ApplyParamsChainConfigToConfig(chainConfig *params.ChainConfig, config *Config) error

ApplyParamsChainConfigToConfig applies the istanbul config values from params.chainConfig to the istanbul.Config config

func CheckSignedBy added in v1.7.1

func CheckSignedBy(p PayloadNoSig, signature []byte, signer common.Address, wrongSignatureError error, validateFn ValidateFn) error

func CheckValidatorSignature

func CheckValidatorSignature(valSet ValidatorSet, data []byte, sig []byte) (common.Address, error)

func CompareValidatorPublicKeySlices

func CompareValidatorPublicKeySlices(valSet1 []blscrypto.SerializedPublicKey, valSet2 []blscrypto.SerializedPublicKey) bool

func CompareValidatorSlices

func CompareValidatorSlices(valSet1 []common.Address, valSet2 []common.Address) bool

CompareValidatorSlices compares 2 validator slices and indicate if they are equal. Equality is defined as: valseSet1[i] must be equal to valSet2[i] for every i. (aka. order matters)

func ConvertPublicKeysToStringSlice

func ConvertPublicKeysToStringSlice(publicKeys []blscrypto.SerializedPublicKey) []string

func EmptyPreparedCertificateV2 added in v1.7.1

func EmptyPreparedCertificateV2() (PreparedCertificateV2, Proposal)

func GetEpochFirstBlockGivenBlockNumber

func GetEpochFirstBlockGivenBlockNumber(blockNumber uint64, epochSize uint64) (uint64, error)

GetEpochFirstBlockGivenBlockNumber retrieves first block of a given block's epoch Fails when try to obtain first block of epoch 0 (genesis)

func GetEpochFirstBlockNumber

func GetEpochFirstBlockNumber(epochNumber uint64, epochSize uint64) (uint64, error)

GetEpochFirstBlockNumber retrieves first block of epoch.

func GetEpochLastBlockNumber

func GetEpochLastBlockNumber(epochNumber uint64, epochSize uint64) uint64

GetEpochLastBlockNumber retrieves last block of epoch

func GetEpochNumber

func GetEpochNumber(number uint64, epochSize uint64) uint64

GetEpochNumber retrieves the epoch number given the block number. Epoch 0 is a special block that only contains the genesis block (block 0), epoch 1 starts at block 1

func GetNodeID

func GetNodeID(enodeURL string) (*enode.ID, error)

func GetNumberWithinEpoch

func GetNumberWithinEpoch(number uint64, epochSize uint64) uint64

GetNumberWithinEpoch retrieves the block number within an epoch. The return value will be 1-based; thus first block of epoch is 1, and last block of epoch is `epochSize` There is a special case if the number == 0. It is basically the last block of the 0th epoch, and should have a value of epochSize

func GetSignatureAddress

func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)

GetSignatureAddress gets the signer address from the signature

func GetSignerFromSignature added in v1.7.1

func GetSignerFromSignature(p PayloadNoSig, signature []byte, validateFn ValidateFn) (common.Address, error)

func GetTimestamp added in v1.6.0

func GetTimestamp() uint

func IsFirstBlockOfEpoch

func IsFirstBlockOfEpoch(number uint64, epochSize uint64) bool

IsFirstBlockOfEpoch indicates if block number is the first block of its epoch

func IsIstanbulMsg

func IsIstanbulMsg(msg p2p.Msg) bool

func IsLastBlockOfEpoch

func IsLastBlockOfEpoch(number uint64, epochSize uint64) bool

IsLastBlockOfEpoch indicates if block number is the last block of its epoch

func IsPreprepareCode added in v1.7.1

func IsPreprepareCode(istanbulMsgCode uint64) bool

IsPreprepareCode returns true if and only if the message code equals MsgPreprepareV2

func IsRoundChangeCode added in v1.7.1

func IsRoundChangeCode(istanbulMsgCode uint64) bool

IsRoundChangeCode returns true if and only if the message code equals MsgRoundChangeV2

func MapMessagesToSenders

func MapMessagesToSenders(messages []Message) []common.Address

MapMessagesToSenders map a list of Messages to the list of the sender addresses

func MapRoundChangeRequestsToSenders added in v1.7.1

func MapRoundChangeRequestsToSenders(requests []RoundChangeRequest) []common.Address

MapRoundChangeRequestsToSenders map a list of RoundChangeRequest to the list of the sender addresses

func MapValidatorsToAddresses

func MapValidatorsToAddresses(validators []Validator) []common.Address

MapValidatorsToAddresses maps a slice of validator to a slice of addresses

func MapValidatorsToPublicKeys

func MapValidatorsToPublicKeys(validators []Validator) []blscrypto.SerializedPublicKey

MapValidatorsToPublicKeys maps a slice of validator to a slice of public keys

func MustGetEpochFirstBlockGivenBlockNumber

func MustGetEpochFirstBlockGivenBlockNumber(blockNumber uint64, epochSize uint64) uint64

MustGetEpochFirstBlockGivenBlockNumber is a variant of GetEpochFirstBlockGivenBlockNumber that panics if called for epoch 0 (genesis)

func RLPHash

func RLPHash(v interface{}) (h common.Hash)

func SeparateValidatorDataIntoIstanbulExtra

func SeparateValidatorDataIntoIstanbulExtra(validators []ValidatorData) ([]common.Address, []blscrypto.SerializedPublicKey)

Types

type AddressEntry

type AddressEntry struct {
	Address                      common.Address
	PublicKey                    *ecdsa.PublicKey
	Node                         *enode.Node
	Version                      uint
	HighestKnownVersion          uint
	NumQueryAttemptsForHKVersion uint
	LastQueryTimestamp           *time.Time
}

## AddressEntry ###################################################################### AddressEntry is an entry for the valEnodeTable.

func (*AddressEntry) DecodeRLP

func (ae *AddressEntry) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the AddressEntry fields from a RLP stream.

func (*AddressEntry) EncodeRLP

func (ae *AddressEntry) EncodeRLP(w io.Writer) error

EncodeRLP serializes AddressEntry into the Ethereum RLP format.

func (*AddressEntry) GetAddress

func (ae *AddressEntry) GetAddress() common.Address

GetAddess returns the addess entry's address

func (*AddressEntry) GetNode

func (ae *AddressEntry) GetNode() *enode.Node

GetNode returns the address entry's node

func (*AddressEntry) GetVersion

func (ae *AddressEntry) GetVersion() uint

GetVersion returns the addess entry's version

func (*AddressEntry) String

func (ae *AddressEntry) String() string

type AddressEntryRLP

type AddressEntryRLP struct {
	Address                      common.Address
	CompressedPublicKey          []byte
	EnodeURL                     string
	Version                      uint
	HighestKnownVersion          uint
	NumQueryAttemptsForHKVersion uint
	LastQueryTimestamp           []byte
}

Implement RLP Encode/Decode interface

type BLSSignerFn

type BLSSignerFn func(accounts.Account, []byte, []byte, bool, bool) (blscrypto.SerializedSignature, error)

BLSSignerFn is a signer callback function to request a message and extra data to be signed by a backing account using BLS with a direct or composite hasher

type BlsInfo added in v1.6.0

type BlsInfo struct {
	Address common.Address // Ethereum address of the BLS signing key
	// contains filtered or unexported fields
}

func NewBlsInfo added in v1.6.0

func NewBlsInfo(blsAddress common.Address, signBLSFn BLSSignerFn) *BlsInfo

func (*BlsInfo) Sign added in v1.6.0

func (bi *BlsInfo) Sign(data []byte, extra []byte, useComposite, cip22 bool) (blscrypto.SerializedSignature, error)

Sign signs with the bls account

type ChainHeaderReader added in v1.6.0

type ChainHeaderReader interface {
	// GetHeader retrieves a block header from the database by hash and number.
	GetHeader(hash common.Hash, number uint64) *types.Header

	// GetHeaderByNumber retrieves a block header from the database by number.
	GetHeaderByNumber(number uint64) *types.Header
}

type CommittedSubject

type CommittedSubject struct {
	Subject               *Subject
	CommittedSeal         []byte
	EpochValidatorSetSeal []byte
}

type Config

type Config struct {
	RequestTimeout              uint64         `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
	TimeoutBackoffFactor        uint64         `toml:",omitempty"` // Timeout at subsequent rounds is: RequestTimeout + 2**round * TimeoutBackoffFactor (in milliseconds)
	MinResendRoundChangeTimeout uint64         `toml:",omitempty"` // Minimum interval with which to resend RoundChange messages for same round
	MaxResendRoundChangeTimeout uint64         `toml:",omitempty"` // Maximum interval with which to resend RoundChange messages for same round
	BlockPeriod                 uint64         `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
	ProposerPolicy              ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
	Epoch                       uint64         `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
	DefaultLookbackWindow       uint64         `toml:",omitempty"` // The default value for how many blocks in a row a validator must miss to be considered "down"
	ReplicaStateDBPath          string         `toml:",omitempty"` // The location for the validator replica state DB
	ValidatorEnodeDBPath        string         `toml:",omitempty"` // The location for the validator enodes DB
	VersionCertificateDBPath    string         `toml:",omitempty"` // The location for the signed announce version DB
	RoundStateDBPath            string         `toml:",omitempty"` // The location for the round states DB
	Validator                   bool           `toml:",omitempty"` // Specified if this node is configured to validate  (specifically if --mine command line is set)
	Replica                     bool           `toml:",omitempty"` // Specified if this node is configured to be a replica

	// Proxy Configs
	Proxy                   bool           `toml:",omitempty"` // Specifies if this node is a proxy
	ProxiedValidatorAddress common.Address `toml:",omitempty"` // The address of the proxied validator

	// Proxied Validator Configs
	Proxied      bool           `toml:",omitempty"` // Specifies if this node is proxied
	ProxyConfigs []*ProxyConfig `toml:",omitempty"` // The set of proxy configs for this proxied validator at startup

	// Announce Configs
	AnnounceQueryEnodeGossipPeriod                 uint64 `toml:",omitempty"` // Time duration (in seconds) between gossiped query enode messages
	AnnounceAggressiveQueryEnodeGossipOnEnablement bool   `toml:",omitempty"` // Specifies if this node should aggressively query enodes on announce enablement
	AnnounceAdditionalValidatorsToGossip           int64  `toml:",omitempty"` // Specifies the number of additional non-elected validators to gossip an announce

	// Load test config
	LoadTestCSVFile string `toml:",omitempty"` // If non-empty, specifies the file to write out csv metrics about the block production cycle to.
}

Config represents the istanbul consensus engine

type DecryptFn

type DecryptFn func(accounts.Account, []byte, []byte, []byte) ([]byte, error)

Decrypt is a decrypt callback function to request an ECIES ciphertext to be decrypted

type EcdsaInfo added in v1.6.0

type EcdsaInfo struct {
	Address   common.Address   // Ethereum address of the ECDSA signing key
	PublicKey *ecdsa.PublicKey // The signer public key
	// contains filtered or unexported fields
}

func NewEcdsaInfo added in v1.6.0

func NewEcdsaInfo(ecdsaAddress common.Address, publicKey *ecdsa.PublicKey,
	decryptFn DecryptFn, signFn SignerFn, signHashFn HashSignerFn) *EcdsaInfo

func (EcdsaInfo) Decrypt added in v1.6.0

func (ei EcdsaInfo) Decrypt(payload []byte) ([]byte, error)

Decrypt is a decrypt callback function to request an ECIES ciphertext to be decrypted

func (EcdsaInfo) Sign added in v1.6.0

func (ei EcdsaInfo) Sign(data []byte) ([]byte, error)

Sign hashes and signs the data with the ecdsa account

func (EcdsaInfo) SignHash added in v1.6.0

func (ei EcdsaInfo) SignHash(hash common.Hash) ([]byte, error)

SignHash signs the given hash with the ecdsa account

type EncryptedEnodeURL added in v1.4.0

type EncryptedEnodeURL struct {
	DestAddress       common.Address
	EncryptedEnodeURL []byte
}

func (*EncryptedEnodeURL) DecodeRLP added in v1.4.0

func (ee *EncryptedEnodeURL) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the ar fields from a RLP stream.

func (*EncryptedEnodeURL) EncodeRLP added in v1.4.0

func (ee *EncryptedEnodeURL) EncodeRLP(w io.Writer) error

EncodeRLP serializes ar into the Ethereum RLP format.

func (*EncryptedEnodeURL) String added in v1.4.0

func (ee *EncryptedEnodeURL) String() string

type EnodeCertMsg

type EnodeCertMsg struct {
	Msg           *Message
	DestAddresses []common.Address
}

## EnodeCertMsg ######################################################################

type EnodeCertificate

type EnodeCertificate struct {
	EnodeURL string
	Version  uint
}

func (*EnodeCertificate) DecodeRLP

func (ec *EnodeCertificate) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the ec fields from a RLP stream.

func (*EnodeCertificate) EncodeRLP

func (ec *EnodeCertificate) EncodeRLP(w io.Writer) error

EncodeRLP serializes ec into the Ethereum RLP format.

type EpochHeadersProvider added in v1.6.0

type EpochHeadersProvider interface {
	// GetEpochHeadersUpTo returns all headers from the same epoch as the header provided (included) ordered, up to
	// the given one, with a limit on the amount of headers to return. E.g limit 3 would return [prev-2, prev-1, upToHeader], assuming
	// all of them are on the same epoch.
	GetEpochHeadersUpToLimit(epochSize uint64, upToHeader *types.Header, limit uint64) ([]*types.Header, error)
}

func NewHeadersProvider added in v1.6.0

func NewHeadersProvider(chr ChainHeaderReader) EpochHeadersProvider

type FinalCommittedEvent

type FinalCommittedEvent struct {
}

FinalCommittedEvent is posted when a proposal is committed

type ForwardMessage

type ForwardMessage struct {
	Code          uint64
	Msg           []byte
	DestAddresses []common.Address
}

type GossipCache added in v1.6.0

type GossipCache interface {
	MarkMessageProcessedByPeer(peerNodeAddr common.Address, payload []byte)
	CheckIfMessageProcessedByPeer(peerNodeAddr common.Address, payload []byte) bool

	MarkMessageProcessedBySelf(payload []byte)
	CheckIfMessageProcessedBySelf(payload []byte) bool
}

type HashSignerFn

type HashSignerFn func(accounts.Account, []byte) ([]byte, error)

HashSignerFn is a signer callback function to request a hash to be signed by a backing account.

type LRUGossipCache added in v1.6.0

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

func NewLRUGossipCache added in v1.6.0

func NewLRUGossipCache(peerCacheSize, messageCacheSize int) *LRUGossipCache

func (*LRUGossipCache) CheckIfMessageProcessedByPeer added in v1.6.0

func (gc *LRUGossipCache) CheckIfMessageProcessedByPeer(peerNodeAddr common.Address, payload []byte) bool

func (*LRUGossipCache) CheckIfMessageProcessedBySelf added in v1.6.0

func (gc *LRUGossipCache) CheckIfMessageProcessedBySelf(payload []byte) bool

func (*LRUGossipCache) MarkMessageProcessedByPeer added in v1.6.0

func (gc *LRUGossipCache) MarkMessageProcessedByPeer(peerNodeAddr common.Address, payload []byte)

func (*LRUGossipCache) MarkMessageProcessedBySelf added in v1.6.0

func (gc *LRUGossipCache) MarkMessageProcessedBySelf(payload []byte)

type Message

type Message struct {
	Code      uint64
	Msg       []byte         // The serialised bytes of the innner message.
	Address   common.Address // The sender address
	Signature []byte         // Signature of the Message using the private key associated with the "Address" field
	// contains filtered or unexported fields
}

Message is a wrapper used for all istanbul communication. It encapsulates the sender's address, a code that indicates the type of the wrapped message and a signature. Message instances also hold a deserialised instance of the inner message which can be retrieved by calling the corresponding function (Commit(), Preprepare() ... etc).

Messages should be initialised either through the use of one of the NewXXXMessage constructors or by calling FromPayload on an empty Message instance, these mechanisms ensure that the produced Message instances will contain the deserialised inner message instance and the serialised bytes of the inner message.

func NewCommitMessage added in v1.4.0

func NewCommitMessage(commit *CommittedSubject, sender common.Address) *Message

NewCommitMessage constructs a Message instance with the given sender and commit. Both the commit instance and the serialized bytes of commit are part of the returned Message.

func NewEnodeCeritifcateMessage added in v1.4.0

func NewEnodeCeritifcateMessage(enodeCertificate *EnodeCertificate, sender common.Address) *Message

NewValEnodesShareMessage constructs a Message instance with the given sender and enodeCertificate. Both the enodeCertificate instance and the serialized bytes of enodeCertificate are part of the returned Message.

func NewForwardMessage added in v1.4.0

func NewForwardMessage(fowardMessage *ForwardMessage, sender common.Address) *Message

NewForwardMessage constructs a Message instance with the given sender and forwardMessage. Both the forwardMessage instance and the serialized bytes of fowardMessage are part of the returned Message.

func NewPrepareMessage added in v1.4.0

func NewPrepareMessage(subject *Subject, sender common.Address) *Message

NewPrepareMessage constructs a Message instance with the given sender and subject. Both the subject instance and the serialized bytes of subject are part of the returned Message.

func NewPreprepareV2Message added in v1.7.1

func NewPreprepareV2Message(prePrepareV2 *PreprepareV2, sender common.Address) *Message

NewPreprepareV2Message constructs a Message instance with the given sender and prePrepare. Both the prePrepare instance and the serialized bytes of prePrepare are part of the returned Message.

func NewQueryEnodeMessage added in v1.4.0

func NewQueryEnodeMessage(queryEnode *QueryEnodeData, sender common.Address) *Message

NewQueryEnodeMessage constructs a Message instance with the given sender and queryEnode. Both the queryEnode instance and the serialized bytes of queryEnode are part of the returned Message.

func NewRoundChangeV2Message added in v1.7.1

func NewRoundChangeV2Message(roundChangeV2 *RoundChangeV2, sender common.Address) *Message

NewRoundChangeV2Message constructs a Message instance with the given sender and roundChangeV2. Both the roundChangeV2 instance and the serialized bytes of roundChange are part of the returned Message.

func NewValEnodesShareMessage added in v1.4.0

func NewValEnodesShareMessage(valEnodeShareData *ValEnodesShareData, sender common.Address) *Message

NewValEnodesShareMessage constructs a Message instance with the given sender and valEnodeShareData. Both the valEnodeShareData instance and the serialized bytes of valEnodeShareData are part of the returned Message.

func NewVersionCeritifcatesMessage added in v1.4.0

func NewVersionCeritifcatesMessage(versionCertificates []*VersionCertificate, sender common.Address) *Message

NewVersionCeritifcatesMessage constructs a Message instance with the given sender and versionCertificates. Both the versionCertificates instance and the serialized bytes of versionCertificates are part of the returned Message.

func (*Message) Commit added in v1.4.0

func (m *Message) Commit() *CommittedSubject

Commit returns the committed subject if this is a commit message.

func (*Message) Copy

func (m *Message) Copy() *Message

func (*Message) DecodeMessage added in v1.6.0

func (m *Message) DecodeMessage() error

func (*Message) DecodeRLP added in v1.4.0

func (m *Message) DecodeRLP(stream *rlp.Stream) error

func (*Message) EnodeCertificate added in v1.4.0

func (m *Message) EnodeCertificate() *EnodeCertificate

EnodeCertificate returns the enode certificate if this is an enode certificate message

func (*Message) ForwardMessage added in v1.4.0

func (m *Message) ForwardMessage() *ForwardMessage

ForwardMessage returns forward message if this is a forward message.

func (*Message) FromPayload

func (m *Message) FromPayload(b []byte, validateFn ValidateFn) error

FromPayload decodes b into a Message instance it will set one of the private fields committedSubject, prePrepare, prepare or roundChange depending on the type of the message.

func (*Message) Payload

func (m *Message) Payload() ([]byte, error)

func (*Message) PayloadNoSig

func (m *Message) PayloadNoSig() ([]byte, error)

func (*Message) Prepare added in v1.4.0

func (m *Message) Prepare() *Subject

Prepare returns prepare if this is a prepare message.

func (*Message) PreprepareV2 added in v1.7.1

func (m *Message) PreprepareV2() *PreprepareV2

PreprepareV2 returns preprepare if this is a preprepare message.

func (*Message) QueryEnodeMsg added in v1.4.0

func (m *Message) QueryEnodeMsg() *QueryEnodeData

QueryEnode returns query enode data if this is a query enode message.

func (*Message) RoundChangeV2 added in v1.7.1

func (m *Message) RoundChangeV2() *RoundChangeV2

RoundChangeV2 returns a round change v2 if this is a round change v2 message.

func (*Message) Sign

func (m *Message) Sign(signingFn func(data []byte) ([]byte, error)) error

func (*Message) String

func (m *Message) String() string

func (*Message) ValEnodesShareData added in v1.4.0

func (m *Message) ValEnodesShareData() *ValEnodesShareData

ValEnodesShareData returns val enode share data if this is a val enodes share message.

func (*Message) VersionCertificates added in v1.4.0

func (m *Message) VersionCertificates() []*VersionCertificate

VersionCertificates returns the version certificate entries if this is a version certificates message.

type MessageEvent

type MessageEvent struct {
	Payload []byte
}

MessageEvent is posted for Istanbul engine communication

type MessageWithPeerIDEvent

type MessageWithPeerIDEvent struct {
	PeerID  enode.ID
	Payload []byte
}

MessageWithPeerIDEvent is a MessageEvent with the peerID that sent the message

type PayloadNoSig added in v1.7.1

type PayloadNoSig interface {
	PayloadNoSig() ([]byte, error)
}

type PreparedCertificate

type PreparedCertificate struct {
	Proposal                Proposal
	PrepareOrCommitMessages []Message
}

func EmptyPreparedCertificate

func EmptyPreparedCertificate() PreparedCertificate

func (*PreparedCertificate) AsData

func (*PreparedCertificate) DecodeRLP

func (pc *PreparedCertificate) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*PreparedCertificate) EncodeRLP

func (pc *PreparedCertificate) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*PreparedCertificate) IsEmpty

func (pc *PreparedCertificate) IsEmpty() bool

func (*PreparedCertificate) Summary

type PreparedCertificateData

type PreparedCertificateData struct {
	Proposal                *types.Block
	PrepareOrCommitMessages []Message
}

type PreparedCertificateSummary

type PreparedCertificateSummary struct {
	ProposalHash   common.Hash      `json:"proposalHash"`
	PrepareSenders []common.Address `json:"prepareSenders"`
	CommitSenders  []common.Address `json:"commitSenders"`
}

type PreparedCertificateV2 added in v1.7.1

type PreparedCertificateV2 struct {
	ProposalHash            common.Hash
	PrepareOrCommitMessages []Message
}

func PCV2FromPCV1 added in v1.7.1

func (*PreparedCertificateV2) DecodeRLP added in v1.7.1

func (pc *PreparedCertificateV2) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*PreparedCertificateV2) EncodeRLP added in v1.7.1

func (pc *PreparedCertificateV2) EncodeRLP(w io.Writer) error

EncodeRLP serializes pc into the Ethereum RLP format.

func (*PreparedCertificateV2) IsEmpty added in v1.7.1

func (pc *PreparedCertificateV2) IsEmpty() bool

type PreprepareSummary

type PreprepareSummary struct {
	View                          *View            `json:"view"`
	ProposalHash                  common.Hash      `json:"proposalHash"`
	RoundChangeCertificateSenders []common.Address `json:"roundChangeCertificateSenders"`
}

type PreprepareV2 added in v1.7.1

type PreprepareV2 struct {
	View                     *View
	Proposal                 Proposal
	RoundChangeCertificateV2 RoundChangeCertificateV2
}

func (*PreprepareV2) DecodeRLP added in v1.7.1

func (pp *PreprepareV2) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*PreprepareV2) EncodeRLP added in v1.7.1

func (pp *PreprepareV2) EncodeRLP(w io.Writer) error

EncodeRLP serializes pp into the Ethereum RLP format.

func (*PreprepareV2) HasRoundChangeCertificateV2 added in v1.7.1

func (pp *PreprepareV2) HasRoundChangeCertificateV2() bool

func (*PreprepareV2) Summary added in v1.7.1

func (pp *PreprepareV2) Summary() *PreprepareSummary

type Proposal

type Proposal interface {
	// Number retrieves the sequence number of this proposal.
	Number() *big.Int

	Header() *types.Header

	// Hash retrieves the hash of this block
	Hash() common.Hash

	// ParentHash retrieves the hash of this block's parent
	ParentHash() common.Hash

	EncodeRLP(w io.Writer) error

	DecodeRLP(s *rlp.Stream) error
}

Proposal supports retrieving height and serialized block to be used during Istanbul consensus.

type ProposerPolicy

type ProposerPolicy uint64

ProposerPolicy represents the policy used to order elected validators within an epoch

const (
	RoundRobin ProposerPolicy = iota
	Sticky
	ShuffledRoundRobin
)

type ProposerSelector

type ProposerSelector func(validatorSet ValidatorSet, lastBlockProposer common.Address, currentRound uint64) Validator

ProposerSelector returns the block proposer for a round given the last proposer, round number, and randomness.

type ProxyConfig

type ProxyConfig struct {
	InternalNode *enode.Node `toml:",omitempty"` // The internal facing node of the proxy that this proxied validator will peer with
	ExternalNode *enode.Node `toml:",omitempty"` // The external facing node of the proxy that the proxied validator will broadcast via the announce message
}

ProxyConfig represents the configuration for validator's proxies

type QueryEnodeData added in v1.4.0

type QueryEnodeData struct {
	EncryptedEnodeURLs []*EncryptedEnodeURL
	Version            uint
	// The timestamp of the node when the message is generated.
	// This results in a new hash for a newly generated message so it gets regossiped by other nodes
	Timestamp uint
}

func (*QueryEnodeData) DecodeRLP added in v1.4.0

func (qed *QueryEnodeData) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the ad fields from a RLP stream.

func (*QueryEnodeData) EncodeRLP added in v1.4.0

func (qed *QueryEnodeData) EncodeRLP(w io.Writer) error

EncodeRLP serializes ad into the Ethereum RLP format.

func (*QueryEnodeData) HasDuplicates added in v1.6.0

func (qed *QueryEnodeData) HasDuplicates() (bool, common.Address)

HasDuplicates returns true if there are duplicate destination addresses in the query, and the first duplicate's destination address.

func (*QueryEnodeData) String added in v1.4.0

func (qed *QueryEnodeData) String() string

type Request

type Request struct {
	Proposal Proposal
}

func (*Request) DecodeRLP

func (b *Request) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Request) EncodeRLP

func (b *Request) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

type RequestEvent

type RequestEvent struct {
	Proposal Proposal
}

RequestEvent is posted to propose a proposal

type RoundChangeCertificateV2 added in v1.7.1

type RoundChangeCertificateV2 struct {
	Requests []RoundChangeRequest
}

func (*RoundChangeCertificateV2) AnyHighestPreparedCertificate added in v1.7.1

func (rcc *RoundChangeCertificateV2) AnyHighestPreparedCertificate() *PreparedCertificateV2

func (*RoundChangeCertificateV2) DecodeRLP added in v1.7.1

func (rcc *RoundChangeCertificateV2) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*RoundChangeCertificateV2) EncodeRLP added in v1.7.1

func (rcc *RoundChangeCertificateV2) EncodeRLP(w io.Writer) error

EncodeRLP serializes rcc into the Ethereum RLP format.

func (*RoundChangeCertificateV2) GetPreparedCertificateFor added in v1.7.1

func (rcc *RoundChangeCertificateV2) GetPreparedCertificateFor(round *big.Int, proposalHash common.Hash) *PreparedCertificateV2

func (*RoundChangeCertificateV2) HighestRoundWithPreparedCertificate added in v1.7.1

func (rcc *RoundChangeCertificateV2) HighestRoundWithPreparedCertificate() *big.Int

HighestRoundWithPreparedCertificate returns the highest round request with a PC. Be mindful that there could be many different PCs with the same highest round.

func (*RoundChangeCertificateV2) IsEmpty added in v1.7.1

func (rcc *RoundChangeCertificateV2) IsEmpty() bool

type RoundChangeRequest added in v1.7.1

type RoundChangeRequest struct {
	Address               common.Address
	View                  View
	PreparedCertificateV2 PreparedCertificateV2
	Signature             []byte
}

func (*RoundChangeRequest) DecodeRLP added in v1.7.1

func (rcr *RoundChangeRequest) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*RoundChangeRequest) EncodeRLP added in v1.7.1

func (rcr *RoundChangeRequest) EncodeRLP(w io.Writer) error

EncodeRLP serializes rcr into the Ethereum RLP format.

func (*RoundChangeRequest) HasPreparedCertificate added in v1.7.1

func (rcr *RoundChangeRequest) HasPreparedCertificate() bool

func (*RoundChangeRequest) PayloadNoSig added in v1.7.1

func (rcr *RoundChangeRequest) PayloadNoSig() ([]byte, error)

func (*RoundChangeRequest) Sign added in v1.7.1

func (rcr *RoundChangeRequest) Sign(signingFn func(data []byte) ([]byte, error)) error

type RoundChangeV2 added in v1.7.1

type RoundChangeV2 struct {
	Request          RoundChangeRequest
	PreparedProposal Proposal
}

func (*RoundChangeV2) DecodeRLP added in v1.7.1

func (rc *RoundChangeV2) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*RoundChangeV2) EncodeRLP added in v1.7.1

func (rc *RoundChangeV2) EncodeRLP(w io.Writer) error

EncodeRLP serializes rc into the Ethereum RLP format.

func (*RoundChangeV2) HasPreparedCertificate added in v1.7.1

func (rc *RoundChangeV2) HasPreparedCertificate() bool

func (*RoundChangeV2) ProposalMatch added in v1.7.1

func (rc *RoundChangeV2) ProposalMatch() bool

type SharedValidatorEnode added in v1.4.0

type SharedValidatorEnode struct {
	Address  common.Address
	EnodeURL string
	Version  uint
}

func (*SharedValidatorEnode) String added in v1.4.0

func (sve *SharedValidatorEnode) String() string

type SignerFn

type SignerFn func(accounts.Account, string, []byte) ([]byte, error)

SignerFn is a signer callback function to request a header to be signed by a backing account.

type Subject

type Subject struct {
	View   *View
	Digest common.Hash
}

func (*Subject) String

func (s *Subject) String() string

type ValEnodesShareData added in v1.4.0

type ValEnodesShareData struct {
	ValEnodes []SharedValidatorEnode
}

func (*ValEnodesShareData) DecodeRLP added in v1.4.0

func (sd *ValEnodesShareData) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the sd fields from a RLP stream.

func (*ValEnodesShareData) EncodeRLP added in v1.4.0

func (sd *ValEnodesShareData) EncodeRLP(w io.Writer) error

EncodeRLP serializes sd into the Ethereum RLP format.

func (*ValEnodesShareData) String added in v1.4.0

func (sd *ValEnodesShareData) String() string

type ValidateFn added in v1.7.1

type ValidateFn func([]byte, []byte) (common.Address, error)

type Validator

type Validator interface {
	fmt.Stringer

	// Address returns address
	Address() common.Address

	// BLSPublicKey returns the BLS public key (compressed format)
	BLSPublicKey() blscrypto.SerializedPublicKey

	// BLSPublicKeyUncompressed returns the BLS public key (uncompressed format)
	BLSPublicKeyUncompressed() []byte

	// Serialize returns binary reprenstation of the Validator
	// can be use used to instantiate a validator with DeserializeValidator()
	Serialize() ([]byte, error)

	// AsData returns Validator representation as ValidatorData
	AsData() *ValidatorData

	// AsData returns Validator representation as ValidatorData
	AsDataWithBLSKeyCache() *ValidatorDataWithBLSKeyCache

	// CacheUncompressedBLSKey stores the uncompressed BLS public key to cache
	CacheUncompressedBLSKey()

	// Copy validator
	Copy() Validator
}

type ValidatorData

type ValidatorData struct {
	Address      common.Address
	BLSPublicKey blscrypto.SerializedPublicKey
}

func CombineIstanbulExtraToValidatorData

func CombineIstanbulExtraToValidatorData(addrs []common.Address, blsPublicKeys []blscrypto.SerializedPublicKey) ([]ValidatorData, error)

func ValidatorSetDiff

func ValidatorSetDiff(oldValSet []ValidatorData, newValSet []ValidatorData) ([]ValidatorData, *big.Int)

type ValidatorDataWithBLSKeyCache

type ValidatorDataWithBLSKeyCache struct {
	Address                  common.Address
	BLSPublicKey             blscrypto.SerializedPublicKey
	UncompressedBLSPublicKey []byte
}

type ValidatorSet

type ValidatorSet interface {
	fmt.Stringer

	// Sets the randomness for use in the proposer policy.
	// This is injected into the ValidatorSet when we call `getOrderedValidators`
	SetRandomness(seed common.Hash)
	// Sets the randomness for use in the proposer policy
	GetRandomness() common.Hash

	// Return the validator size
	Size() int
	// Get the maximum number of faulty nodes
	F() int
	// Get the minimum quorum size
	MinQuorumSize() int

	// List returns all the validators
	List() []Validator
	// Return the validator index
	GetIndex(addr common.Address) int
	// Get validator by index
	GetByIndex(i uint64) Validator
	// Get validator by given address
	GetByAddress(addr common.Address) (int, Validator)
	// CointainByAddress indicates if a validator with the given address is present
	ContainsByAddress(add common.Address) bool

	// Add validators
	AddValidators(validators []ValidatorData) bool
	// Remove validators
	RemoveValidators(removedValidators *big.Int) bool
	// Copy validator set
	Copy() ValidatorSet

	// CacheUncompressedBLSKey stores the uncompressed BLS public key to cache for each validator in the valset
	CacheUncompressedBLSKey()

	// HasBLSKeyCache tests that all uncompressed BLS public keys are in the cache, otherwise returns false
	HasBLSKeyCache() bool

	// Serialize returns binary reprentation of the ValidatorSet
	// can be use used to instantiate a validator with DeserializeValidatorSet()
	Serialize() ([]byte, error)
}

type ValidatorSetData

type ValidatorSetData struct {
	Validators []ValidatorData
	Randomness common.Hash
}

type ValidatorSetDataWithBLSKeyCache

type ValidatorSetDataWithBLSKeyCache struct {
	Validators []ValidatorDataWithBLSKeyCache
	Randomness common.Hash
}

type ValidatorsDataByAddress

type ValidatorsDataByAddress []ValidatorData

func (ValidatorsDataByAddress) Len

func (a ValidatorsDataByAddress) Len() int

func (ValidatorsDataByAddress) Less

func (a ValidatorsDataByAddress) Less(i, j int) bool

func (ValidatorsDataByAddress) Swap

func (a ValidatorsDataByAddress) Swap(i, j int)

type VersionCertificate added in v1.4.0

type VersionCertificate struct {
	Version   uint
	Signature []byte
	// contains filtered or unexported fields
}

VersionCertificate is an entry in the VersionCertificateDB. It's a signed message from a registered or active validator indicating the most recent version of its enode.

func NewVersionCertificate added in v1.4.0

func NewVersionCertificate(version uint, signingFn func([]byte) ([]byte, error)) (*VersionCertificate, error)

NewVersionCeritifcate constructs a VersionCertificate instance with the given version. It uses the signingFn to generate a version signature and then builds a version certificate from the version and its signature.

func NewVersionCertificateFromFields added in v1.4.0

func NewVersionCertificateFromFields(version uint, signature []byte, address common.Address, key *ecdsa.PublicKey) *VersionCertificate

NewVersionCeritifcateFrom fields constructs a VersionCertificate instance with the given fields, using them to build a VersionCertificate instance. No validation is done on the provided fields. It is assumed that the fields are valid, meaning that the signature was generated using the given version and the private part of the given public key, and also that the address corresponds to the given public key.

func (*VersionCertificate) Address added in v1.4.0

func (vc *VersionCertificate) Address() common.Address

func (*VersionCertificate) DecodeRLP added in v1.4.0

func (vc *VersionCertificate) DecodeRLP(s *rlp.Stream) error

func (*VersionCertificate) PublicKey added in v1.4.0

func (vc *VersionCertificate) PublicKey() *ecdsa.PublicKey

func (*VersionCertificate) String added in v1.4.0

func (vc *VersionCertificate) String() string

type View

type View struct {
	Round    *big.Int
	Sequence *big.Int
}

View includes a round number and a sequence number. Sequence is the block number we'd like to commit. Each round has a number and is composed by 3 steps: preprepare, prepare and commit.

If the given block is not accepted by validators, a round change will occur and the validators start a new round with round+1.

func (*View) Cmp

func (v *View) Cmp(y *View) int

Cmp compares v and y and returns:

-1 if v <  y
 0 if v == y
+1 if v >  y

func (*View) String

func (v *View) String() string

type Wallets added in v1.6.0

type Wallets struct {
	Ecdsa EcdsaInfo
	Bls   BlsInfo
}

Directories

Path Synopsis
random
Package random implements a language independent method of producing random validator orderings.
Package random implements a language independent method of producing random validator orderings.

Jump to

Keyboard shortcuts

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