tribe

package
v0.0.0-...-4e915b7 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: Apache-2.0 Imports: 28 Imported by: 3

Documentation

Overview

Copyright 2018 The Proton Authors

Index

Constants

View Source
const (
	// None -> Volunteer -> Signer -> Sinner
	LevelNone      = "None"
	LevelVolunteer = "Volunteer"
	LevelSigner    = "Signer"
	LevelSinner    = "Sinner"

	CHIEF_NUMBER = int64(2)
)

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

	// for tribe consensus block validator
	ErrTribeNotAllowEmptyTxList = errors.New("tribe not allow empty tx list")
	ErrTribeMustContainChiefTx  = errors.New("tribe must contain chief tx")
	ErrTribeChiefCannotRepeat   = errors.New("tribe chief tx cannot repeat")
)

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
}

func (*API) GetHistory

func (api *API) GetHistory(last *big.Int, noRpc *bool) (interface{}, error)

func (*API) GetMiner

func (api *API) GetMiner(number *rpc.BlockNumber) (*TribeMiner, error)

func (*API) GetSigners

func (api *API) GetSigners(hash *common.Hash) ([]*Signer, error)

func (*API) GetSinners

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

chief-0.0.3 show blacklist

func (*API) GetStatus

func (api *API) GetStatus(hash *common.Hash) (*TribeStatus, error)

func (*API) GetVolunteers

func (api *API) GetVolunteers(hash *common.Hash) (*TribeVolunteers, error)

type History

type History struct {
	Number     int64          `json:"number"`
	Hash       common.Hash    `json:"hash"`
	Signer     common.Address `json:"signer"`
	Difficulty *big.Int       `json:"difficulty"`
	Timestamp  *big.Int       `json:"timestamp"`
}

type Signer

type Signer struct {
	Address common.Address `json:"address"` // 签名人
	Score   int64          `json:"score"`   // 分数
}

func (*Signer) String

func (self *Signer) String() string

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 Tribe

type Tribe struct {
	Status      *TribeStatus
	SealErrorCh map[int64]error // when error from seal fun, may be need commit a new work
	// contains filtered or unexported fields
}

func New

func New(config *params.TribeConfig, db ethdb.Database) *Tribe

signers set to the ones provided by the user.

func (*Tribe) APIs

func (t *Tribe) APIs(chain consensus.ChainReader) []rpc.API

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

func (*Tribe) Author

func (t *Tribe) Author(header *types.Header) (a common.Address, e error)

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

func (*Tribe) Authorize

func (t *Tribe) Authorize(signer common.Address, signFn SignerFn)

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

func (*Tribe) CalcDifficulty

func (t *Tribe) 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 (*Tribe) Finalize

func (t *Tribe) 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 (*Tribe) GetPeriod

func (t *Tribe) GetPeriod(header *types.Header, signers []*Signer) (p uint64)

func (*Tribe) Init

func (t *Tribe) Init(hash common.Hash, number *big.Int)

func (*Tribe) Prepare

func (t *Tribe) 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 (*Tribe) Seal

func (t *Tribe) 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 (*Tribe) SetMining

func (t *Tribe) SetMining(i int32, currentNumber *big.Int, currentBlockHash common.Hash)

called by worker.start and worker.stop 1 mining start 0 mining stop

func (*Tribe) VerifyHeader

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

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Tribe) VerifyHeaders

func (t *Tribe) 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 (*Tribe) VerifySeal

func (t *Tribe) 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 (*Tribe) VerifyUncles

func (t *Tribe) 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.

func (*Tribe) WaitingNomination

func (t *Tribe) WaitingNomination() chan struct{}

called by miner.start

type TribeMiner

type TribeMiner struct {
	Address common.Address `json:"address"`
	Balance *big.Int       `json:"balance"`
	Level   string         `json:"level"` // None 、 Volunteer 、 Signer
}

type TribeStatus

type TribeStatus struct {
	Signers        []*Signer        `json:"signers"`
	Volunteers     []common.Address `json:"volunteers"`     // Discarded on vsn 0.0.6
	TotalVolunteer *big.Int         `json:"totalVolunteer"` // add by vsn 0.0.6
	SignerLevel    string           `json:"signerLevel"`    // None -> Volunteer -> Signer
	Number         int64            `json:"number"`         // last block.number
	BlackListLen   int              `json:"totalSinner"`    // length of blacklist
	// for watch the set method result
	Epoch          *big.Int `json:"epoch"`
	SignerLimit    *big.Int `json:"signerLimit"`
	VolunteerLimit *big.Int `json:"volunteerLimit"`
	Vsn            string   `json:"version"` // chief version
	// contains filtered or unexported fields
}

func NewTribeStatus

func NewTribeStatus() *TribeStatus

func (*TribeStatus) GetMinerAddress

func (self *TribeStatus) GetMinerAddress() common.Address

func (*TribeStatus) GetSigners

func (self *TribeStatus) GetSigners() []*Signer

func (*TribeStatus) GetSignersFromChiefByHash

func (self *TribeStatus) GetSignersFromChiefByHash(hash common.Hash, number *big.Int) ([]*Signer, error)

func (*TribeStatus) InTurnForCalc

func (self *TribeStatus) InTurnForCalc(signer common.Address, parent *types.Header) *big.Int

func (*TribeStatus) InTurnForVerify

func (self *TribeStatus) InTurnForVerify(number int64, parentHash common.Hash, signer common.Address) *big.Int

func (*TribeStatus) LoadSignersFromChief

func (self *TribeStatus) LoadSignersFromChief(hash common.Hash, number *big.Int) error

在 加载完所有 node.service 后,需要主动调用一次

func (*TribeStatus) String

func (self *TribeStatus) String() string

func (*TribeStatus) Update

func (self *TribeStatus) Update(currentNumber *big.Int, hash common.Hash)

called by end of WriteBlockAndState if miner then execute chief.update and chief.getStatus else execute chief.getStatus only

func (*TribeStatus) ValidateBlock

func (self *TribeStatus) ValidateBlock(parent, block *types.Block, validateSigner bool) error

every block sync download or mine check chief tx

func (*TribeStatus) ValidateSigner

func (self *TribeStatus) ValidateSigner(parentHeader, header *types.Header, signer common.Address) bool

type TribeVolunteers

type TribeVolunteers struct {
	Length     *big.Int     `json:length`
	Volunteers []*Volunteer `json:"volunteers"`
}

type Volunteer

type Volunteer struct {
	Address common.Address `json:"address"` // 候选人
	Weight  int64          `json:"weight"`  // 权重
}

append chief vsn 0.0.6

Jump to

Keyboard shortcuts

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