func (p *StateProcessor) ProcessTxs(block *types.Block, statedb *state.StateDB, cfg vm.Config, upTime map[common.Address]uint64) (types.Receipts, []*types.Log, uint64, error) {
	var (
		receipts types.Receipts
		usedGas  = new(uint64)
		header   = block.Header()
		allLogs  []*types.Log
		gp       = new(GasPool).AddGas(block.GasLimit())
	)
	// Mutate the the block and state according to any hard-fork specs
	if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
		misc.ApplyDAOHardFork(statedb)
	}
	// Iterate over and process the individual transactions
	statedb.UpdateTxForBtree(uint32(block.Time().Uint64()))
	statedb.UpdateTxForBtreeBytime(uint32(block.Time().Uint64()))
	stxs := make([]types.SelfTransaction, 0)
	var txcount int
	txs := block.Transactions()
	var waitG = &sync.WaitGroup{}
	maxProcs := runtime.NumCPU() //获取cpu个数
	if maxProcs >= 2 {
		runtime.GOMAXPROCS(maxProcs - 1) //限制同时运行的goroutines数量
	}
	normalTxindex := 0
	for _, tx := range txs {
		if tx.GetMatrixType() == common.ExtraUnGasMinerTxType || tx.GetMatrixType() == common.ExtraUnGasValidatorTxType ||
			tx.GetMatrixType() == common.ExtraUnGasInterestTxType || tx.GetMatrixType() == common.ExtraUnGasTxsType || tx.GetMatrixType() == common.ExtraUnGasLotteryTxType {
			tmpstxs := make([]types.SelfTransaction, 0)
			tmpstxs = append(tmpstxs, tx)
			tmpstxs = append(tmpstxs, stxs...)
			stxs = tmpstxs
			normalTxindex++
			continue
		}
		sig := types.NewEIP155Signer(tx.ChainId())
		waitG.Add(1)
		ttx := tx
		go types.Sender_self(sig, ttx, waitG)
	}
	waitG.Wait()
	from := make([]common.Address, 0)
	for i, tx := range txs[normalTxindex:] {
		if tx.GetMatrixType() == common.ExtraUnGasMinerTxType || tx.GetMatrixType() == common.ExtraUnGasValidatorTxType ||
			tx.GetMatrixType() == common.ExtraUnGasInterestTxType || tx.GetMatrixType() == common.ExtraUnGasTxsType || tx.GetMatrixType() == common.ExtraUnGasLotteryTxType {
			tmpstxs := make([]types.SelfTransaction, 0)
			tmpstxs = append(tmpstxs, tx)
			tmpstxs = append(tmpstxs, stxs...)
			stxs = tmpstxs
			continue
		}
		if tx.IsEntrustTx() {
			from := tx.From()
			entrustFrom := statedb.GetGasAuthFrom(from, p.bc.CurrentBlock().NumberU64()) //
			if !entrustFrom.Equal(common.Address{}) {
				tx.Setentrustfrom(entrustFrom)
				//tx.IsEntrustGas = true
				tx.SetIsEntrustGas(true)
			} else {
				entrustFrom := statedb.GetGasAuthFromByTime(from, uint64(block.Time().Uint64()))
				if !entrustFrom.Equal(common.Address{}) {
					tx.Setentrustfrom(entrustFrom)
					//tx.IsEntrustGas = true
					//tx.IsEntrustByTime = true
					tx.SetIsEntrustGas(true)
					tx.SetIsEntrustByTime(true)
				} else {
					log.Error("下载过程:该用户没有被授权过委托Gas")
					return nil, nil, 0, ErrWithoutAuth
				}
			}
		}
		statedb.Prepare(tx.Hash(), block.Hash(), i)
		receipt, _, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, nil, 0, err
		}
		receipts = append(receipts, receipt)
		allLogs = append(allLogs, receipt.Logs...)
		txcount = i
		from = append(from, tx.From())
	}
	p.ProcessReward(statedb, block.Header(), upTime, from, *usedGas)

	for _, tx := range stxs {
		statedb.Prepare(tx.Hash(), block.Hash(), txcount+1)
		receipt, _, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, nil, 0, err
		}
		tmpr := make(types.Receipts, 0)
		tmpr = append(tmpr, receipt)
		tmpr = append(tmpr, receipts...)
		receipts = tmpr
		tmpl := make([]*types.Log, 0)
		tmpl = append(tmpl, receipt.Logs...)
		tmpl = append(tmpl, allLogs...)
		allLogs = tmpl
	}

	// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
	p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), receipts)

	return receipts, allLogs, *usedGas, nil
}
// Process processes the state changes according to the Matrix rules by running
// the transaction messages using the statedb and applying any rewards to both
// the processor (coinbase) and any included uncles.
//
// Process returns the receipts and logs accumulated during the process and
// returns the amount of gas that was used in the process. If any of the
// transactions failed to execute due to insufficient gas it will return an error.
Process processes the state changes according to the Matrix rules by running
the transaction messages using the statedb and applying any rewards to both
the processor (coinbase) and any included uncles.

Process returns the receipts and logs accumulated during the process and
returns the amount of gas that was used in the process. If any of the
transactions failed to execute due to insufficient gas it will return an error.
// Process processes the state changes according to the Matrix rules by running // the transaction messages using the statedb and applying any rewards to both // the processor ( coinbase ) and any included uncles . // // Process returns the receipts and logs accumulated during the process and // returns the amount of gas that was used in the process . If any of the // transactions failed to execute due to insufficient gas it will return an error .
func (p *StateProcessor) ProcessTxs(block *types.Block, statedb *state.StateDB, cfg vm.Config, upTime map[common.Address]uint64) (types.Receipts, []*types.Log, uint64, error) {
	var (
		receipts types.Receipts
		usedGas  = new(uint64)
		header   = block.Header()
		allLogs  []*types.Log
		gp       = new(GasPool).AddGas(block.GasLimit())
	)
	if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
		misc.ApplyDAOHardFork(statedb)
	}
	statedb.UpdateTxForBtree(uint32(block.Time().Uint64()))
	statedb.UpdateTxForBtreeBytime(uint32(block.Time().Uint64()))
	stxs := make([]types.SelfTransaction, 0)
	var txcount int
	txs := block.Transactions()
	var waitG = &sync.WaitGroup{}
	maxProcs := runtime.NumCPU() 
	if maxProcs >= 2 {
		runtime.GOMAXPROCS(maxProcs - 1) 
	}
	normalTxindex := 0
	for _, tx := range txs {
		if tx.GetMatrixType() == common.ExtraUnGasMinerTxType || tx.GetMatrixType() == common.ExtraUnGasValidatorTxType ||
			tx.GetMatrixType() == common.ExtraUnGasInterestTxType || tx.GetMatrixType() == common.ExtraUnGasTxsType || tx.GetMatrixType() == common.ExtraUnGasLotteryTxType {
			tmpstxs := make([]types.SelfTransaction, 0)
			tmpstxs = append(tmpstxs, tx)
			tmpstxs = append(tmpstxs, stxs...)
			stxs = tmpstxs
			normalTxindex++
			continue
		}
		sig := types.NewEIP155Signer(tx.ChainId())
		waitG.Add(1)
		ttx := tx
		go types.Sender_self(sig, ttx, waitG)
	}
	waitG.Wait()
	from := make([]common.Address, 0)
	for i, tx := range txs[normalTxindex:] {
		if tx.GetMatrixType() == common.ExtraUnGasMinerTxType || tx.GetMatrixType() == common.ExtraUnGasValidatorTxType ||
			tx.GetMatrixType() == common.ExtraUnGasInterestTxType || tx.GetMatrixType() == common.ExtraUnGasTxsType || tx.GetMatrixType() == common.ExtraUnGasLotteryTxType {
			tmpstxs := make([]types.SelfTransaction, 0)
			tmpstxs = append(tmpstxs, tx)
			tmpstxs = append(tmpstxs, stxs...)
			stxs = tmpstxs
			continue
		}
		if tx.IsEntrustTx() {
			from := tx.From()
			entrustFrom := statedb.GetGasAuthFrom(from, p.bc.CurrentBlock().NumberU64()) 
			if !entrustFrom.Equal(common.Address{}) {
				tx.Setentrustfrom(entrustFrom)
				tx.IsEntrustGas = true
				tx.SetIsEntrustGas(true)
			} else {
				entrustFrom := statedb.GetGasAuthFromByTime(from, uint64(block.Time().Uint64()))
				if !entrustFrom.Equal(common.Address{}) {
					tx.Setentrustfrom(entrustFrom)
					tx.IsEntrustGas = true
					tx.IsEntrustByTime = true
					tx.SetIsEntrustGas(true)
					tx.SetIsEntrustByTime(true)
				} else {
					log.Error("下载过程:该用户没有被授权过委托Gas")
					return nil, nil, 0, ErrWithoutAuth
				}
			}
		}
		statedb.Prepare(tx.Hash(), block.Hash(), i)
		receipt, _, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, nil, 0, err
		}
		receipts = append(receipts, receipt)
		allLogs = append(allLogs, receipt.Logs...)
		txcount = i
		from = append(from, tx.From())
	}
	p.ProcessReward(statedb, block.Header(), upTime, from, *usedGas)
	for _, tx := range stxs {
		statedb.Prepare(tx.Hash(), block.Hash(), txcount+1)
		receipt, _, err := ApplyTransaction(p.config, p.bc, nil, gp, statedb, header, tx, usedGas, cfg)
		if err != nil && err != ErrSpecialTxFailed {
			return nil, nil, 0, err
		}
		tmpr := make(types.Receipts, 0)
		tmpr = append(tmpr, receipt)
		tmpr = append(tmpr, receipts...)
		receipts = tmpr
		tmpl := make([]*types.Log, 0)
		tmpl = append(tmpl, receipt.Logs...)
		tmpl = append(tmpl, allLogs...)
		allLogs = tmpl
	}
	 Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
	p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), receipts)
	return receipts, allLogs, *usedGas, nil
}
func ( p * StateProcessor ) ProcessTxs ( block * types . Block , statedb * state . StateDB , cfg vm . Config , upTime map [ common . Address ] uint64 ) ( types . Receipts , [ ] * types . Log , uint64 , error ) { var ( receipts types . Receipts usedGas = new ( uint64 ) header = block . Header ( ) allLogs [ ] * types . Log gp = new ( GasPool ) . AddGas ( block . GasLimit ( ) ) ) if p . config . DAOForkSupport && p . config . DAOForkBlock != nil && p . config . DAOForkBlock . Cmp ( block . Number ( ) ) == 0 { misc . ApplyDAOHardFork ( statedb ) } statedb . UpdateTxForBtree ( uint32 ( block . Time ( ) . Uint64 ( ) ) ) statedb . UpdateTxForBtreeBytime ( uint32 ( block . Time ( ) . Uint64 ( ) ) ) stxs := make ( [ ] types . SelfTransaction , 0 ) var txcount int txs := block . Transactions ( ) var waitG = & sync . WaitGroup { } maxProcs := runtime . NumCPU ( ) if maxProcs >= 2 { runtime . GOMAXPROCS ( maxProcs - 1 ) } normalTxindex := 0 for _ , tx := range txs { if tx . GetMatrixType ( ) == common . ExtraUnGasMinerTxType || tx . GetMatrixType ( ) == common . ExtraUnGasValidatorTxType || tx . GetMatrixType ( ) == common . ExtraUnGasInterestTxType || tx . GetMatrixType ( ) == common . ExtraUnGasTxsType || tx . GetMatrixType ( ) == common . ExtraUnGasLotteryTxType { tmpstxs := make ( [ ] types . SelfTransaction , 0 ) tmpstxs = append ( tmpstxs , tx ) tmpstxs = append ( tmpstxs , stxs ... ) stxs = tmpstxs normalTxindex ++ continue } sig := types . NewEIP155Signer ( tx . ChainId ( ) ) waitG . Add ( 1 ) ttx := tx go types . Sender_self ( sig , ttx , waitG ) } waitG . Wait ( ) from := make ( [ ] common . Address , 0 ) for i , tx := range txs [ normalTxindex : ] { if tx . GetMatrixType ( ) == common . ExtraUnGasMinerTxType || tx . GetMatrixType ( ) == common . ExtraUnGasValidatorTxType || tx . GetMatrixType ( ) == common . ExtraUnGasInterestTxType || tx . GetMatrixType ( ) == common . ExtraUnGasTxsType || tx . GetMatrixType ( ) == common . ExtraUnGasLotteryTxType { tmpstxs := make ( [ ] types . SelfTransaction , 0 ) tmpstxs = append ( tmpstxs , tx ) tmpstxs = append ( tmpstxs , stxs ... ) stxs = tmpstxs continue } if tx . IsEntrustTx ( ) { from := tx . From ( ) entrustFrom := statedb . GetGasAuthFrom ( from , p . bc . CurrentBlock ( ) . NumberU64 ( ) ) if ! entrustFrom . Equal ( common . Address { } ) { tx . Setentrustfrom ( entrustFrom ) tx . SetIsEntrustGas ( true ) } else { entrustFrom := statedb . GetGasAuthFromByTime ( from , uint64 ( block . Time ( ) . Uint64 ( ) ) ) if ! entrustFrom . Equal ( common . Address { } ) { tx . Setentrustfrom ( entrustFrom ) tx . SetIsEntrustGas ( true ) tx . SetIsEntrustByTime ( true ) } else { log . Error ( " return nil , nil , 0 , ErrWithoutAuth } } } statedb . Prepare ( tx . Hash ( ) , block . Hash ( ) , i ) receipt , _ , err := ApplyTransaction ( p . config , p . bc , nil , gp , statedb , header , tx , usedGas , cfg ) if err != nil && err != ErrSpecialTxFailed { return nil , nil , 0 , err } receipts = append ( receipts , receipt ) allLogs = append ( allLogs , receipt . Logs ... ) txcount = i from = append ( from , tx . From ( ) ) } p . ProcessReward ( statedb , block . Header ( ) , upTime , from , * usedGas ) for _ , tx := range stxs { statedb . Prepare ( tx . Hash ( ) , block . Hash ( ) , txcount + 1 ) receipt , _ , err := ApplyTransaction ( p . config , p . bc , nil , gp , statedb , header , tx , usedGas , cfg ) if err != nil && err != ErrSpecialTxFailed { return nil , nil , 0 , err } tmpr := make ( types . Receipts , 0 ) tmpr = append ( tmpr , receipt ) tmpr = append ( tmpr , receipts ... ) receipts = tmpr tmpl := make ( [ ] * types . Log , 0 ) tmpl = append ( tmpl , receipt . Logs ... ) tmpl = append ( tmpl , allLogs ... ) allLogs = tmpl } p . engine . Finalize ( p . bc , header , statedb , block . Transactions ( ) , block . Uncles ( ) , receipts ) return receipts , allLogs , * usedGas , nil }
Process processes the state changes according to the Matrix rules by running
the transaction messages using the statedb and applying any rewards to both
the processor (coinbase) and any included uncles.
Process processes the state changes according to the Matrix rules by running the transaction messages using the statedb and applying any rewards to both the processor ( coinbase ) and any included uncles .
// Mutate the the block and state according to any hard-fork specs // Iterate over and process the individual transactions //获取cpu个数 //限制同时运行的goroutines数量 // //tx.IsEntrustGas = true //tx.IsEntrustGas = true //tx.IsEntrustByTime = true // Finalize the block, applying any consensus engine specific extras (e.g. block rewards)