alien

package
v0.0.0-...-cdd992c Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: GPL-3.0, GPL-3.0 Imports: 29 Imported by: 2

Documentation

Overview

Package alien implements the delegated-proof-of-stake consensus engine.

Package alien implements the delegated-proof-of-stake consensus engine.

Index

Constants

View Source
const (
	SecondsPerYear = 2 * 365 * 24 * 3600 // Number of seconds for one year

)

Variables

View Source
var (
	SignerBlockReward                = new(big.Int).Mul(big.NewInt(5), big.NewInt(5e+18)) // Block reward in wei for successfully mining a block first year
	MinerRewardPerThousand           = uint64(618)                                        // Default reward for miner in each block from block reward (618/1000)
	DefaultLoopCntRecalculateSigners = uint64(1)                                          // Default loop count to recreate signers from top tally

)

Alien delegated-proof-of-stake 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 signer and voting mechanisms of the delegated-proof-of-stake scheme.

func (*API) GetCandidatesAndTally

func (api *API) GetCandidatesAndTally() (map[common.Address]*big.Int, error)

func (*API) GetFreezeBalance

func (api *API) GetFreezeBalance(address common.Address) (uint64, error)

func (*API) GetRemainingFreezeTime

func (api *API) GetRemainingFreezeTime(address common.Address) (uint64, error)

func (*API) GetSideCandidatesAndTally

func (api *API) GetSideCandidatesAndTally(appId string) (map[common.Address]*big.Int, error)

func (*API) GetSideFreezeBalance

func (api *API) GetSideFreezeBalance(address common.Address, appId string) (uint64, error)

func (*API) GetSideRemainingFreezeTime

func (api *API) GetSideRemainingFreezeTime(address common.Address, appId string) (uint64, error)

func (*API) GetSideSnapshot

func (api *API) GetSideSnapshot(appId string) (*Snapshot, error)

func (*API) GetSideSnapshotAtNumber

func (api *API) GetSideSnapshotAtNumber(number uint64, appId string) (*Snapshot, error)

GetSideSnapshotAtNumber retrieves the state snapshot at a given block.

func (*API) GetSideTally

func (api *API) GetSideTally(address common.Address, appId string) (uint64, error)

func (*API) GetSideVote

func (api *API) GetSideVote(address common.Address, appId string) (*Vote, error)

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

func (api *API) GetSnapshotAtNumber(number uint64) (*Snapshot, error)

GetSnapshotAtNumber retrieves the state snapshot at a given block.

func (*API) GetSnapshotByHeaderTime

func (api *API) GetSnapshotByHeaderTime(targetTime uint64) (*Snapshot, error)

GetSnapshotByHeaderTime retrieves the state snapshot by timestamp of header. snapshot.header.time <= targetTime < snapshot.header.time + period

func (*API) GetTally

func (api *API) GetTally(address common.Address) (uint64, error)

func (*API) GetVote

func (api *API) GetVote(address common.Address) (*Vote, error)

type Alien

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

Alien is the delegated-proof-of-stake consensus engine.

func New

func New(config *params.AlienConfig, db ethdb.Database, testFlag bool, eth ...core.Backend) *Alien

New creates a Alien delegated-proof-of-stake consensus engine with the initial signers set to the ones provided by the user.

func (*Alien) APIs

func (a *Alien) APIs(chain consensus.ChainReader) []rpc.API

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

func (*Alien) Author

func (a *Alien) Author(header *types.Header) (common.Address, error)

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

func (*Alien) Authorize

func (a *Alien) Authorize(signer common.Address, signFn SignerFn)

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

func (*Alien) CalcDifficulty

func (a *Alien) 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 (*Alien) Finalize

func (a *Alien) 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 (*Alien) Prepare

func (a *Alien) 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 (*Alien) Seal

func (a *Alien) 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 (*Alien) SetEth

func (a *Alien) SetEth(eth core.Backend)

func (*Alien) SignTx

func (a *Alien) SignTx(signTxFn SignTxFn)

func (*Alien) Snapshot

func (a *Alien) Snapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header, genesisVotes []*Vote, lcrs uint64) (*Snapshot, error)

func (*Alien) VerifyHeader

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

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Alien) VerifyHeaders

func (a *Alien) 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 (*Alien) VerifySeal

func (a *Alien) 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 (*Alien) VerifyUncles

func (a *Alien) 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 Cancel

type Cancel struct {
	Canceler common.Address
	Passive  bool
}

Cancel : cancel come from custom tx which data like "ufo:1:event:cancel" Sender of tx is Canceler Passive is true if

type Confirmation

type Confirmation struct {
	Signer      common.Address
	BlockNumber *big.Int
}

Confirmation : confirmation come from custom tx which data like "ufo:1:event:confirm:123" 123 is the block number be confirmed Sender of tx is Signer only if the signer in the SignerQueue for block number 123

type HeaderExtra

type HeaderExtra struct {
	CurrentBlockConfirmations []Confirmation
	CurrentBlockVotes         []Vote
	CurrentBlockCancels       []Cancel
	LoopStartTime             uint64
	SignerQueue               []common.Address
	SignerMissing             []common.Address
	ConfirmedBlockNumber      uint64
	// contains filtered or unexported fields
}

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

type SignTxFn

SignTxFn is a signTx

type SignerFn

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

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

type SignerItem

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

type SignerSlice

type SignerSlice []SignerItem

func (SignerSlice) Len

func (s SignerSlice) Len() int

func (SignerSlice) Less

func (s SignerSlice) Less(i, j int) bool

func (SignerSlice) Swap

func (s SignerSlice) Swap(i, j int)

type Snapshot

type Snapshot struct {
	LCRS uint64 // Loop count to recreate signers from top tally

	Period          uint64                       `json:"period"`          // Period of seal each block
	Number          uint64                       `json:"number"`          // Block number where the snapshot was created
	ConfirmedNumber uint64                       `json:"confirmedNumber"` // Block number confirmed when the snapshot was created
	Hash            common.Hash                  `json:"hash"`            // Block hash where the snapshot was created
	HistoryHash     []common.Hash                `json:"historyHash"`     // Block hash list for two recent loop
	Signers         []*common.Address            `json:"signers"`         // Signers queue in current header
	Votes           map[common.Address]*Vote     `json:"votes"`           // All validate votes from genesis block
	Tally           map[common.Address]*big.Int  `json:"tally"`           // Stake for each candidate address
	Voters          map[common.Address]*big.Int  `json:"voters"`          // Block number for each voter address
	Cancels         map[common.Address]*Cancel   `json:"cancels"`         // All cancels
	Cancelers       map[common.Address]*big.Int  `json:"cancelers"`       // Block number for each canceler address
	Candidates      map[common.Address][]*Vote   `json:"candidates"`      // all votes for candidates, used for private
	Punished        map[common.Address]uint64    `json:"punished"`        // The signer be punished count cause of missing seal
	Confirmations   map[uint64][]*common.Address `json:"confirms"`        // The signer confirm given block number
	HeaderTime      uint64                       `json:"headerTime"`      // Time of the current header
	LoopStartTime   uint64                       `json:"loopStartTime"`   // Start Time of the current loop
	Backup1         []byte
	Backup2         []byte
	// contains filtered or unexported fields
}

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

func (*Snapshot) CalculateReward

func (s *Snapshot) CalculateReward(coinbase common.Address, votersReward *big.Int) map[common.Address]*big.Int

type TallyItem

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

type TallySlice

type TallySlice []TallyItem

func (TallySlice) Len

func (s TallySlice) Len() int

func (TallySlice) Less

func (s TallySlice) Less(i, j int) bool

func (TallySlice) Swap

func (s TallySlice) Swap(i, j int)

type Vote

type Vote struct {
	Voter     common.Address
	Candidate common.Address
	Stake     *big.Int
	Hash      common.Hash
}

Vote : vote come from custom tx which data like "ufo:1:event:vote:stake" Sender of tx is Voter, the tx.to is Candidate or self

Jump to

Keyboard shortcuts

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