Version: v0.0.0-...-8d08d5c Latest Latest

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

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



Package consensus implements the PoWork consensus



This section is empty.


This section is empty.


This section is empty.


type Consensus

type Consensus interface {
	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 {

	SyncMod  *syncModule
	MinerMod *miner.Miner

	Chain     *ngchain.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 *ngchain.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() *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 consensus mined new block and need to add it into the chain.

func (*PoWork) UpdateMiningThread

func (pow *PoWork) UpdateMiningThread(newThreadNum int)

SwitchMiningOn resumes the pow consensus.

type PoWorkConfig

type PoWorkConfig struct {
	Network                     ngtypes.NetworkType
	DisableConnectingBootstraps bool
	MiningThread                int
	PrivateKey                  *secp256k1.PrivateKey

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


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to