Documentation ¶
Overview ¶
Copyright 2019 The go-smilo Authors Copyright 2017 The go-ethereum Authors This file is part of the go-ethereum library.
The go-ethereum library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The go-ethereum library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
Index ¶
- Variables
- func CheckFullnodeSignature(fullnodeSet FullnodeSet, data []byte, sig []byte) (common.Address, error)
- func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)
- func RLPHash(v interface{}) (h common.Hash)
- type Backend
- type BlockProposal
- type BlockProposalSelector
- type Config
- type FinalCommittedEvent
- type Fullnode
- type FullnodeSet
- type Fullnodes
- type MessageEvent
- type Preprepare
- type Request
- type RequestEvent
- type SpeakerPolicy
- type Subject
- type View
Constants ¶
This section is empty.
Variables ¶
var ( // current fullnode set. ErrUnauthorizedAddress = errors.New("unauthorized address") // ErrStoppedEngine is returned if the engine is stopped ErrStoppedEngine = errors.New("stopped engine") // ErrStartedEngine is returned if the engine is already started ErrStartedEngine = errors.New("started engine") )
var DefaultConfig = &Config{ RequestTimeout: 10000, MaxTimeout: 60, BlockPeriod: 1, SpeakerPolicy: RoundRobin, Epoch: 30000, MinFunds: 1, MinBlocksEmptyMining: big.NewInt(20000000), }
Functions ¶
func CheckFullnodeSignature ¶
func GetSignatureAddress ¶
GetSignatureAddress gets the signer address from the signature
Types ¶
type Backend ¶
type Backend interface { // Address returns the owner's address Address() common.Address // Fullnodes returns the fullnode set Fullnodes(blockproposal BlockProposal) FullnodeSet // EventMux returns the event mux in backend EventMux() *event.TypeMux // Broadcast sends a message to all fullnodes (include self) Broadcast(fullnodeSet FullnodeSet, payload []byte) error // Gossip sends a message to all fullnodes (exclude self) Gossip(fullnodeSet FullnodeSet, payload []byte) error // Commit delivers an approved proposal to backend. // The delivered proposal will be put into blockchain. Commit(blockproposal BlockProposal, seals [][]byte) error // Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned, // the time difference of the proposal and current time is also returned. Verify(BlockProposal) (time.Duration, error) // Sign signs input data with the backend's private key Sign([]byte) ([]byte, error) // CheckSignature verifies the signature by checking if it's signed by // the given fullnode CheckSignature(data []byte, addr common.Address, sig []byte) error // LastBlockProposal retrieves latest committed proposal and the address of speaker LastBlockProposal() (BlockProposal, common.Address) // HasBlockProposal checks if the combination of the given hash and height matches any existing blocks HasBlockProposal(hash common.Hash, number *big.Int) bool // GetSpeaker returns the speaker of the given block height GetSpeaker(number uint64) common.Address // ParentFullnodes returns the fullnode set of the given proposal's parent block ParentFullnodes(proposal BlockProposal) FullnodeSet // HasBadBlock returns whether the block with the hash is a bad block HasBadBlockProposal(hash common.Hash) bool Close() error }
Backend provides application specific functions for Sport core
type BlockProposal ¶
type BlockProposal interface { // Number retrieves the sequence number of this proposal. Number() *big.Int // Hash retrieves the hash of this proposal. Hash() common.Hash EncodeRLP(w io.Writer) error DecodeRLP(s *rlp.Stream) error String() string }
BlockProposal supports retrieving height and serialized block to be used during Sport consensus.
type BlockProposalSelector ¶
type BlockProposalSelector func(FullnodeSet, common.Address, uint64) Fullnode
type Config ¶
type Config struct { RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Sport round in milliseconds MaxTimeout uint64 `toml:",omitempty"` // The Max Timeout for each Sport round in milliseconds BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second SpeakerPolicy SpeakerPolicy `toml:",omitempty"` // The policy for speaker selection Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes DataDir string `toml:",omitempty"` // The default datadir for permissioned-nodes.json file MinFunds int64 `toml:",omitempty"` // The minimum funds a node should have to be a full node CommunityAddress string `toml:",omitempty"` // The community address for miner donations MinBlocksEmptyMining *big.Int `toml:",omitempty"` // Min Blocks to mine before Stop Mining Empty Blocks }
type FinalCommittedEvent ¶
type FinalCommittedEvent struct { }
FinalCommittedEvent is posted when a proposal is committed
type FullnodeSet ¶
type FullnodeSet interface { // Calculate the speaker CalcSpeaker(lastSpeaker common.Address, round uint64) // Return the fullnode size Size() int // Return the fullnode array List() []Fullnode // Get fullnode by index GetByIndex(i uint64) Fullnode // Get fullnode by given address GetByAddress(addr common.Address) (int, Fullnode) // Get current speaker GetSpeaker() Fullnode // Check whether the fullnode with given address is a speaker IsSpeaker(address common.Address) bool // Add fullnode AddFullnode(address common.Address) bool // Remove fullnode RemoveFullnode(address common.Address) bool // Copy fullnode set Copy() FullnodeSet // Get the maximum number of faulty nodes MaxFaulty() int // Minimum nodes to approve on Consensus MinApprovers() int // Get the extra number of faulty nodes E() int // Get speaker policy Policy() SpeakerPolicy }
type MessageEvent ¶
type MessageEvent struct {
Payload []byte
}
MessageEvent is posted for Sport engine communication
type Preprepare ¶
type Preprepare struct { View *View BlockProposal BlockProposal }
type Request ¶
type Request struct {
BlockProposal BlockProposal
}
type RequestEvent ¶
type RequestEvent struct {
BlockProposal BlockProposal
}
RequestEvent is posted to propose a proposal
type Subject ¶
func (*Subject) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.
type View ¶
View includes a round number and a sequence number. Sequence is the block number we'd like to commit. Each round has a number and is composed by 3 steps: preprepare, prepare and commit.
If the given block is not accepted by fullnodes, a round change will occur and the fullnodes start a new round with round+1.
func (*View) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.