consensus

package
v0.0.0-...-8f649d9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Eth62 = 62
	Eth63 = 63
)

Constants to match up protocol versions and messages

Variables

View Source
var (
	// ErrUnknownAncestor is returned when validating a block requires an ancestor
	// that is unknown.
	ErrUnknownAncestor = errors.New("unknown ancestor")

	// ErrPrunedAncestor is returned when validating a block requires an ancestor
	// that is known, but the state of which is not available.
	ErrPrunedAncestor = errors.New("pruned ancestor")

	// ErrFutureBlock is returned when a block's timestamp is in the future according
	// to the current node.
	ErrFutureBlock = errors.New("block in the future")

	// ErrInvalidNumber is returned if a block's number doesn't equal its parent's
	// plus one.
	ErrInvalidNumber = errors.New("invalid block number")
)
View Source
var (
	EthProtocol = Protocol{
		Name:     "eth",
		Versions: []uint{Eth62, Eth63},
		Lengths:  []uint64{17, 8},
	}
)

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster interface {
	// Enqueue add a block into fetcher queue
	Enqueue(id string, block *types.Block)
	// FindPeers retrives peers by addresses
	FindPeers(map[types.Address]bool) map[types.Address]Peer
}

Broadcaster defines the interface to enqueue blocks to fetcher and find peer

type ChainReader

type ChainReader interface {
	// Config retrieves the blockchain's chain configuration.
	Config() *chain.Params

	// Executor retrieves the blockchain's executor.
	Executor() *state.Executor

	// CurrentHeader retrieves the current header from the local chain.
	CurrentHeader() (*types.Header, bool)

	// GetHeader retrieves a block header from the database by hash and number.
	GetHeader(hash types.Hash, number uint64) (*types.Header, bool)

	// GetHeaderByNumber retrieves a block header from the database by number.
	GetHeaderByNumber(number uint64) (*types.Header, bool)

	// GetHeaderByHash retrieves a block header from the database by its hash.
	GetHeaderByHash(hash types.Hash) (*types.Header, bool)

	// GetBlock retrieves a block from the database by hash and number.
	GetBlock(hash types.Hash, number uint64, full bool) (*types.Block, bool)
}

ChainReader defines a small collection of methods needed to access the local blockchain during header and/or uncle verification.

type Config

type Config struct {
	// Logger to be used by the backend
	Logger *log.Logger

	// Params are the params of the chain and the consensus
	Params *chain.Params

	// Specific configuration parameters for the backend
	Config map[string]interface{}
}

Config is the configuration for the consensus

type Consensus

type Consensus interface {
	// VerifyHeader verifies the header is correct
	VerifyHeader(chain ChainReader, header *types.Header, uncle, seal bool) error

	//Prepare initializes the consensus fields of a block header according to the
	//rules of a particular engine. The changes are executed inline.
	Prepare(chain ChainReader, header *types.Header) error

	// Seal seals the block
	Seal(chain ChainReader, block *types.Block, ctx context.Context) (*types.Block, error)

	// Close closes the connection
	Close() error
}

Consensus is the interface for consensus

type Factory

type Factory func(context.Context, *Config, *ecdsa.PrivateKey, storage.Storage, hclog.Logger) (Consensus, error)

Factory is the factory function to create a discovery backend

type Handler

type Handler interface {
	// NewChainHead handles a new head block comes
	NewChainHead() error

	//HandleMsg handles a message from peer
	HandleMsg(address types.Address, data Msg) (bool, error)

	// SetBroadcaster sets the broadcaster to send message to peers
	SetBroadcaster(Broadcaster)
}

Handler should be implemented is the consensus needs to handle and send peer's message

type Istanbul

type Istanbul interface {
	Consensus

	// Start starts the engine
	Start(chain ChainReader, currentBlock func(bool) *types.Block, hasBadBlock func(hash types.Hash) bool) error

	// Stop stops the engine
	Stop() error
}

Istanbul is a consensus engine to avoid byzantine failure

type Msg

type Msg struct {
	Code    uint64
	Size    uint32
	Payload io.Reader
}

type NoProof

type NoProof struct {
}

NoProof is a consensus algorithm that validates everything

func (*NoProof) Close

func (n *NoProof) Close() error

Close closes the connection

func (*NoProof) Finalize

func (n *NoProof) Finalize(txn *state.Txn, block *types.Block) error

func (*NoProof) Prepare

func (n *NoProof) Prepare(chain ChainReader, header *types.Header) error

Prepare initializes the consensus fields of a block header according to the rules of a particular engine. The changes are executed inline.

func (*NoProof) Seal

func (n *NoProof) Seal(chain ChainReader, block *types.Block, ctx context.Context) (*types.Block, error)

Seal seals the block

func (*NoProof) VerifyHeader

func (n *NoProof) VerifyHeader(chain ChainReader, header *types.Header, uncle, seal bool) error

VerifyHeader verifies the header is correct

type Peer

type Peer interface {
	// Send sends the message to this peer
	Send(msgcode uint64, data interface{}) error
}

Peer defines the interface to communicate with peer

type Protocol

type Protocol struct {
	// Official short name of the protocol used during capability negotiation.
	Name string
	// Supported versions of the eth protocol (first is primary).
	Versions []uint
	// Number of implemented message corresponding to different protocol versions.
	Lengths []uint64
}

Protocol defines the protocol of the consensus

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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