common

package
v0.0.0-...-bda353b Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULTDURATION = 1000 // default proposal duration, millis seconds
	//blockSig:%d,vm:%d,txVerify:%d,txRoot:%d
	BlockSig            = "blockSig"
	VM                  = "vm"
	TxVerify            = "txVerify"
	TxRoot              = "txRoot"
	QuickSyncVerifyMode = uint8(1) // quick sync verify mode
	NormalVerifyMode    = uint8(0) // normal verify mode
	DEFAULTTIMEOUT      = 5000
)
View Source
const LOCKED = "LOCKED" // LOCKED mark

Variables

View Source
var (
	ProposeRepeatTimerMap sync.Map
)
View Source
var TxPoolType string

Functions

func CheckBlockDigests

func CheckBlockDigests(block *commonPb.Block, txHashes [][]byte, hashType string, log protocol.Logger) error

func CheckPreBlock

func CheckPreBlock(block *commonPb.Block, lastBlock *commonPb.Block,
	err error, lastBlockHash []byte, proposedHeight uint64) error

nolint: staticcheck

func CheckVacuumBlock

func CheckVacuumBlock(block *commonPb.Block, consensusType consensus.ConsensusType) error

func ClearProposeRepeatTimerMap

func ClearProposeRepeatTimerMap()

func DeserializeTxBatchInfo

func DeserializeTxBatchInfo(data []byte) (*commonPb.TxBatchInfo, error)

func FinalizeBlock

func FinalizeBlock(
	block *commonPb.Block,
	txRWSetMap map[string]*commonPb.TxRWSet,
	aclFailTxs []*commonPb.Transaction,
	hashType string,
	logger protocol.Logger) error

func GetBatchIds

func GetBatchIds(block *commonpb.Block) ([]string, []uint32, error)

func GetProposerId

func GetProposerId(
	ac protocol.AccessControlProvider,
	netService protocol.NetService,
	proposer *accesscontrol.Participant) (string, error)

func GetTurboBlock

func GetTurboBlock(block, turboBlock *commonPb.Block, logger protocol.Logger) *commonPb.Block

func IfExitInSameBranch

func IfExitInSameBranch(height uint64, txId string, proposalCache protocol.ProposalCache, preBlockHash []byte) (
	bool, error)

判断相同分支上是否存在交易重复(防止双花)

func IfOpenConsensusMessageTurbo

func IfOpenConsensusMessageTurbo(chainConf protocol.ChainConf) bool

func IntegersContains

func IntegersContains(array []int, val int) bool

func IsBlockHashValid

func IsBlockHashValid(block *commonPb.Block, hashType string) error

IsBlockHashValid to check if block hash equals with result calculated from block

func IsDagHashValid

func IsDagHashValid(block *commonPb.Block, hashType string) error

IsDagHashValid to check if block dag equals with simulated block dag

func IsHeightValid

func IsHeightValid(block *commonPb.Block, currentHeight uint64) error

IsHeightValid to check if block height is valid

func IsMerkleRootValid

func IsMerkleRootValid(block *commonPb.Block, txHashes [][]byte, hashType string) error

IsMerkleRootValid to check if block merkle root equals with simulated merkle root

func IsPreHashValid

func IsPreHashValid(block *commonPb.Block, preHash []byte) error

IsPreHashValid to check if block.preHash equals with last block hash

func IsRWSetHashValid

func IsRWSetHashValid(block *commonPb.Block, hashType string) error

IsRWSetHashValid to check if read write set is valid

func IsTxCountValid

func IsTxCountValid(block *commonPb.Block) error

IsTxCountValid to check if txcount in block is valid

func IsTxDuplicate

func IsTxDuplicate(txs []*commonPb.Transaction) (duplicate bool, duplicateTxs []string)

IsTxDuplicate to check if there is duplicated transactions in one block

func IsTxRWSetValid

func IsTxRWSetValid(block *commonpb.Block, tx *commonpb.Transaction, rwSet *commonpb.TxRWSet, result *commonpb.Result,
	rwsetHash []byte) error

IsTxRWSetValid, to check if transaction read write set is valid

func IsTxRequestValid

func IsTxRequestValid(tx *commonpb.Transaction, txInPool *commonpb.Transaction) error

IsTxRequestValid, to check if transaction request payload is valid

func NotifyChainConf

func NotifyChainConf(block *commonpb.Block, chainConf protocol.ChainConf) (err error)

NotifyChainConf Notify each module of callback before version v2.3.0

func RecoverBlock

func RecoverBlock(
	block *commonPb.Block,
	mode protocol.VerifyMode,
	chainConf protocol.ChainConf,
	txPool protocol.TxPool,
	ac protocol.AccessControlProvider,
	netService protocol.NetService,
	logger protocol.Logger) (*commonPb.Block, []string, error)

func RetryAndRemoveTxs

func RetryAndRemoveTxs(
	txPool protocol.TxPool,
	txsRetry []*commonPb.Transaction,
	txsRem []*commonPb.Transaction,
	log protocol.Logger)

RetryAndRemoveTxs filter charging gas tx out before call tx pool

func SerializeTxBatchInfo

func SerializeTxBatchInfo(batchIds []string, txs []*commonPb.Transaction,
	fetchBatches [][]*commonPb.Transaction, logger protocol.Logger) ([]byte, error)

func TxVerifyResultsMerge

func TxVerifyResultsMerge(resultTasks map[int]VerifyBlockBatch,
	verifyBatchs map[int][]*commonpb.Transaction) ([][]byte, []*commonpb.Transaction, error)

func ValidateTx

func ValidateTx(txsRet map[string]*commonpb.Transaction, tx *commonpb.Transaction,
	stat *VerifyStat, newAddTxs []*commonpb.Transaction, block *commonpb.Block,
	consensusType consensuspb.ConsensusType, filter protocol.TxFilter,
	chainId string, ac protocol.AccessControlProvider, proposalCache protocol.ProposalCache,
	mode protocol.VerifyMode, verifyMode uint8, options ...string) error

func ValidateTxRules

func ValidateTxRules(filter protocol.TxFilter, txs []*commonpb.Transaction) (
	removeTxs []*commonpb.Transaction, remainTxs []*commonpb.Transaction)

ValidateTxRules validate Transactions and return remain Transactions and Transactions that need to be removed

func VerifyHeight

func VerifyHeight(height uint64, ledgerCache protocol.LedgerCache) error

func VerifyTxResult

func VerifyTxResult(tx *commonpb.Transaction, result *commonpb.Result) error

VerifyTxResult, to check if transaction result is valid, compare result simulate in this node with executed in other node

Types

type BlockBuilder

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

func NewBlockBuilder

func NewBlockBuilder(conf *BlockBuilderConf) *BlockBuilder

func (*BlockBuilder) GenerateNewBlock

func (bb *BlockBuilder) GenerateNewBlock(
	proposingHeight uint64, preHash []byte, txBatch []*commonPb.Transaction,
	batchIds []string, fetchBatches [][]*commonPb.Transaction) (
	*commonPb.Block, []int64, error)

type BlockBuilderConf

type BlockBuilderConf struct {
	ChainId         string                      // chain id, to identity this chain
	TxPool          protocol.TxPool             // tx pool provides tx batch
	TxScheduler     protocol.TxScheduler        // scheduler orders tx batch into DAG form and returns a block
	SnapshotManager protocol.SnapshotManager    // snapshot manager
	Identity        protocol.SigningParticipant // identity manager
	LedgerCache     protocol.LedgerCache        // ledger cache
	ProposalCache   protocol.ProposalCache
	ChainConf       protocol.ChainConf // chain config
	Log             protocol.Logger
	StoreHelper     conf.StoreHelper
}

type BlockCommitterConfig

type BlockCommitterConfig struct {
	ChainId         string
	BlockchainStore protocol.BlockchainStore
	SnapshotManager protocol.SnapshotManager
	TxPool          protocol.TxPool
	LedgerCache     protocol.LedgerCache
	ProposedCache   protocol.ProposalCache
	ChainConf       protocol.ChainConf
	MsgBus          msgbus.MessageBus
	Subscriber      *subscriber.EventSubscriber
	Verifier        protocol.BlockVerifier
	StoreHelper     conf.StoreHelper
	TxFilter        protocol.TxFilter
}

type BlockCommitterImpl

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

BlockCommitterImpl implements BlockCommitter interface. To commit a block after it is confirmed by consensus module.

func (*BlockCommitterImpl) AddBlock

func (chain *BlockCommitterImpl) AddBlock(block *commonPb.Block) (err error)

type CommitBlock

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

func (*CommitBlock) CommitBlock

func (cb *CommitBlock) CommitBlock(
	block *commonpb.Block,
	rwSetMap map[string]*commonpb.TxRWSet,
	conEventMap map[string][]*commonpb.ContractEvent) (
	dbLasts, snapshotLasts, confLasts, otherLasts, pubEventLasts, filterLasts int64, blockInfo *commonpb.BlockInfo,
	err error)

CommitBlock the action that all consensus types do when a block is committed

func (*CommitBlock) NotifyMessage

func (cb *CommitBlock) NotifyMessage(block *commonpb.Block, events []*commonpb.ContractEvent) (err error)

NotifyMessage Notify other subscription modules of chain configuration and certificate management events

type KVStoreHelper

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

func NewKVStoreHelper

func NewKVStoreHelper(chainId string) *KVStoreHelper

func (*KVStoreHelper) BeginDbTransaction

func (kv *KVStoreHelper) BeginDbTransaction(blockchainStore protocol.BlockchainStore, txKey string)

KVDB do nothing

func (*KVStoreHelper) GetPoolCapacity

func (kv *KVStoreHelper) GetPoolCapacity() int

func (*KVStoreHelper) RollBack

func (kv *KVStoreHelper) RollBack(block *commonpb.Block, blockchainStore protocol.BlockchainStore) error

KVDB do nothing

type ReentrantLocks

type ReentrantLocks struct {
	ReentrantLocks map[string]interface{}
	Mu             sync.Mutex
}

reentrantLocks, avoid the same block hash

func (*ReentrantLocks) Lock

func (l *ReentrantLocks) Lock(key string) bool

func (*ReentrantLocks) Unlock

func (l *ReentrantLocks) Unlock(key string) bool

type RwSetVerifyFailTx

type RwSetVerifyFailTx struct {
	TxIds       []string
	BlockHeight uint64
}

type SQLStoreHelper

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

func NewSQLStoreHelper

func NewSQLStoreHelper(chainId string) *SQLStoreHelper

func (*SQLStoreHelper) BeginDbTransaction

func (sql *SQLStoreHelper) BeginDbTransaction(blockchainStore protocol.BlockchainStore, txKey string)

func (*SQLStoreHelper) GetPoolCapacity

func (sql *SQLStoreHelper) GetPoolCapacity() int

func (*SQLStoreHelper) RollBack

func (sql *SQLStoreHelper) RollBack(block *commonpb.Block, blockchainStore protocol.BlockchainStore) error

type VerifierBlock

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

func NewVerifierBlock

func NewVerifierBlock(conf *VerifierBlockConf) *VerifierBlock

func (*VerifierBlock) FetchLastBlock

func (vb *VerifierBlock) FetchLastBlock(block *commonPb.Block) (*commonPb.Block, error)

func (*VerifierBlock) SetTxScheduler

func (v *VerifierBlock) SetTxScheduler(txScheduler protocol.TxScheduler)

SetTxScheduler sets the txScheduler of VerifierBlock only used for test

func (*VerifierBlock) ValidateBlock

func (vb *VerifierBlock) ValidateBlock(
	block, lastBlock *commonPb.Block, hashType string, timeLasts map[string]int64, mode protocol.VerifyMode) (
	map[string]*commonPb.TxRWSet, map[string][]*commonPb.ContractEvent, map[string]int64, *RwSetVerifyFailTx, error)

validateBlock, validate block and transactions

func (*VerifierBlock) ValidateBlockWithRWSets

func (vb *VerifierBlock) ValidateBlockWithRWSets(
	block, lastBlock *commonPb.Block, hashType string, timeLasts map[string]int64,
	txRWSetMap map[string]*commonPb.TxRWSet, mode protocol.VerifyMode) (
	map[string][]*commonPb.ContractEvent, map[string]int64, *RwSetVerifyFailTx, error)

validateBlock, validate block and transactions

type VerifierBlockConf

type VerifierBlockConf struct {
	ChainConf       protocol.ChainConf
	Log             protocol.Logger
	LedgerCache     protocol.LedgerCache
	Ac              protocol.AccessControlProvider
	SnapshotManager protocol.SnapshotManager
	VmMgr           protocol.VmManager
	TxPool          protocol.TxPool
	BlockchainStore protocol.BlockchainStore
	ProposalCache   protocol.ProposalCache // proposal cache
	StoreHelper     conf.StoreHelper
	TxScheduler     protocol.TxScheduler
	TxFilter        protocol.TxFilter
}

type VerifierTx

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

func NewVerifierTx

func NewVerifierTx(conf *VerifierTxConfig) *VerifierTx

type VerifierTxConfig

type VerifierTxConfig struct {
	Block         *commonpb.Block
	TxRWSetMap    map[string]*commonpb.TxRWSet
	TxResultMap   map[string]*commonpb.Result
	Log           protocol.Logger
	TxFilter      protocol.TxFilter
	TxPool        protocol.TxPool
	Ac            protocol.AccessControlProvider
	ChainConf     protocol.ChainConf
	ProposalCache protocol.ProposalCache
}

type VerifyBlockBatch

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

func NewVerifyBlockBatch

func NewVerifyBlockBatch(txs, newAddTxs []*commonpb.Transaction, txHash [][]byte) VerifyBlockBatch

type VerifyStat

type VerifyStat struct {
	TotalCount  int
	DBLasts     int64
	SigLasts    int64
	OthersLasts int64
	SigCount    int
	txfilter.Stat
}

verifyStat, statistic for verify steps

func (*VerifyStat) Sum

func (stat *VerifyStat) Sum(filter *txfilter.Stat)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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