middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 21 Imported by: 0

README

BlockValidation

  1. Verify header

CsBFT does not modify data when verifying state roots and registering roots SaveBlock confirms data and save data when verifying status root and registration root

completeness rate block type consensus method
complete both block configuration correct:version ID,chain ID, etc ValidateBlockVersion
complete both verify continuum of block height ValidateBlockNumber
complete both verify correctness of block hash ValidateBlockHash
complete both verify block size smaller than default maximum ValidateBlockSize
complete normal block verify block difficulty meets the need ValidateBlockDifficulty
complete normal block verify block hash satisfies the difficulty ValidHashForDifficulty
complete both verify correctness of block seed ValidateSeed
complete special block verify the address of the miner of the block is boot node ValidateBlockCoinBase
complete both verify vote root hash validVerificationRoot
complete both verify transaction root hash ValidateBlockTxs
complete both verify state root hash validStateRoot
complete both verify registration root hash validBlockVerifier
incomplete both verify interlink root hash ???
  1. Verify votes

When CsBFT verifies the vote, it only needs to verify the verification in the body. The object is the last block. When SaveBlock verifies the vote, you need to verify the two sets of votes, except for verification, the other group is see commit, and the object is the current block.

completeness rate block type consensus method
complete normal block check at least 2/3 of verifiers vote validVotesForBlock
complete special block check there is angel node who has voted validVotesForBlock
complete special block check vote type is correct HaltedVoteValid
complete both verify there is no repeated vote sameVote
complete both check the voter is the current verifier verificationSignerInVerifiers
complete both verify the correctness of signature of verifiers ver.Valid()
complete both verify the correctness of verifiers validVotesForBlock
  1. Verify Txs
completeness rate block type consensus method
complete special block verify transaction list of the special block is empty ValidateBlockTxs
complete normal block verify the correctness of signature of transactions ValidateBlockTxs
complete normal block verify transactions of all types meet the need of safety txValidators
complete normal block verify the sender's balance is sufficient ValidTxSender
complete normal block verify the size of each transaction is smaller than the default maximal value ValidTxSize

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidSateRootForTest

func ValidSateRootForTest(preStateRoot common.Hash, economyModel economy_model.EconomyModel, blockProcess BlockProcessor, processBlock model.AbstractBlock) error

func ValidTxSender

func ValidTxSender(tx model.AbstractTransaction, chain ChainInterface, blockHeight uint64) error

valid sender and amount

func ValidTxSize

func ValidTxSize(tx model.AbstractTransaction) error

Types

type BftBlockContext

type BftBlockContext struct {
	BlockContext

	Votes []model.AbstractVerification
}

type BftBlockContextWithoutVotes

type BftBlockContextWithoutVotes struct {
	BlockContext
}

type BftBlockValidator

type BftBlockValidator struct {
	Chain ChainInterface
}

func NewBftBlockValidator

func NewBftBlockValidator(chain ChainInterface) *BftBlockValidator

func (*BftBlockValidator) FullValid

func (v *BftBlockValidator) FullValid(b model.AbstractBlock) error

func (*BftBlockValidator) Valid

type BlockContext

type BlockContext struct {
	MiddlewareContext

	// the block to be handled
	Block model.AbstractBlock
	// chain
	Chain ChainInterface
}

visit chain, db, state_root through processor

func NewBlockContext

func NewBlockContext(block model.AbstractBlock, chain ChainInterface) *BlockContext

type BlockProcessor

type BlockProcessor func(root common.Hash) (*chain.BlockProcessor, error)

type ChainHelper

type ChainHelper interface {
	GetChainConfig() *chain_config.ChainConfig
	GetEconomyModel() economy_model.EconomyModel
	GetChainDB() chaindb.Database
}

type Middleware

type Middleware func() error

func InsertBlock

func InsertBlock(c *BlockContext) Middleware

func NextRoundVerifier

func NextRoundVerifier(c *BlockContext) Middleware

func UpdateBlockVerifier

func UpdateBlockVerifier(c *BlockContext) Middleware

func UpdateStateRoot

func UpdateStateRoot(c *BlockContext) Middleware

func ValidBlockVerifier

func ValidBlockVerifier(c *BlockContext) Middleware

func ValidStateRoot

func ValidStateRoot(c *BlockContext) Middleware

func ValidTxByType

func ValidTxByType(tx model.AbstractTransaction, chain ChainInterface, blockHeight uint64) Middleware

do checking for different types of transactions

func ValidateBlockCoinBase

func ValidateBlockCoinBase(c *BlockContext) Middleware

func ValidateBlockDifficulty

func ValidateBlockDifficulty(c *BlockContext) Middleware

func ValidateBlockHash

func ValidateBlockHash(c *BlockContext) Middleware

func ValidateBlockNumber

func ValidateBlockNumber(c *BlockContext) Middleware

validate_block typical usage: bc := InitBlockContext(block) m := &BlockProcessor{bc, chain} m.Use(ValidateBlockNumber(bc), ValidateBlockDifficulty(bc), ValidateBlockTxs(bc), ) m.Use(VrfCheckCommits(bc), ) m.Use(UpdateState(bc)) m.Use(InsertBlock(bc))

func ValidateBlockSize

func ValidateBlockSize(c *BlockContext) Middleware

func ValidateBlockTime

func ValidateBlockTime(c *BlockContext) Middleware

func ValidateBlockTxs

func ValidateBlockTxs(c *BlockContext) Middleware

func ValidateBlockVersion

func ValidateBlockVersion(c *BlockContext) Middleware

func ValidateSeed

func ValidateSeed(c *BlockContext) Middleware

func ValidateVotes

func ValidateVotes(c *BftBlockContext) Middleware

SaveBlock use

func ValidateVotesForBFT

func ValidateVotesForBFT(c *BlockContext) Middleware

BFT use

type MiddlewareChain

type MiddlewareChain []Middleware

func (MiddlewareChain) Last

func (c MiddlewareChain) Last() Middleware

type MiddlewareContext

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

basic middleware, can be comprised by other middleware

func (*MiddlewareContext) Middleware

func (mc *MiddlewareContext) Middleware() Middleware

func (*MiddlewareContext) Next

func (mc *MiddlewareContext) Next() error

the core function of middleware, called only once after the registration of each middleware

func (*MiddlewareContext) Process

func (mc *MiddlewareContext) Process(m ...Middleware) error

func (*MiddlewareContext) Use

func (mc *MiddlewareContext) Use(m ...Middleware)

type StateHelper

type StateHelper interface {
	GetStateStorage() state_processor.StateStorage
	CurrentState() (*state_processor.AccountStateDB, error)
	StateAtByBlockNumber(num uint64) (*state_processor.AccountStateDB, error)
	StateAtByStateRoot(root common.Hash) (*state_processor.AccountStateDB, error)
	BuildStateProcessor(preAccountStateRoot common.Hash) (*state_processor.AccountStateDB, error)
}

type StateReader

type StateReader interface {
	Genesis() model.AbstractBlock
	CurrentBlock() model.AbstractBlock
	CurrentHeader() model.AbstractHeader
	GetBlock(hash common.Hash, number uint64) model.AbstractBlock
	GetBlockByHash(hash common.Hash) model.AbstractBlock
	GetBlockByNumber(number uint64) model.AbstractBlock
	HasBlock(hash common.Hash, number uint64) bool
	GetBody(hash common.Hash) model.AbstractBody
	GetBodyRLP(hash common.Hash) rlp.RawValue
	GetHeader(hash common.Hash, number uint64) model.AbstractHeader
	GetHeaderByHash(hash common.Hash) model.AbstractHeader
	GetHeaderByNumber(number uint64) model.AbstractHeader
	GetHeaderRLP(hash common.Hash) rlp.RawValue
	HasHeader(hash common.Hash, number uint64) bool
	GetBlockNumber(hash common.Hash) *uint64
	GetTransaction(txHash common.Hash) (model.AbstractTransaction, common.Hash, uint64, uint64)

	GetLatestNormalBlock() model.AbstractBlock

	BlockProcessor(root common.Hash) (*chain.BlockProcessor, error)
	BlockProcessorByNumber(num uint64) (*chain.BlockProcessor, error)
}

type StateWriter

type StateWriter interface {
	Rollback(target uint64) error
}

type TxValidatorForRpcService

type TxValidatorForRpcService struct {
	Chain ChainInterface
}

func NewTxValidatorForRpcService

func NewTxValidatorForRpcService(chain ChainInterface) *TxValidatorForRpcService

NewValidatorTx create a validator for transactions

func (*TxValidatorForRpcService) Valid

Valid valid transactions

type VerifierHelper

type VerifierHelper interface {
	CurrentSeed() (common.Hash, uint64)
	IsChangePoint(block model.AbstractBlock, isProcessPackageBlock bool) bool
	GetLastChangePoint(block model.AbstractBlock) *uint64
	GetSlotByNum(num uint64) *uint64
	GetSlot(block model.AbstractBlock) *uint64
	GetCurrVerifiers() []common.Address
	GetVerifiers(round uint64) []common.Address
	GetNextVerifiers() []common.Address
	NumBeforeLastBySlot(slot uint64) *uint64
	BuildRegisterProcessor(preRoot common.Hash) (*registerdb.RegisterDB, error)
}

Jump to

Keyboard shortcuts

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