Documentation ¶
Index ¶
- Constants
- Variables
- func AddrIndex(addr common.Address, list []common.Address) int
- func AddrListHash(addrList []common.Address) (hash common.Hash)
- func AddrListToNodeList(addrToNodeID map[common.Address]string, addrList []common.Address) []interface{}
- func AddressList() []common.Address
- func BytesToID(temp []byte) *discover.NodeID
- func CalcPIndex(number uint64, view uint64, num_miners uint64) uint64
- func EliminateSigningField(header *types.Header) *types.Header
- func GetNodeConfig(ctx *node.ServiceContext) (string, string, common.Address, error)
- func GetNodeID(ctx *node.ServiceContext) string
- func HexToID(flag bool, s string) interface{}
- func IndexInSlice(i int, s []uint64) bool
- func NodeList(flag bool) []interface{}
- type API
- func (api *API) CheckVote() error
- func (api *API) ClearVote() error
- func (api *API) GetByzantine()
- func (api *API) GetGroupSigsAtHash(blockHash common.Hash) ([]GroupSigFormatter, error)
- func (api *API) GetGroupSigsAtNumber(number *rpc.BlockNumber) ([]GroupSigFormatter, error)
- func (api *API) GetMinerList() error
- func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetSignersAtHash(hash common.Hash) ([]common.Address, error)
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*SnapShot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*SnapShot, error)
- func (api *API) IsVoteInEffect(currVoteList []common.Address) bool
- func (api *API) SetByzantine(byzantine bool)
- func (api *API) Test()
- func (api *API) UpdateVote(addrStr string, updatedVotingAt uint64) error
- type AdvertToNewViewEvent
- type ChangeView
- type ChangeViewEvent
- type ControlChangeV
- type ControlNewViewBroadCast
- type ControlPreReq
- type ControlPreResp
- type ControlTxRequest
- type Dbft
- func (d *Dbft) APIs(chain consensus.ChainReader) []rpc.API
- func (d *Dbft) Author(header *types.Header) (common.Address, error)
- func (d *Dbft) Authorize(signer common.Address, signFn SignerFn)
- func (d *Dbft) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int
- func (d *Dbft) Consensus(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (d *Dbft) ConsensusRound(chain consensus.ChainReader, round *Round)
- func (d *Dbft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (d *Dbft) GetConsensusConfig() params.ConsensusConfig
- func (d *Dbft) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (d *Dbft) RequiredNodes(numMiners uint64) int
- func (d *Dbft) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
- func (d *Dbft) SnapShot(chain consensus.ChainReader, number uint64, hash common.Hash, ...) (*SnapShot, error)
- func (d *Dbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (d *Dbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (d *Dbft) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (d *Dbft) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type GetAdvertToNewViewEvent
- type GetChangeViewEvent
- type GetPrepareReqEvent
- type GetPrepareRespEvent
- type GetTxPoolEvent
- type GetTxReqEvent
- type GetTxRespEvent
- type GroupSigFormatter
- type NewViewBroadCast
- type PrepareReqEvent
- type PrepareRequest
- type PrepareRespEvent
- type PrepareResponse
- type QuitMiningEvent
- type Round
- type RoundStateEvent
- type SendTxReqEvent
- type SendTxRespEvent
- type SignerFn
- type SnapShot
- type TxPool
- type TxRequest
- type TxResponse
- type VoteEvent
Constants ¶
const ( WaitingForPeriod = iota SentPreReq SentAllTxResp )
Speaker states
const ( NoPreReq = iota HasPreReq SentTxReq HasTxResp )
Delegate states
const ( PIndexTampered = iota MaliciousAdvertNewView MaliciousVoting )
const (
IDLength = 64
)
Variables ¶
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.
var (
MinePeriod = uint64(0) // Default minimum difference between two mining operation's timestamps
)
Protocol constants.
Functions ¶
func AddrListHash ¶
AddrListHash returns the hash value of a set of addresses.
func AddrListToNodeList ¶
func AddrListToNodeList(addrToNodeID map[common.Address]string, addrList []common.Address) []interface{}
Returns a list of nodeIDs in the correct order
func AddressList ¶
func EliminateSigningField ¶
EliminateSigningField eliminates the proposer address in the extra-data field prior to validation.
func GetNodeConfig ¶
TODO: This func needs a rewrite, too many magic here.
func GetNodeID ¶
func GetNodeID(ctx *node.ServiceContext) string
Returns the nodeID from the nodekey
func IndexInSlice ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a user facing RPC API to allow controlling the signer mechanisms of dbft scheme.
func (*API) GetByzantine ¶
func (api *API) GetByzantine()
func (*API) GetGroupSigsAtHash ¶
func (api *API) GetGroupSigsAtHash(blockHash common.Hash) ([]GroupSigFormatter, error)
GetGroupSigsAtHash retrieves the group signature at a given block.
func (*API) GetGroupSigsAtNumber ¶
func (api *API) GetGroupSigsAtNumber(number *rpc.BlockNumber) ([]GroupSigFormatter, error)
GetGroupSigsAtNumber retrieves the group signature at a given block.
func (*API) GetMinerList ¶
Prints out the current list of miners
func (*API) GetSigners ¶
GetSigners retrieves the list of authorized signers at the specified block. Here the signer is the node who broadcasts the newblock
func (*API) GetSignersAtHash ¶
GetSignersAtHash retrieves the state snapshot at a given block. Here the signer is the node who broadcasts the newblock
func (*API) GetSnapshot ¶
func (api *API) GetSnapshot(number *rpc.BlockNumber) (*SnapShot, error)
GetSnapshot retrieves the state snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
func (*API) IsVoteInEffect ¶
Returns whether the current voting list is the also the current mining list.
func (*API) SetByzantine ¶
APIs to test the Byzantine faulty
type AdvertToNewViewEvent ¶
type AdvertToNewViewEvent struct{}
type ChangeView ¶
type ChangeView struct{}
type ChangeViewEvent ¶
type ChangeViewEvent struct{}
type ControlChangeV ¶
type ControlChangeV struct{}
func NewChangeView ¶
func NewChangeView(round *Round) (*ControlChangeV, error)
func (*ControlChangeV) Get ¶
func (control *ControlChangeV) Get() *ChangeView
type ControlNewViewBroadCast ¶
type ControlNewViewBroadCast struct{}
func NewBroadcastNewView ¶
func NewBroadcastNewView(round *Round, newView uint64) (*ControlNewViewBroadCast, error)
func (*ControlNewViewBroadCast) Get ¶
func (control *ControlNewViewBroadCast) Get() *NewViewBroadCast
func (*ControlNewViewBroadCast) GetNewV ¶
func (control *ControlNewViewBroadCast) GetNewV() uint64
type ControlPreReq ¶
type ControlPreReq struct{}
func NewPrepareReq ¶
func NewPrepareReq(header *types.Header, headerSig []byte, round *Round, config *params.DbftConfig, sigcache *lru.ARCCache) (*ControlPreReq, error)
The sigcache is often the signatures
func (*ControlPreReq) Get ¶
func (control *ControlPreReq) Get() *PrepareRequest
TODO: These are pretty bad APIs
type ControlPreResp ¶
type ControlPreResp struct{}
func NewPrepareResp ¶
func NewPrepareResp(round *Round, config *params.DbftConfig, sigcache *lru.ARCCache) (*ControlPreResp, error)
func (*ControlPreResp) Get ¶
func (control *ControlPreResp) Get() *PrepareResponse
type ControlTxRequest ¶
type ControlTxRequest struct{}
func NewTxRequest ¶
func NewTxRequest(round *Round) (*ControlTxRequest, error)
func (*ControlTxRequest) Get ¶
func (control *ControlTxRequest) Get() *TxRequest
type Dbft ¶
type Dbft struct {
// contains filtered or unexported fields
}
Dbft is the Delegated Byzantine Fault Tolerance consensus engine
func New ¶
func New(ctx *node.ServiceContext, config *params.DbftConfig, db ethdb.Database, eventMux *event.TypeMux, isLight bool) *Dbft
New creates a Dbft consensus engine with the initial signers set to the ones provided by the user.
func (*Dbft) APIs ¶
func (d *Dbft) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer signing.
func (*Dbft) Author ¶
Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.
func (*Dbft) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Dbft) CalcDifficulty ¶
func (d *Dbft) 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 (*Dbft) Consensus ¶
func (d *Dbft) Consensus(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)
Main entry
func (*Dbft) ConsensusRound ¶
func (d *Dbft) ConsensusRound(chain consensus.ChainReader, round *Round)
Rounds regarding the view number
func (*Dbft) Finalize ¶
func (d *Dbft) 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 (*Dbft) GetConsensusConfig ¶
func (d *Dbft) GetConsensusConfig() params.ConsensusConfig
func (*Dbft) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Dbft) RequiredNodes ¶
Calculates the minimum required nodes to have 2/3 consensus. This is 3 when numMiners is 4
func (*Dbft) Seal ¶
func (d *Dbft) 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 (*Dbft) SnapShot ¶
func (d *Dbft) SnapShot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) (*SnapShot, error)
Returns a snapshot containing a count of how many times each signer has contributed. SnapShot chain is always one block behind the canonical chain
func (*Dbft) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Dbft) VerifyHeaders ¶
func (d *Dbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
This function is called by InsertChain() in blockchain.go
func (*Dbft) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Dbft) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
type GetAdvertToNewViewEvent ¶
type GetAdvertToNewViewEvent struct{}
type GetChangeViewEvent ¶
type GetChangeViewEvent struct{}
type GetPrepareReqEvent ¶
type GetPrepareReqEvent struct{ PreReq *PrepareRequest }
type GetPrepareRespEvent ¶
type GetPrepareRespEvent struct{}
type GetTxPoolEvent ¶
type GetTxPoolEvent struct{ Txpool TxPool } // deprecated
type GetTxReqEvent ¶
type GetTxReqEvent struct{}
type GetTxRespEvent ¶
type GetTxRespEvent struct{}
type GroupSigFormatter ¶
type NewViewBroadCast ¶
type NewViewBroadCast struct{}
type PrepareReqEvent ¶
type PrepareReqEvent struct{}
type PrepareRequest ¶
type PrepareRequest struct{}
type PrepareRespEvent ¶
type PrepareRespEvent struct{}
type PrepareResponse ¶
type PrepareResponse struct{}
type QuitMiningEvent ¶
type QuitMiningEvent struct{}
type Round ¶
type Round struct { }
Round holds important information about the current round of dbft consensus
type SendTxReqEvent ¶
type SendTxReqEvent struct{}
type SendTxRespEvent ¶
type SendTxRespEvent struct{}
type SignerFn ¶
SignerFn is a signer callback function to request a hash to be signed by a backing account. // Sign all the things! sighash, err := signFn(accounts.Account{Address: signer}, sigHash(header).Bytes())
type SnapShot ¶
type TxPool ¶
type TxPool interface{}
TxPool wraps all methods required to retrieve the txpool. deprecated
type TxResponse ¶
type TxResponse struct{}
func NewTxResponse ¶
func NewTxResponse(txs types.Transactions, i uint64) (*TxResponse, error)