consensus

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBlock

func BuildBlock(params BuildBlockParams) *types.Block

BuildBlock is a utility function that builds a block, based on the passed in header, transactions and receipts

func MilliToUnix

func MilliToUnix(m uint64) time.Time

MilliToUnix returns the local Time corresponding to the given Unix time m milliseconds since January 1, 1970 UTC.

func UnixToMilli

func UnixToMilli(t time.Time) uint64

UnixToMilli returns uint64 value for miliseconds

Types

type BuildBlockParams

type BuildBlockParams struct {
	Header   *types.Header
	Txns     []*types.Transaction
	Receipts []*types.Receipt
}

BuildBlockParams are parameters passed into the BuildBlock helper method

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

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

	// Path is the directory path for the consensus protocol tos tore information
	Path string
}

Config is the configuration for the consensus

type Consensus

type Consensus interface {
	// VerifyHeader verifies the header is correct
	VerifyHeader(parent, header *types.Header) error

	// GetBlockCreator retrieves the block creator (or signer) given the block header
	GetBlockCreator(header *types.Header) (types.Address, error)

	// GetSyncProgression retrieves the current sync progression, if any
	GetSyncProgression() *progress.Progression

	// Initialize initializes the consensus (e.g. setup data)
	Initialize() error

	// Start starts the consensus and servers
	Start() error

	// Close closes the connection
	Close() error
}

Consensus is the public interface for consensus mechanism Each consensus mechanism must implement this interface in order to be valid

type ConsensusParams

type ConsensusParams struct {
	Context        context.Context
	Seal           bool
	Config         *Config
	Txpool         *txpool.TxPool
	Network        *network.Server
	Blockchain     *blockchain.Blockchain
	Executor       *state.Executor
	Grpc           *grpc.Server
	Logger         hclog.Logger
	Metrics        *Metrics
	SecretsManager secrets.SecretsManager
	BlockTime      uint64 // block time im miliseconds
}

type Factory

type Factory func(
	*ConsensusParams,
) (Consensus, error)

Factory is the factory function to create a discovery backend

type Metrics

type Metrics struct {
	// No.of validators
	Validators metrics.Gauge
	// No.of rounds
	Rounds metrics.Gauge
	// No.of transactions in the block
	NumTxs metrics.Gauge

	//Time between current block and the previous block in seconds
	BlockInterval metrics.Gauge
}

Metrics represents the consensus metrics

func GetPrometheusMetrics

func GetPrometheusMetrics(namespace string, labelsWithValues ...string) *Metrics

GetPrometheusMetrics return the consensus metrics instance

func NilMetrics

func NilMetrics() *Metrics

NilMetrics will return the non operational metrics

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(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(block *types.Block, ctx context.Context) (*types.Block, error)

Seal seals the block

func (*NoProof) VerifyHeader

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

VerifyHeader verifies the header is correct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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