consensus

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agreement

type Agreement interface {
	Commit(operation Operation) (ConsensusState, error)
	GetHeadState() (ConsensusState, error)
	Rollback(state ConsensusState) error
}

agree on a operation that update the consensus state

type Block

type Block interface {
	Decidable
	Parent() *hash.Hash
	Verify() error
	Bytes() []byte
	Height() uint64
	Timestamp() time.Time
	Transactions() []model.Tx
}

type BlockChainConsensue

type BlockChainConsensue interface {

	// VerifySeal checks whether the crypto seal on a header is valid according to
	// the consensus rules of the given engine.
	Verify(chain model.BlockChain, header BlockHeader) 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 model.BlockChain, header BlockHeader) error

	// Finalize runs any post-transaction state modifications (e.g. block rewards)
	// and assembles the final block.
	// Note: The block header and state database might be updated to reflect any
	// consensus rules that happen at finalization (e.g. block rewards).
	Finalize() (Block, error)

	// Generates a new block for the given input block with the local miner's
	// seal place on top.
	Generate(chain model.BlockChain, block Block, stop <-chan struct{}) (Block, error)
}

the algorithm agnostic consensus engine.

type BlockDAG

type BlockDAG interface {
	DAG
}

type BlockHeader

type BlockHeader interface {
}

type ChainVM

type ChainVM interface {
	VM

	GetBlock(*hash.Hash) (Block, error)
	GetBlockByNumber(num uint64) (Block, error)

	BuildBlock([]model.Tx) (Block, error)

	ParseBlock([]byte) (Block, error)

	LastAccepted() (*hash.Hash, error)

	GetBalance(string) (int64, error)

	VerifyTx(tx model.Tx) (int64, error)
	VerifyTxSanity(tx model.Tx) error

	AddTxToMempool(tx *types.Transaction, local bool) (int64, error)

	GetTxsFromMempool() ([]*types.Transaction, []*hash.Hash, error)

	GetMempoolSize() int64

	RemoveTxFromMempool(tx *types.Transaction) error

	CheckConnectBlock(block Block) error

	ConnectBlock(block Block) (uint64, error)

	DisconnectBlock(block Block) (uint64, error)
	RewindTo(state model.BlockState) error

	ResetTemplate() error

	Genesis() *hash.Hash

	GetBlockIDByTxHash(txhash *hash.Hash) uint64

	GetCurStateRoot() common.Hash
	GetCurHeader() *etypes.Header
	BlockChain() *core.BlockChain
	ChainDatabase() ethdb.Database
	PrepareEnvironment(state model.BlockState) (*etypes.Header, error)

	HasTx(h *hash.Hash) bool
}

type Consensus

type Consensus interface {
	GetCurrentState() (ConsensusState, error)
	Commit(state ConsensusState) (ConsensusState, error)
	SetAlgorithm(algorithm ConsensusAlgorithm)
}

agree on a consensus state

type ConsensusAlgorithm

type ConsensusAlgorithm interface {
	SetState(state ConsensusState) (ConsensusState, error)
}

type ConsensusState

type ConsensusState interface {
}

Any ConsensusState

type Context

type Context interface {
	context.Context
	GetConfig() *config.Config
	GetTxPool() model.TxPool
	GetNotify() Notify
	GetConsensus() model.Consensus
}

type DAG

type DAG interface {
}

type Decidable

type Decidable interface {
	ID() *hash.Hash
	Accept() error
	Reject() error
	Status() Status
}

type Notify

type Notify interface {
	AnnounceNewTransactions(newTxs []*types.TxDesc, filters []peer.ID)
	RelayInventory(data interface{}, filters []peer.ID)
	BroadcastMessage(data interface{})
	TransactionConfirmed(tx *types.Tx)
	AddRebroadcastInventory(newTxs []*types.TxDesc)
}

Notify interface manage message announce & relay & notification between mempool, websocket, gbt long pull and rpc server.

type Operation

type Operation interface {
	ApplyTo(state ConsensusState) (ConsensusState, error)
}

type PoA

type PoA interface {
	BlockChainConsensue
}

type PoW

type PoW interface {
	BlockChainConsensue
	// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
	// that a new block should have.
	CalcDifficulty(chain model.BlockChain, time uint64, parent BlockHeader) *big.Int

	// Hashrate returns the current mining hashrate of a PoW consensus engine.
	Hashrate() float64
}

PoW is a consensus engine based on proof-of-work.

type Status

type Status byte
const (
	Unknown Status = iota
	Processing
	Rejected
	Accepted
)

func (Status) Bytes

func (s Status) Bytes() []byte

func (Status) Decided

func (s Status) Decided() bool

func (Status) Fetched

func (s Status) Fetched() bool

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

func (Status) Valid

func (s Status) Valid() error

type VM

type VM interface {
	GetID() string
	Initialize(ctx Context) error
	Bootstrapping() error
	Bootstrapped() error
	Shutdown() error
	Version() string
	RegisterAPIs(apis []api.API)
	SetLogLevel(level string)
}

Jump to

Keyboard shortcuts

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