Documentation
¶
Index ¶
- Constants
- Variables
- func CheckValidatorSignature(valSet ValidatorSet, data []byte, sig []byte) (common.Address, error)
- func CompareValidatorPublicKeySlices(valSet1 []blscrypto.SerializedPublicKey, ...) bool
- func CompareValidatorSlices(valSet1 []common.Address, valSet2 []common.Address) bool
- func ConvertPublicKeysToStringSlice(publicKeys []blscrypto.SerializedPublicKey) []string
- func GetEpochFirstBlockNumber(epochNumber uint64, epochSize uint64) (uint64, error)
- func GetEpochLastBlockNumber(epochNumber uint64, epochSize uint64) uint64
- func GetEpochNumber(number uint64, epochSize uint64) uint64
- func GetNodeID(enodeURL string) (*enode.ID, error)
- func GetNumberWithinEpoch(number uint64, epochSize uint64) uint64
- func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)
- func GetValScoreTallyFirstBlockNumber(epochNumber uint64, epochSize uint64, lookbackWindowSize uint64) uint64
- func GetValScoreTallyLastBlockNumber(epochNumber uint64, epochSize uint64) uint64
- func IsFirstBlockOfEpoch(number uint64, epochSize uint64) bool
- func IsLastBlockOfEpoch(number uint64, epochSize uint64) bool
- func MapMessagesToSenders(messages []Message) []common.Address
- func MapValidatorsToAddresses(validators []Validator) []common.Address
- func NewIstLogger(fn func() *big.Int, ctx ...interface{}) log.Logger
- func RLPHash(v interface{}) (h common.Hash)
- func SeparateValidatorDataIntoIstanbulExtra(validators []ValidatorData) ([]common.Address, []blscrypto.SerializedPublicKey)
- type BLSSignerFn
- type Backend
- type CommittedSubject
- type Config
- type FinalCommittedEvent
- type ForwardMessage
- type Message
- func (m *Message) Decode(val interface{}) error
- func (m *Message) FromPayload(b []byte, validateFn func([]byte, []byte) (common.Address, error)) error
- func (m *Message) Payload() ([]byte, error)
- func (m *Message) PayloadNoSig() ([]byte, error)
- func (m *Message) Sign(signingFn func(data []byte) ([]byte, error)) error
- func (m *Message) String() string
- type MessageEvent
- type MessageSignerFn
- type PreparedCertificate
- func (pc *PreparedCertificate) AsData() *PreparedCertificateData
- func (pc *PreparedCertificate) DecodeRLP(s *rlp.Stream) error
- func (pc *PreparedCertificate) EncodeRLP(w io.Writer) error
- func (pc *PreparedCertificate) IsEmpty() bool
- func (pc *PreparedCertificate) Summary() *PreparedCertificateSummary
- type PreparedCertificateData
- type PreparedCertificateSummary
- type Preprepare
- type PreprepareData
- type PreprepareSummary
- type Proposal
- type ProposerPolicy
- type ProposerSelector
- type Request
- type RequestEvent
- type RoundChange
- type RoundChangeCertificate
- type SignerFn
- type Subject
- type Uptime
- type UptimeEntry
- type Validator
- type ValidatorData
- type ValidatorSet
- type ValidatorSetData
- type ValidatorsDataByAddress
- type View
Constants ¶
const ( MsgPreprepare uint64 = iota MsgPrepare MsgCommit MsgRoundChange )
Variables ¶
var ( // 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") )
var DefaultConfig = &Config{ RequestTimeout: 3000, TimeoutBackoffFactor: 1000, MinResendRoundChangeTimeout: 15 * 1000, MaxResendRoundChangeTimeout: 2 * 60 * 1000, BlockPeriod: 1, ProposerPolicy: ShuffledRoundRobin, Epoch: 30000, LookbackWindow: 12, ValidatorEnodeDBPath: "validatorenodes", RoundStateDBPath: "roundstates", Proxy: false, Proxied: false, }
Functions ¶
func CheckValidatorSignature ¶
func CompareValidatorPublicKeySlices ¶
func CompareValidatorPublicKeySlices(valSet1 []blscrypto.SerializedPublicKey, valSet2 []blscrypto.SerializedPublicKey) bool
func CompareValidatorSlices ¶
This function assumes that valSet1 and valSet2 are ordered in the same way
func ConvertPublicKeysToStringSlice ¶
func ConvertPublicKeysToStringSlice(publicKeys []blscrypto.SerializedPublicKey) []string
func GetEpochLastBlockNumber ¶
func GetEpochNumber ¶
Retrieves the epoch number given the block number. There is a special case if the number == 0 (the genesis block). That block will be in the 1st epoch.
func GetNumberWithinEpoch ¶
Retrieves the block number within an epoch. The return value will be 1-based. 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 ¶
GetSignatureAddress gets the signer address from the signature
func IsFirstBlockOfEpoch ¶
func IsLastBlockOfEpoch ¶
func MapMessagesToSenders ¶
MapMessagesToSenders map a list of Messages to the list of the sender addresses
func MapValidatorsToAddresses ¶
MapValidatorsToAddresses maps a slice of validator to a slice of addresses
func NewIstLogger ¶
NewIstLogger creates an Istanbul Logger with custom logic for exposing logs
func SeparateValidatorDataIntoIstanbulExtra ¶
func SeparateValidatorDataIntoIstanbulExtra(validators []ValidatorData) ([]common.Address, []blscrypto.SerializedPublicKey)
Types ¶
type BLSSignerFn ¶
BLSSignerFn is a signer callback function to request a hash to be signed by a backing account using BLS.
type Backend ¶
type Backend interface {
// Address returns the owner's address
Address() common.Address
// Validators returns the validator set
Validators(proposal Proposal) ValidatorSet
NextBlockValidators(proposal Proposal) (ValidatorSet, error)
// EventMux returns the event mux in backend
EventMux() *event.TypeMux
// BroadcastConsensusMsg sends a message to all validators (include self)
BroadcastConsensusMsg(validators []common.Address, payload []byte) error
// Gossip sends a message to all validators (exclude self)
Gossip(validators []common.Address, payload []byte, ethMsgCode uint64, ignoreCache bool) error
// Commit delivers an approved proposal to backend.
// The delivered proposal will be put into blockchain.
Commit(proposal Proposal, aggregatedSeal types.IstanbulAggregatedSeal, aggregatedEpochValidatorSetSeal types.IstanbulEpochValidatorSetSeal) error
// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
// the time difference of the proposal and current time is also returned.
Verify(Proposal) (time.Duration, error)
// Sign signs input data with the backend's private key
Sign([]byte) ([]byte, error)
SignBlockHeader([]byte) (blscrypto.SerializedSignature, error)
SignBLSWithCompositeHash([]byte) (blscrypto.SerializedSignature, error)
// CheckSignature verifies the signature by checking if it's signed by
// the given validator
CheckSignature(data []byte, addr common.Address, sig []byte) error
// GetCurrentHeadBlock retrieves the last block
GetCurrentHeadBlock() Proposal
// GetCurrentHeadBlockAndAuthor retrieves the last block alongside the author for that block
GetCurrentHeadBlockAndAuthor() (Proposal, common.Address)
// LastSubject retrieves latest committed subject (view and digest)
LastSubject() (Subject, error)
// HasBlock checks if the combination of the given hash and height matches any existing blocks
HasBlock(hash common.Hash, number *big.Int) bool
// AuthorForBlock returns the proposer of the given block height
AuthorForBlock(number uint64) common.Address
// ParentBlockValidators returns the validator set of the given proposal's parent block
ParentBlockValidators(proposal Proposal) ValidatorSet
// RefreshValPeers will connect with all the validators in the valset and disconnect validator peers that are not in the set
RefreshValPeers(valset ValidatorSet)
// Authorize injects a private key into the consensus engine.
Authorize(address common.Address, signFn SignerFn, signHashBLSFn BLSSignerFn, signMessageBLSFn MessageSignerFn)
}
Backend provides application specific functions for Istanbul core
type CommittedSubject ¶
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
LookbackWindow uint64 `toml:",omitempty"` // The window of blocks in which a validator is forgived from voting
ValidatorEnodeDBPath string `toml:",omitempty"` // The location for the validator enodes DB
RoundStateDBPath string `toml:",omitempty"` // The location for the round states DB
// 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
ProxyInternalFacingNode *enode.Node `toml:",omitempty"` // The internal facing node of the proxy that this proxied validator will contect to
ProxyExternalFacingNode *enode.Node `toml:",omitempty"` // The external facing node of the proxy that the proxied validator will broadcast via the announce message
}
type FinalCommittedEvent ¶
type FinalCommittedEvent struct {
}
FinalCommittedEvent is posted when a proposal is committed
type ForwardMessage ¶
type Message ¶
type Message struct {
Code uint64
Msg []byte
Address common.Address // The sender address
Signature []byte // Signature of the Message using the private key associated with the "Address" field
}
func (*Message) FromPayload ¶
func (*Message) PayloadNoSig ¶
type MessageEvent ¶
type MessageEvent struct {
Payload []byte
}
MessageEvent is posted for Istanbul engine communication
type MessageSignerFn ¶
MessageSignerFn is a signer callback function to request a raw message to be signed by a backing account.
type PreparedCertificate ¶
func EmptyPreparedCertificate ¶
func EmptyPreparedCertificate() PreparedCertificate
func (*PreparedCertificate) AsData ¶
func (pc *PreparedCertificate) AsData() *PreparedCertificateData
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 ¶
func (pc *PreparedCertificate) Summary() *PreparedCertificateSummary
type PreparedCertificateData ¶
type Preprepare ¶
type Preprepare struct {
View *View
Proposal Proposal
RoundChangeCertificate RoundChangeCertificate
}
func (*Preprepare) AsData ¶
func (pp *Preprepare) AsData() *PreprepareData
func (*Preprepare) DecodeRLP ¶
func (pp *Preprepare) DecodeRLP(s *rlp.Stream) error
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.
func (*Preprepare) EncodeRLP ¶
func (pp *Preprepare) EncodeRLP(w io.Writer) error
EncodeRLP serializes b into the Ethereum RLP format.
func (*Preprepare) HasRoundChangeCertificate ¶
func (pp *Preprepare) HasRoundChangeCertificate() bool
func (*Preprepare) Summary ¶
func (pp *Preprepare) Summary() *PreprepareSummary
type PreprepareData ¶
type PreprepareData struct {
View *View
Proposal *types.Block
RoundChangeCertificate RoundChangeCertificate
}
type 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
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 Request ¶
type Request struct {
Proposal Proposal
}
type RequestEvent ¶
type RequestEvent struct {
Proposal Proposal
}
RequestEvent is posted to propose a proposal
type RoundChange ¶
type RoundChange struct {
View *View
PreparedCertificate PreparedCertificate
}
func (*RoundChange) DecodeRLP ¶
func (b *RoundChange) DecodeRLP(s *rlp.Stream) error
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.
func (*RoundChange) EncodeRLP ¶
func (b *RoundChange) EncodeRLP(w io.Writer) error
EncodeRLP serializes b into the Ethereum RLP format.
func (*RoundChange) HasPreparedCertificate ¶
func (b *RoundChange) HasPreparedCertificate() bool
type RoundChangeCertificate ¶
type RoundChangeCertificate struct {
RoundChangeMessages []Message
}
func (*RoundChangeCertificate) IsEmpty ¶
func (b *RoundChangeCertificate) IsEmpty() bool
type SignerFn ¶
SignerFn is a signer callback function to request a hash to be signed by a backing account.
type Uptime ¶
type Uptime struct {
LatestBlock uint64
Entries []UptimeEntry
}
Uptime contains the latest block for which uptime metrics were accounted for. It also contains an array of Entries where the `i`th entry represents the uptime statistics of the `i`th validator in the validator set for that epoch
type UptimeEntry ¶
UptimeEntry contains the uptime score of a validator during an epoch as well as the last block they signed on
func (*UptimeEntry) String ¶
func (u *UptimeEntry) String() string
type Validator ¶
type Validator interface {
fmt.Stringer
// Address returns address
Address() common.Address
BLSPublicKey() blscrypto.SerializedPublicKey
// 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
}
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 ValidatorSet ¶
type ValidatorSet interface {
// 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
// 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 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 View ¶
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.