aiconsensus

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: GPL-3.0 Imports: 26 Imported by: 2

Documentation

Overview

Package aiconsensus implements the ai consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	PoABlockReward = big.NewInt(2e+17) // Block reward in wei for successfully mining a PoA block
	PoWBlockReward = big.NewInt(1e+18) // Block reward in wei for successfully mining a Pow block

)

AiConsensus protocol constants.

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")
)

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

This section is empty.

Types

type API

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

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

func (*API) Discard

func (api *API) Discard(address common.Address)

Discard drops a currently running proposal, stopping the validator from casting further votes (either for or against).

func (*API) GetPooledMiners

func (api *API) GetPooledMiners(number *rpc.BlockNumber) ([]common.Address, error)

GetPooledMiners retrieves the list of authorized pooled miners at the specified block.

func (*API) GetPooledMinersAtHash

func (api *API) GetPooledMinersAtHash(hash common.Hash) ([]common.Address, error)

GetPooledMinersAtHash retrieves the state snapshot at a given block.

func (*API) GetSnapshot

func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

func (*API) GetTally

func (api *API) GetTally(number *rpc.BlockNumber) (map[common.Address]Tally, error)

GetTally retrieves the list of vote tally at the specified block.

func (*API) GetTallyAtHash

func (api *API) GetTallyAtHash(hash common.Hash) (map[common.Address]Tally, error)

GetTallyAtHash retrieves the state snapshot at a given block.

func (*API) GetValidators

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

GetValidators retrieves the list of authorized validators at the specified block.

func (*API) GetValidatorsAtHash

func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)

GetValidatorsAtHash retrieves the state snapshot at a given block.

func (*API) Proposals

func (api *API) Proposals() map[common.Address]bool

Proposals returns the current proposals the node tries to uphold and vote on.

func (*API) Propose

func (api *API) Propose(address common.Address, auth bool)

Propose injects a new authorization proposal that the validator will attempt to push through.

type AiConsensus

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

AiConsensus is the Ai consensus engine proposed to support the AICHAIN testnet following the Ropsten attacks.

func New

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

func (*AiConsensus) APIs

func (c *AiConsensus) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.

func (*AiConsensus) Author

func (c *AiConsensus) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the AICHAIN address recovered from the signature in the header's extra-data section.

func (*AiConsensus) AuthorizeWithPassphrase

func (c *AiConsensus) AuthorizeWithPassphrase(signer common.Address, signFn SignerFnWithPassphraseCached, passphrase string)

AuthorizeWithPassphrase injects a private key and it's passphrase into the consensus engine to mint new blocks

func (*AiConsensus) CalcDifficulty

func (c *AiConsensus) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.

func (*AiConsensus) Ecrecover

func (c *AiConsensus) Ecrecover(header *types.Header) (common.Address, error)

Ecrecover extracts the AICHAIN account address from a signed header.

func (*AiConsensus) Finalize

func (c *AiConsensus) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.

func (*AiConsensus) Prepare

func (c *AiConsensus) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*AiConsensus) Seal

func (c *AiConsensus) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.

func (*AiConsensus) VerifyHeader

func (c *AiConsensus) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*AiConsensus) VerifyHeaders

func (c *AiConsensus) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. 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 (*AiConsensus) VerifySeal

func (c *AiConsensus) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*AiConsensus) VerifyUncles

func (c *AiConsensus) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.

type SignerFnWithPassphraseCached

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

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

type Snapshot

type Snapshot struct {
	Number    uint64                      `json:"number"`     // Block number where the snapshot was created
	Hash      common.Hash                 `json:"hash"`       // Block hash where the snapshot was created
	Validator map[common.Address]struct{} `json:"validators"` // Set of authorized signers at this moment
	// Recents     map[uint64]common.Address   `json:"recents"`   // Set of recent signers for spam protections
	Votes       []*Vote                     `json:"votes"`        // List of votes cast in chronological order
	Tally       map[common.Address]Tally    `json:"tally"`        // Current vote tally to avoid recalculating
	Weight      map[common.Address]*big.Int `json:"weight"`       // Weight for each PoW block miner
	PooledMiner map[common.Address]bool     `json:"pooledMiners"` // Pool miner selected in last milestone
	// contains filtered or unexported fields
}

Snapshot is the state of the authorization voting at a given point in time.

type Tally

type Tally struct {
	Authorize bool `json:"authorize"` // Whether the vote is about authorizing or kicking someone
	Votes     int  `json:"votes"`     // Number of votes until now wanting to pass the proposal
}

Tally is a simple vote tally to keep the current score of votes. Votes that go against the proposal aren't counted since it's equivalent to not voting.

type Vote

type Vote struct {
	Signer    common.Address `json:"signer"`    // Authorized signer that cast this vote
	Block     uint64         `json:"block"`     // Block number the vote was cast in (expire old votes)
	Address   common.Address `json:"address"`   // Account being voted on to change its authorization
	Authorize bool           `json:"authorize"` // Whether to authorize or deauthorize the voted account
}

Vote represents a single vote that an authorized signer made to modify the list of authorizations.

Directories

Path Synopsis
Package ethash implements the ethash proof-of-work consensus engine.
Package ethash implements the ethash proof-of-work consensus engine.

Jump to

Keyboard shortcuts

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