consensus

package
v0.0.0-...-571fd38 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package consensus implements the PoWork consensus

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMsgRejected    = errors.New("message get rejected")
	ErrInvalidMsgType = errors.New("invalid message type")
)
View Source
var ErrChainOnSyncing = errors.New("chain is syncing")

Functions

This section is empty.

Types

type Consensus

type Consensus interface {
	Loop()
	GetCurrentState() (State, error)
	CommitState(State) (State, error)
}

Consensus is an abstract consensus interface.

type Op

type Op interface{}

Op is an abstract operation interface.

type OpBatch

type OpBatch interface {
	ToUnsealing(...Op) error
}

OpBatch is an abstract OpBatch interface.

type PoWork

type PoWork struct {
	PoWorkConfig

	SyncMod *syncModule

	Chain     *blockchain.Chain
	Pool      *ngpool.TxPool
	State     *ngstate.State
	LocalNode *ngp2p.LocalNode
	// contains filtered or unexported fields
}

PoWork is a proof on work consensus manager.

func InitPoWConsensus

func InitPoWConsensus(db *badger.DB, chain *blockchain.Chain, pool *ngpool.TxPool, state *ngstate.State, localNode *ngp2p.LocalNode, config PoWorkConfig) *PoWork

InitPoWConsensus creates and initializes the PoW consensus.

func (*PoWork) GetBlockTemplate

func (pow *PoWork) GetBlockTemplate(privateKey *secp256k1.PrivateKey) *ngtypes.Block

GetBlockTemplate is a generator of new block. But the generated block has no nonce.

func (*PoWork) GoLoop

func (pow *PoWork) GoLoop()

GoLoop ignites all loops.

func (*PoWork) ImportBlock

func (pow *PoWork) ImportBlock(block *ngtypes.Block) error

func (*PoWork) MinedNewBlock

func (pow *PoWork) MinedNewBlock(block *ngtypes.Block) error

MinedNewBlock means the local (from rpc) mined new block and need to add it into the chain. called by submitBlock and submitWork

type PoWorkConfig

type PoWorkConfig struct {
	Network                     ngtypes.Network
	StrictMode                  bool
	SnapshotMode                bool
	DisableConnectingBootstraps bool
}

type RemoteRecord

type RemoteRecord struct {
	// contains filtered or unexported fields
}

func NewRemoteRecord

func NewRemoteRecord(id peer.ID, origin, latest uint64, checkpointHash, checkpointActualDiff []byte) *RemoteRecord

type State

type State interface {
	CommitOp() (State, error)
}

State is an abstract state interface.

Jump to

Keyboard shortcuts

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