dbft

package
v0.0.0-...-b564531 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2019 License: GPL-3.0, GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WaitingForPeriod = iota
	SentPreReq
	SentAllTxResp
)

Speaker states

View Source
const (
	NoPreReq = iota
	HasPreReq
	SentTxReq
	HasTxResp
)

Delegate states

View Source
const (
	PIndexTampered = iota
	MaliciousAdvertNewView
	MaliciousVoting
)
View Source
const (
	IDLength = 64
)

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 (
	MinePeriod = uint64(0) // Default minimum difference between two mining operation's timestamps

)

Protocol constants.

Functions

func AddrIndex

func AddrIndex(addr common.Address, list []common.Address) int

func AddrListHash

func AddrListHash(addrList []common.Address) (hash common.Hash)

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 AddressList() []common.Address

func BytesToID

func BytesToID(temp []byte) *discover.NodeID

func CalcPIndex

func CalcPIndex(number uint64, view uint64, num_miners uint64) uint64

func EliminateSigningField

func EliminateSigningField(header *types.Header) *types.Header

EliminateSigningField eliminates the proposer address in the extra-data field prior to validation.

func GetNodeConfig

func GetNodeConfig(ctx *node.ServiceContext) (string, string, common.Address, error)

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 HexToID

func HexToID(flag bool, s string) interface{}

func IndexInSlice

func IndexInSlice(i int, s []uint64) bool

func NodeList

func NodeList(flag bool) []interface{}

test Node

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

func (api *API) CheckVote() error

Allows a user to check their vote

func (*API) ClearVote

func (api *API) ClearVote() error

Clears the user's vote

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

func (api *API) GetMinerList() error

Prints out the current list of miners

func (*API) GetSigners

func (api *API) GetSigners(number *rpc.BlockNumber) ([]common.Address, error)

GetSigners retrieves the list of authorized signers at the specified block. Here the signer is the node who broadcasts the newblock

func (*API) GetSignersAtHash

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

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

func (api *API) GetSnapshotAtHash(hash common.Hash) (*SnapShot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

func (*API) IsVoteInEffect

func (api *API) IsVoteInEffect(currVoteList []common.Address) bool

Returns whether the current voting list is the also the current mining list.

func (*API) SetByzantine

func (api *API) SetByzantine(byzantine bool)

APIs to test the Byzantine faulty

func (*API) Test

func (api *API) Test()

An API just for me to write personal tests

func (*API) UpdateVote

func (api *API) UpdateVote(addrStr string, updatedVotingAt uint64) error

User enters a list of comma separated addresses, which he desires to be the next mining list.

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

func (d *Dbft) 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 (*Dbft) Authorize

func (d *Dbft) Authorize(signer common.Address, signFn SignerFn)

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

func (d *Dbft) 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 (*Dbft) RequiredNodes

func (d *Dbft) RequiredNodes(numMiners uint64) int

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

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

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

func (d *Dbft) 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 (*Dbft) VerifyUncles

func (d *Dbft) 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 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 GroupSigFormatter struct {
	Sig    string `json:"sigs"`
	IIndex uint64 `json:"i"`
}

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 RoundStateEvent

type RoundStateEvent struct{}

ConsensusEvents:

type SendTxReqEvent

type SendTxReqEvent struct{}

type SendTxRespEvent

type SendTxRespEvent struct{}

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. // Sign all the things! sighash, err := signFn(accounts.Account{Address: signer}, sigHash(header).Bytes())

type SnapShot

type SnapShot struct {
	Number  uint64                    `json:"number"`
	Hash    common.Hash               `json:"hash"`
	Signers map[common.Address]uint64 `json:"signers"`
	// contains filtered or unexported fields
}

func NewSnapShot

func NewSnapShot(config *params.DbftConfig, sigcache *lru.ARCCache, number uint64, hash common.Hash, signers []common.Address) *SnapShot

type TxPool

type TxPool interface{}

TxPool wraps all methods required to retrieve the txpool. deprecated

type TxRequest

type TxRequest struct{}

type TxResponse

type TxResponse struct{}

func NewTxResponse

func NewTxResponse(txs types.Transactions, i uint64) (*TxResponse, error)

type VoteEvent

type VoteEvent struct{}

Jump to

Keyboard shortcuts

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