sport

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorizedAddress is returned when given address cannot be found in
	// 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")
)
View Source
var DefaultConfig = &Config{
	RequestTimeout:       10000,
	MaxTimeout:           60,
	BlockPeriod:          1,
	SpeakerPolicy:        RoundRobin,
	Epoch:                30000,
	MinFunds:             1,
	MinBlocksEmptyMining: big.NewInt(20000000),
}

Functions

func CheckFullnodeSignature

func CheckFullnodeSignature(fullnodeSet FullnodeSet, data []byte, sig []byte) (common.Address, error)

func GetSignatureAddress

func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)

GetSignatureAddress gets the signer address from the signature

func RLPHash

func RLPHash(v interface{}) (h common.Hash)

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 Fullnode

type Fullnode interface {
	// Address returns address
	Address() common.Address

	// String representation of Fullnode
	String() string
}

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 Fullnodes

type Fullnodes []Fullnode

func (Fullnodes) Len

func (slice Fullnodes) Len() int

func (Fullnodes) Less

func (slice Fullnodes) Less(i, j int) bool

func (Fullnodes) Swap

func (slice Fullnodes) Swap(i, j int)

type MessageEvent

type MessageEvent struct {
	Payload []byte
}

MessageEvent is posted for Sport engine communication

type Preprepare

type Preprepare struct {
	View          *View
	BlockProposal BlockProposal
}

func (*Preprepare) DecodeRLP

func (b *Preprepare) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Preprepare) EncodeRLP

func (b *Preprepare) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

type Request

type Request struct {
	BlockProposal BlockProposal
}

type RequestEvent

type RequestEvent struct {
	BlockProposal BlockProposal
}

RequestEvent is posted to propose a proposal

type SpeakerPolicy

type SpeakerPolicy uint64
const (
	RoundRobin SpeakerPolicy = iota
)

type Subject

type Subject struct {
	View   *View
	Digest common.Hash
}

func (*Subject) DecodeRLP

func (b *Subject) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Subject) EncodeRLP

func (b *Subject) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*Subject) String

func (b *Subject) String() string

type View

type View struct {
	Round    *big.Int
	Sequence *big.Int
}

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

func (v *View) Cmp(y *View) int

Cmp compares v and y and returns:

-1 if v <  y
 0 if v == y
+1 if v >  y

func (*View) DecodeRLP

func (v *View) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*View) EncodeRLP

func (v *View) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*View) String

func (v *View) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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