consensus

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: ISC Imports: 10 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() []Tx
}

type BlockChain

type BlockChain interface {
}

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 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 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 BlockChain, block Block, stop <-chan struct{}) (Block, error)
}

the algorithm agnostic consensus engine.

type BlockDAG

type BlockDAG interface {
	DAG
	GetBlock(h *hash.Hash) meerdag.IBlock
}

type BlockHeader

type BlockHeader interface {
}

type ChainVM

type ChainVM interface {
	VM

	GetBlock(*hash.Hash) (Block, error)

	BuildBlock([]Tx) (Block, error)

	ParseBlock([]byte) (Block, error)

	LastAccepted() (*hash.Hash, error)

	GetBalance(string) (int64, error)

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

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

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

	GetMempoolSize() int64

	RemoveTxFromMempool(tx *types.Transaction) error

	CheckConnectBlock(block Block) error

	ConnectBlock(block Block) error

	DisconnectBlock(block Block) error

	ResetTemplate() error

	Genesis() *hash.Hash
}

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() TxPool
	GetNotify() Notify
}

type DAG

type DAG interface {
}

type Decidable

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

type FeeEstimator

type FeeEstimator interface {
	RegisterBlock(block *types.SerializedBlock) error
	Rollback(hash *hash.Hash) error
}

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 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 Tx

type Tx interface {
	GetTxType() types.TxType
	GetFrom() string
	GetTo() string
	GetValue() uint64
	GetData() []byte
}

type TxPool

type TxPool interface {
	RemoveTransaction(tx *types.Tx, removeRedeemers bool)

	RemoveDoubleSpends(tx *types.Tx)

	RemoveOrphan(txHash *hash.Hash)

	ProcessOrphans(hash *hash.Hash) []*types.TxDesc

	MaybeAcceptTransaction(tx *types.Tx, isNew, rateLimit bool) ([]*hash.Hash, error)

	HaveTransaction(hash *hash.Hash) bool

	PruneExpiredTx()

	ProcessTransaction(tx *types.Tx, allowOrphan, rateLimit, allowHighFees bool) ([]*types.TxDesc, error)

	GetMainHeight() int64

	AddTransaction(tx *types.Tx, height uint64, fee int64)

	IsSupportVMTx() bool
}

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