tribe

package
v0.0.0-...-c2b07a9 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Copyright 2018 The Spectrum Authors

Index

Constants

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

	CHIEF_NUMBER = int64(3) //最早版本chief合约开始生效的块数
)

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")
	ErrInvalidTimestampSIP002 = errors.New("invalid timestamp (SIP002)")

	// for tribe consensus block validator
	ErrTribeNotAllowEmptyTxList                 = errors.New("tribe not allow empty tx list")
	ErrTribeMustContainChiefTx                  = errors.New("tribe must contain chief tx")
	ErrTribeChiefVolunteerLowBalance            = errors.New("tribe chief volunteer low balance")
	ErrTribeChiefVolunteerFail                  = errors.New("tribe chief volunteer check fail")
	ErrTribeChiefTxMustAtPositionZero           = errors.New("tribe chief tx must at postion 0")
	ErrTribeChiefTxSignerAndBlockSignerNotMatch = errors.New("tribe chief update tx signer and block signer not match")
	ErrTribeValdateTxSenderCannotInSignerList   = errors.New("tx sender cannot in signerlist")

	Chief100BlockReward, _                      = new(big.Int).SetString("35000000000000000000", 10) //Block reward in wei for successfully mining a block
	BlockRewardReducedInterval                  = 4505000                                            //half reward about two years
	SmartMeshFoundationAccount                  = common.HexToAddress("0xe0014a4268ad3d7b131551be47bc6ed72a6937e4")
	SmartMeshFoundationAccountDestroyBalance, _ = new(big.Int).SetString("376991118360000000000000000", 10)
)

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

func (api *API) Bind(from *common.Address, passphrase string) (string, error)

func (*API) BindInfo

func (api *API) BindInfo(addr *common.Address, num *big.Int) (map[string]interface{}, error)

func (*API) BindSign

func (api *API) BindSign(from *common.Address) (string, error)

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)

func (*API) PocDeposit

func (api *API) PocDeposit(from *common.Address, passphrase string) (string, error)

PocDeposit 调用poc合约的deposit质押,满足金额以后,自动开启挖矿

func (*API) PocGetStatus

func (api *API) PocGetStatus(hash *common.Hash) (*params.PocStatus, error)

PocGetStatus 查询poc合约状态

func (*API) PocStart

func (api *API) PocStart(from *common.Address, passphrase string) (string, error)

PocStart 调用poc合约的start,从stop状态恢复,开启挖矿

func (*API) PocStop

func (api *API) PocStop(from *common.Address, passphrase string) (string, error)

PocStop 调用poc合约的stop,停止挖矿,准备撤回抵押

func (*API) PocWithdraw

func (api *API) PocWithdraw(from *common.Address, passphrase string) (string, error)

PocWithdraw 调用poc合约的withdraw,在stop两周后,可以撤回押金

func (*API) PocWithdrawSurplus

func (api *API) PocWithdrawSurplus(from *common.Address, passphrase string) (string, error)

PocWithdrawSurplus 调用poc合约的PocWithdrawSurplus,从合约中撤回多余的抵押押金

func (*API) Unbind

func (api *API) Unbind(from *common.Address, passphrase string) (string, 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
	// contains filtered or unexported fields
}

func New

func New(accman *accounts.Manager, config *params.TribeConfig, _ 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) (common.Address, error)

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

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

func (t *Tribe) GetChiefUpdateTx(chain consensus.ChainReader, header *types.Header, state *state.StateDB) *types.Transaction

获取要插入的chief Tx 1.0之后是通过vrf来选择下一轮出块人 1.0之前因为没有奖励,所以是现有signer任意指定候选人

func (*Tribe) GetConfig

func (t *Tribe) GetConfig() *params.TribeConfig

func (*Tribe) GetPeriod

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

func (*Tribe) GetPeriodChief100

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

GetPeriodChief100: 计算出块节点对应的延时时间 依据: 普通节点替补出块规则调整为当前常委会出块节点替补出块,当前常委会出块节点替补出块规则调整为常委会节点列表顺序替补出块,出块难度依次递减。 当普通节点出块时,难度为6->5->4->3->2->1;当常委会节点出块时,难度为6->5->4->3->2。每次替补出块时间都顺延4秒, 下一个区块将在当前区块产生以后的14秒+ 以后产生。 总共只有5个常委会节点,其排序固定 signers:[0,...,16] 0号对应的是常委会节点,1-16对应的是普通出块节点 场景1: 假设`header`中的块该signers[3]出, 如果signers[3]出,则延时14秒,否则只能由其他常委会节点替代 假设当前signers[0]对应的是常委2,那么如果常委2出则延时18,常委3出则延时22,...,如果常委1出则延时34 场景2: 假设`header`中的块该signers[0]出, 如果signers[0]出,则延时14秒,否则只能由其他常委会节点替代 假设当前signers[0]对应的是常委2,那么常委3出则延时18,常委4出则延时22,...常委1出则延时30

func (*Tribe) Init

func (t *Tribe) Init()

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

func (t *Tribe) SetConfig(config *params.TribeConfig)

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. don't support remote miner agent, these code never reached

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.

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"`
	Leaders     []common.Address `json:"leaders"`
	SignerLevel string           `json:"signerLevel"` // None -> Volunteer -> Signer
	Number      int64            `json:"number"`      // last block.number
	// for watch the set method result
	Epoch       *big.Int `json:"epoch"`
	LeaderLimit *big.Int `json:"leaderLimit"`
	SignerLimit *big.Int `json:"signerLimit"`
	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) GetMinerAddressByChan

func (self *TribeStatus) GetMinerAddressByChan(rtn chan common.Address)

func (*TribeStatus) GetNodeKey

func (self *TribeStatus) GetNodeKey() *ecdsa.PrivateKey

func (*TribeStatus) InTurnForCalcDiffcultyChief100

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

InTurnForCalcDiffcultyChief100 计算规则参考inTurnForCalcChief100

func (*TribeStatus) InTurnForCalcDifficulty

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

InTurnForCalcDifficulty 在0.6版本yiqian 计算难度

func (*TribeStatus) InTurnForVerifyDiffculty

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

0.6版本之前校验难度

func (*TribeStatus) InTurnForVerifyDifficultyChief100

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

InTurnForVerifyDifficultyChief100: 计算规则参考inTurnForCalcChief100

func (*TribeStatus) IsLeader

func (self *TribeStatus) IsLeader(addr common.Address) bool

func (*TribeStatus) LoadStatusFromChief

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

在每次出块prepare的时候去获取一次,同时在同步区块的时候去获取一次,同步区块获取的是最新块的父区块信息,出块时获取的是当前本地最新块的状态信息

func (*TribeStatus) SetNodeKey

func (self *TribeStatus) SetNodeKey(nodeKey *ecdsa.PrivateKey)

func (*TribeStatus) SetTribe

func (self *TribeStatus) SetTribe(tribe *Tribe)

func (*TribeStatus) String

func (self *TribeStatus) String() string

func (*TribeStatus) ValidateBlock

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

every block sync download or mine check chief tx

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