equality

package
v0.0.0-...-b97d448 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
	// the previous block's timestamp + the minimum block period.
	ErrInvalidTimestamp = errors.New("invalid timestamp")

	// ErrChainConfigMissing is returned if the chain config is missing
	ErrChainConfigMissing = errors.New("chain config missing")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

Functions

func EqualityRLP

func EqualityRLP(header *types.Header) []byte

EqualityRLP returns the rlp bytes which needs to be signed for the proof-of-equality sealing. The RLP to sign consists of the entire header apart from the 65 byte signature contained at the end of the extra data.

Note, the method requires the extra data to be at least 65 bytes, otherwise it panics. This is done to avoid accidentally using both forms (signature present or not), which could be abused to produce different hashes for the same header.

func SealHash

func SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

Types

type API

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

API is a user facing RPC API to allow controlling the signer and voting mechanisms of the proof-of-equality scheme.

func (*API) GetAddress

func (api *API) GetAddress(address common.Address, number *rpc.BlockNumber) (rpcCandidateInfo, error)

GetAddress retrieves the candidate information of the address

func (*API) GetCandidates

func (api *API) GetCandidates(number *rpc.BlockNumber) ([]rpcCandidate, error)

GetCandidates retrieves the list of the candidates at specified block

func (*API) GetCandidatesCount

func (api *API) GetCandidatesCount(number *rpc.BlockNumber) (rpcCandidatesCount, error)

GetCandidatesCount retrieves number of the candidates at specified block

func (*API) GetValidators

func (api *API) GetValidators(number *rpc.BlockNumber) ([]rpcValidator, error)

GetValidators retrieves the list of the validators at specified block

type Candidate

type Candidate struct {
	Staked      *big.Int `json:"staked"`
	BlockNumber uint64   `json:"blockNumber"`
}

Candidate basic information

type Equality

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

Equality is the proof-of-equality consensus engine.

func New

func New(config *params.EqualityConfig, db ethdb.Database) *Equality

New creates a Equality proof-of-equality consensus engine with the initial signers set to the ones provided by the user.

func (*Equality) APIs

func (e *Equality) APIs(chain consensus.ChainHeaderReader) []rpc.API

APIs returns the RPC APIs this consensus engine provides.

func (*Equality) Author

func (e *Equality) Author(header *types.Header) (common.Address, error)

Author retrieves the Ethereum address of the account that minted the given block, which may be different from the header's coinbase if a consensus engine is based on signatures.

func (*Equality) Authorize

func (e *Equality) Authorize(signer common.Address, signFn SignerFn)

Authorize injects a private key into the consensus engine to mint new blocks with.

func (*Equality) CalcDifficulty

func (e *Equality) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have.

func (*Equality) Close

func (e *Equality) Close() error

Close terminates any background threads maintained by the consensus engine.

func (*Equality) Finalize

func (e *Equality) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
	uncles []*types.Header)

Finalize runs any post-transaction state modifications (e.g. block rewards) but does not assemble the block.

Note: The block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).

func (*Equality) FinalizeAndAssemble

func (e *Equality) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
	uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

FinalizeAndAssemble runs any post-transaction state modifications (e.g. block rewards) and assembles the final block.

Note: The block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).

func (*Equality) InTurn

func (e *Equality) InTurn(lastBlockHeader *types.Header, now uint64) bool

InTurn returns if a signer at a given block height is in-turn or not.

func (*Equality) Prepare

func (e *Equality) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error

Prepare initializes the consensus fields of a block header according to the rules of a particular engine. The changes are executed inline.

func (*Equality) Seal

func (e *Equality) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal generates a new sealing request for the given input block and pushes the result into the given channel.

Note, the method returns immediately and will send the result async. More than one result may also be returned depending on the consensus algorithm.

func (*Equality) SealHash

func (e *Equality) SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

func (*Equality) VerifyHeader

func (e *Equality) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules of a given engine. Verifying the seal may be done optionally here, or explicitly via the VerifySeal method.

func (*Equality) VerifyHeaders

func (e *Equality) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*Equality) VerifySeal

func (e *Equality) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error

VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.

func (*Equality) VerifyUncles

func (e *Equality) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles verifies that the given block's uncles conform to the consensus rules of a given engine.

type EventBecomeCandidate

type EventBecomeCandidate struct {
	Candidate common.Address
}

EventBecomeCandidate apply to become Candidate. data like "equality:1:event:candidate" Sender will become a Candidate

func (*EventBecomeCandidate) Action

func (event *EventBecomeCandidate) Action() string

func (*EventBecomeCandidate) Decode

func (event *EventBecomeCandidate) Decode(tx *types.Transaction, data []byte) error

func (*EventBecomeCandidate) Type

func (event *EventBecomeCandidate) Type() TransactionType

type EventCancelCandidate

type EventCancelCandidate struct {
	Delegator common.Address
}

EventCancelCandidate apply to cancel Candidate. data like "equality:1:event:delegator" Sender will cancel Candidate status

func (*EventCancelCandidate) Action

func (event *EventCancelCandidate) Action() string

func (*EventCancelCandidate) Decode

func (event *EventCancelCandidate) Decode(tx *types.Transaction, data []byte) error

func (*EventCancelCandidate) Type

func (event *EventCancelCandidate) Type() TransactionType

type HeaderExtra

type HeaderExtra struct {
	Root                          Root
	Epoch                         uint64
	EpochBlock                    uint64
	CurrentBlockCandidates        []common.Address
	CurrentBlockKickOutCandidates []common.Address
	CurrentBlockCancelCandidates  []common.Address
	CurrentEpochValidators        []common.Address
	ChainConfig                   []params.EqualityConfig
}

HeaderExtra is the struct of info in header.Extra[extraVanity:len(header.extra)-extraSeal]. HeaderExtra is the current struct.

func DecodeHeaderExtra

func DecodeHeaderExtra(header *types.Header) (HeaderExtra, error)

func NewHeaderExtra

func NewHeaderExtra(data []byte) (HeaderExtra, error)

NewHeaderExtra new HeaderExtra from rlp bytes.

func (HeaderExtra) Encode

func (headerExtra HeaderExtra) Encode() ([]byte, error)

Encode encode header extra as rlp bytes.

func (HeaderExtra) Equal

func (headerExtra HeaderExtra) Equal(other HeaderExtra) bool

Equal compares two HeaderExtras for equality.

type Root

type Root struct {
	EpochHash     common.Hash
	CandidateHash common.Hash
	MintCntHash   common.Hash
	ConfigHash    common.Hash
}

Root is the state tree root.

func (Root) PrintDifference

func (root Root) PrintDifference(number uint64, other Root)

type SignerFn

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

type Snapshot

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

Snapshot is the state of the authorization voting at a given block number.

func (*Snapshot) BecomeCandidate

func (snap *Snapshot) BecomeCandidate(
	candidateAddr common.Address, blockNumber uint64, security *big.Int, force ...bool) (exist bool, err error)

BecomeCandidate add a new candidate, return a bool value means address already is or not a candidate

func (*Snapshot) CancelCandidate

func (snap *Snapshot) CancelCandidate(candidateAddr common.Address) (exist bool, security *big.Int, err error)

CancelCandidate remove a candidate

func (*Snapshot) Commit

func (snap *Snapshot) Commit(root Root) error

Commit commit snapshot changes to database.

func (*Snapshot) CountMinted

func (snap *Snapshot) CountMinted(epoch uint64) (SortableAddresses, error)

CountMinted count the minted of each validator.

func (*Snapshot) EnoughCandidates

func (snap *Snapshot) EnoughCandidates(n int) (int, bool)

EnoughCandidates count of candidates is greater than or equal to n.

func (*Snapshot) GetCandidate

func (snap *Snapshot) GetCandidate(candidateAddr common.Address) (*Candidate, error)

GetCandidate returns specified candidate information.

func (*Snapshot) GetCandidates

func (snap *Snapshot) GetCandidates() (map[common.Address]Candidate, error)

GetCandidates returns all candidates.

func (*Snapshot) GetChainConfig

func (snap *Snapshot) GetChainConfig() (params.EqualityConfig, error)

GetChainConfig returns chain config from snapshot.

func (*Snapshot) GetValidators

func (snap *Snapshot) GetValidators() ([]common.Address, error)

GetValidators returns validators of current epoch.

func (*Snapshot) MintBlock

func (snap *Snapshot) MintBlock(epoch, number uint64, validator common.Address) error

ForgeBlock write validator of block to snapshot.

func (*Snapshot) RandCandidates

func (snap *Snapshot) RandCandidates(seed int64, n int) ([]common.Address, error)

RandCandidates random return n candidates.

func (*Snapshot) Root

func (snap *Snapshot) Root() (root Root, err error)

Root returns root of snapshot trie.

func (*Snapshot) SetChainConfig

func (snap *Snapshot) SetChainConfig(config params.EqualityConfig) error

SetChainConfig write chain config to snapshot.

func (*Snapshot) SetValidators

func (snap *Snapshot) SetValidators(validators []common.Address) error

SetValidators write validators of current epoch to snapshot.

type SortableAddress

type SortableAddress struct {
	Address common.Address `json:"address"`
	Weight  *big.Int       `json:"weight"`
}

SortableAddress sorted by votes.

type SortableAddresses

type SortableAddresses []SortableAddress

SortableAddresses sorting in descending order by weight.

func (SortableAddresses) Len

func (p SortableAddresses) Len() int

func (SortableAddresses) Less

func (p SortableAddresses) Less(i, j int) bool

func (SortableAddresses) String

func (p SortableAddresses) String() string

func (SortableAddresses) Swap

func (p SortableAddresses) Swap(i, j int)

type Transaction

type Transaction interface {
	Type() TransactionType
	Action() string
	Decode(*types.Transaction, []byte) error
}

Transaction custom transaction interface.

func NewTransaction

func NewTransaction(tx *types.Transaction) (Transaction, error)

NewTransaction new custom transaction from transaction data. data format: equality:version:type:action:data

type TransactionType

type TransactionType string

TransactionType custom transaction type enums.

const (
	EventTransactionType TransactionType = "event"
)

type Trie

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

PrefixTrie is a Merkle Patricia Trie.

func NewTrieWithPrefix

func NewTrieWithPrefix(root common.Hash, prefix []byte, db *trie.Database) (*Trie, error)

New creates a trie with an existing root node from db.

func (*Trie) Commit

func (t *Trie) Commit(onleaf trie.LeafCallback) (root common.Hash, err error)

Commit writes all nodes to the trie's database. Nodes are stored with their sha3 hash as the key. // // Committing flushes nodes from memory. // Subsequent Get calls will load nodes from the database.

func (*Trie) Delete

func (t *Trie) Delete(key []byte)

Delete removes any existing value for key from the trie.

func (*Trie) Get

func (t *Trie) Get(key []byte) []byte

Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.

func (*Trie) Hash

func (t *Trie) Hash() common.Hash

Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one.

func (*Trie) NodeIterator

func (t *Trie) NodeIterator(start []byte) trie.NodeIterator

NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at the key after the given start key.

func (*Trie) PrefixIterator

func (t *Trie) PrefixIterator(prefix []byte) trie.NodeIterator

PrefixIterator returns an iterator that returns nodes of the trie which has the prefix path specificed Iteration starts at the key after the given start key.

func (*Trie) TryDelete

func (t *Trie) TryDelete(key []byte) error

TryDelete removes any existing value for key from the trie. If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) TryGet

func (t *Trie) TryGet(key []byte) ([]byte, error)

TryGet returns the value for key stored in the trie. The value bytes must not be modified by the caller. If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) TryUpdate

func (t *Trie) TryUpdate(key, value []byte) error

TryUpdate associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.

The value bytes must not be modified by the caller while they are stored in the trie.

If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) Update

func (t *Trie) Update(key, value []byte)

Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.

The value bytes must not be modified by the caller while they are stored in the trie.

Jump to

Keyboard shortcuts

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