alien

package
v0.0.0-...-1f2bba2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2019 License: GPL-3.0, GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

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

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

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

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.

View Source
var SCCurrentBlockReward = map[uint64]map[uint64]uint64{1: {1: 100},
	2: {1: 30, 2: 70},
	3: {1: 15, 2: 30, 3: 55},
	4: {1: 5, 2: 15, 3: 30, 4: 50},
	5: {1: 5, 2: 10, 3: 15, 4: 25, 5: 45},
	6: {1: 1, 2: 4, 3: 10, 4: 15, 5: 25, 6: 45}}

SCCurrentBlockReward is base on scMaxCountPerPeriod = 6

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) 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, scHash common.Hash) (*Snapshot, error)

GetSnapshotByHeaderTime retrieves the state snapshot by timestamp of header. snapshot.header.time <= targetTime < snapshot.header.time + period todo: add confirm headertime in return snapshot, to minimize the request from side chain

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) *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) ApplyGenesis

func (a *Alien) ApplyGenesis(chain consensus.ChainReader, genesisHash common.Hash) error

ApplyGenesis

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, signTxFn SignTxFn)

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

type CCNotice struct {
	CurrentCharging map[common.Hash]GasCharging `json:"currentCharging"` // common.Hash here is the proposal txHash not the hash of side chain
	ConfirmReceived map[common.Hash]NoticeCR    `json:"confirmReceived"` // record the confirm address
}

CCNotice (cross chain notice) contain the information main chain need to notify given side chain

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 Declare

type Declare struct {
	ProposalHash common.Hash
	Declarer     common.Address
	Decision     bool
}

Declare : declare come from custom tx which data like "ufo:1:event:declare:hash:yes" proposal only come from the current candidates hash is the hash of proposal tx

type GasCharging

type GasCharging struct {
	Target common.Address // target address on side chain
	Volume uint64         // volume of gas need charge (unit is ttc)
	Hash   common.Hash    // the hash of proposal, use as id of this proposal
}

type HeaderExtra

type HeaderExtra struct {
	CurrentBlockConfirmations []Confirmation
	CurrentBlockVotes         []Vote
	CurrentBlockProposals     []Proposal
	CurrentBlockDeclares      []Declare
	ModifyPredecessorVotes    []Vote
	LoopStartTime             uint64
	SignerQueue               []common.Address
	SignerMissing             []common.Address
	ConfirmedBlockNumber      uint64
	SideChainConfirmations    []SCConfirmation
	SideChainSetCoinbases     []SCSetCoinbase
	SideChainNoticeConfirmed  []SCConfirmation
	SideChainCharging         []GasCharging //This only exist in side chain's header.Extra
}

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

type NoticeCR

type NoticeCR struct {
	NRecord map[common.Address]bool `json:"noticeConfirmRecord"`
	Number  uint64                  `json:"firstReceivedNumber"` // this number will fill when there are more than 2/3+1 maxSignerCnt
	Type    uint64                  `json:"noticeType"`
	Success bool                    `json:"success"`
}

type Proposal

type Proposal struct {
	Hash                   common.Hash    // tx hash
	ReceivedNumber         *big.Int       // block number of proposal received
	CurrentDeposit         *big.Int       // received deposit for this proposal
	ValidationLoopCnt      uint64         // validation block number length of this proposal from the received block number
	ProposalType           uint64         // type of proposal 1 - add candidate 2 - remove candidate ...
	Proposer               common.Address // proposer
	TargetAddress          common.Address // candidate need to add/remove if candidateNeedPD == true
	MinerRewardPerThousand uint64         // reward of miner + side chain miner
	SCHash                 common.Hash    // side chain genesis parent hash need to add/remove
	SCBlockCountPerPeriod  uint64         // the number block sealed by this side chain per period, default 1
	SCBlockRewardPerPeriod uint64         // the reward of this side chain per period if SCBlockCountPerPeriod reach, default 0. SCBlockRewardPerPeriod/1000 * MinerRewardPerThousand/1000 * BlockReward is the reward for this side chain
	Declares               []*Declare     // Declare this proposal received (always empty in block header)
	MinVoterBalance        uint64         // value of minVoterBalance , need to mul big.Int(1e+18)
	ProposalDeposit        uint64         // The deposit need to be frozen during before the proposal get final conclusion. (TTC)
	SCRentFee              uint64         // number of TTC coin, not wei
	SCRentRate             uint64         // how many coin you want for 1 TTC on main chain
	SCRentLength           uint64         // minimize block number of main chain , the rent fee will be used as reward of side chain miner.
}

Proposal : proposal come from custom tx which data like "ufo:1:event:proposal:candidate:add:address" or "ufo:1:event:proposal:percentage:60" proposal only come from the current candidates not only candidate add/remove , current signer can proposal for params modify like percentage of reward distribution ...

type RefundGas

type RefundGas map[common.Address]*big.Int

RefundGas : refund gas to tx sender

type RefundHash

type RefundHash map[common.Hash]RefundPair

RefundHash :

type RefundPair

type RefundPair struct {
	Sender   common.Address
	GasPrice *big.Int
}

RefundPair :

type SCBlockReward

type SCBlockReward struct {
	RewardScoreMap map[common.Address]uint64 //sum(this value) in one period == 100
}

Score to calculate at one main chain block, for calculate the side chain reward

type SCConfirmation

type SCConfirmation struct {
	Hash     common.Hash
	Coinbase common.Address // the side chain signer , may be diff from signer in main chain
	Number   uint64
	LoopInfo []string
}

SCConfirmation is the confirmed tx send by side chain super node

type SCRecord

type SCRecord struct {
	Record              map[uint64][]*SCConfirmation `json:"record"`              // Confirmation Record of one side chain
	LastConfirmedNumber uint64                       `json:"lastConfirmedNumber"` // Last confirmed header number of one side chain
	MaxHeaderNumber     uint64                       `json:"maxHeaderNumber"`     // max header number of one side chain
	CountPerPeriod      uint64                       `json:"countPerPeriod"`      // block sealed per period on this side chain
	RewardPerPeriod     uint64                       `json:"rewardPerPeriod"`     // full reward per period, number per thousand
	RentReward          map[common.Hash]*SCRentInfo  `json:"rentReward"`          // reward info by rent
}

SCRecord is the state record for side chain

type SCRentInfo

type SCRentInfo struct {
	RentPerPeriod   *big.Int `json:"rentPerPeriod"`
	MaxRewardNumber *big.Int `json:"maxRewardNumber"`
}

type SCReward

type SCReward struct {
	SCBlockRewardMap map[uint64]*SCBlockReward
}

Record for one side chain

type SCSetCoinbase

type SCSetCoinbase struct {
	Hash     common.Hash
	Signer   common.Address
	Coinbase common.Address
}

SCSetCoinbase is the tx send by main chain super node which can set coinbase for side chain

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
	Candidates      map[common.Address]uint64                         `json:"candidates"`        // Candidates for Signers (0- adding procedure 1- normal 2- removing procedure)
	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
	Proposals       map[common.Hash]*Proposal                         `json:"proposals"`         // The Proposals going or success (failed proposal will be removed)
	HeaderTime      uint64                                            `json:"headerTime"`        // Time of the current header
	LoopStartTime   uint64                                            `json:"loopStartTime"`     // Start Time of the current loop
	ProposalRefund  map[uint64]map[common.Address]*big.Int            `json:"proposalRefund"`    // Refund proposal deposit
	SCCoinbase      map[common.Address]map[common.Hash]common.Address `json:"sideChainCoinbase"` // main chain set Coinbase of side chain setting
	SCRecordMap     map[common.Hash]*SCRecord                         `json:"sideChainRecord"`   // main chain record Confirmation of side chain setting
	SCRewardMap     map[common.Hash]*SCReward                         `json:"sideChainReward"`   // main chain record Side Chain Reward
	SCNoticeMap     map[common.Hash]*CCNotice                         `json:"sideChainNotice"`   // main chain record Notification to side chain
	LocalNotice     *CCNotice                                         `json:"localNotice"`       // side chain record Notification
	MinerReward     uint64                                            `json:"minerReward"`       // miner reward per thousand
	MinVB           *big.Int                                          `json:"minVoterBalance"`   // min voter balance
	// contains filtered or unexported fields
}

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

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
}

Vote : vote come from custom tx which data like "ufo:1:event:vote" Sender of tx is Voter, the tx.to is Candidate Stake is the balance of Voter when create this vote

Jump to

Keyboard shortcuts

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