apoa

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApoaProto

func ApoaProto(header block.IHeader) []byte

func New

func New(config *params.CliqueConfig, db kv.RwDB) consensus.Engine

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

func SealHash

func SealHash(header block.IHeader) (hash types.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 jsonrpc API to allow controlling the signer 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 signer from casting further votes (either for or against).

func (*API) GetSigner

func (api *API) GetSigner(rlpOrBlockNr *blockNumberOrHashOrRLP) (types.Address, error)

GetSigner returns the signer for a specific apoa block. Can be called with either a blocknumber, blockhash or an rlp encoded blob. The RLP encoded blob can either be a block or a header.

func (*API) GetSigners

func (api *API) GetSigners(number *jsonrpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block.

func (*API) GetSignersAtHash

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

GetSignersAtHash retrieves the list of authorized signers at the specified block.

func (*API) GetSnapshot

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

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

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

GetSnapshotAtHash 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 signer will attempt to push through.

func (*API) Status

func (api *API) Status() (*status, error)

Status returns the status of the last N blocks, - the number of active signers, - the number of signers, - the percentage of in-turn blocks

type Apoa

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

Apoa is the proof-of-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.

func (*Apoa) APIs

func (c *Apoa) APIs(chain consensus.ChainReader) []jsonrpc.API

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

func (*Apoa) Author

func (c *Apoa) Author(header block.IHeader) (types.Address, error)

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

func (*Apoa) Authorize

func (c *Apoa) Authorize(signer types.Address, signFn SignerFn)

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

func (*Apoa) CalcDifficulty

func (c *Apoa) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent block.IHeader) *uint256.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have: * DIFF_NOTURN(2) if BLOCK_NUMBER % SIGNER_COUNT != SIGNER_INDEX * DIFF_INTURN(1) if BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX

func (*Apoa) Close

func (c *Apoa) Close() error

Close implements consensus.Engine. It's a noop for Apoa as there are no background threads.

func (*Apoa) Finalize

func (c *Apoa) Finalize(chain consensus.ChainHeaderReader, header block.IHeader, state *state.IntraBlockState, txs []*transaction.Transaction, uncles []block.IHeader) ([]*block.Reward, map[types.Address]*uint256.Int, error)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.

func (*Apoa) FinalizeAndAssemble

func (c *Apoa) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header block.IHeader, state *state.IntraBlockState, txs []*transaction.Transaction, uncles []block.IHeader, receipts []*block.Receipt) (block.IBlock, []*block.Reward, map[types.Address]*uint256.Int, error)

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

func (*Apoa) IsServiceTransaction

func (c *Apoa) IsServiceTransaction(sender types.Address, syscall consensus.SystemCall) bool

func (*Apoa) Prepare

func (c *Apoa) Prepare(chain consensus.ChainHeaderReader, header block.IHeader) error

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

func (*Apoa) Rewards

func (c *Apoa) Rewards(tx kv.RwTx, header block.IHeader, state *state.IntraBlockState, setRewards bool) ([]*block.Reward, error)

func (*Apoa) Seal

func (c *Apoa) Seal(chain consensus.ChainHeaderReader, b block.IBlock, results chan<- block.IBlock, stop <-chan struct{}) error

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

func (*Apoa) SealHash

func (c *Apoa) SealHash(header block.IHeader) types.Hash

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

func (*Apoa) Type

func (c *Apoa) Type() params.ConsensusType

func (*Apoa) VerifyHeader

func (c *Apoa) VerifyHeader(chain consensus.ChainHeaderReader, header block.IHeader, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Apoa) VerifyHeaders

func (c *Apoa) VerifyHeaders(chain consensus.ChainHeaderReader, headers []block.IHeader, 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 (*Apoa) VerifyUncles

func (c *Apoa) VerifyUncles(chain consensus.ChainReader, block block.IBlock) error

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

type SignerFn

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

SignerFn hashes and signs the data to be signed by a backing account. todo types.address to account

type Snapshot

type Snapshot struct {
	Number  uint64                     `json:"number"`  // Block number where the snapshot was created
	Hash    types.Hash                 `json:"hash"`    // Block hash where the snapshot was created
	Signers map[types.Address]struct{} `json:"signers"` // Set of authorized signers at this moment
	Recents map[uint64]types.Address   `json:"recents"` // Set of recent signers for spam protections
	Votes   []*Vote                    `json:"votes"`   // List of votes cast in chronological order
	Tally   map[types.Address]Tally    `json:"tally"`   // Current vote tally to avoid recalculating
	// 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    types.Address `json:"signer"`    // Authorized signer that cast this vote
	Block     uint64        `json:"block"`     // Block number the vote was cast in (expire old votes)
	Address   types.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.

Jump to

Keyboard shortcuts

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