// mine is the actual proof-of-work miner that searches for a nonce starting from
// seed that results in correct final block difficulty.
mine is the actual proof-of-work miner that searches for a nonce starting from
seed that results in correct final block difficulty.
// mine is the actual proof - of - work miner that searches for a nonce starting from // seed that results in correct final block difficulty .
func (amhash *Amhash) mine(header *types.Header, id int, seed uint64, abort chan struct{}, found chan *types.Header, isBroadcastNode bool) {
	var (
		curHeader = types.CopyHeader(header)
		target = new(big.Int).Div(maxUint256, header.Difficulty)
		number = curHeader.Number.Uint64()
	)
	if isBroadcastNode {
		target = maxUint256
	}
	log.INFO("SEALER begin mine", "target", target, "isBroadcast", isBroadcastNode, "number", number, "diff", header.Difficulty.Uint64())
	defer log.INFO("SEALER stop mine", "number", number, "diff", header.Difficulty.Uint64())
	var (
		attempts = int64(0)
		nonce    = seed
	)
	logger := log.New("miner", id)
	logger.Trace("Started pow mine search for new nonces", "seed", seed)
search:
	for {
		select {
		case <-abort:
			logger.Trace("pow mine nonce search aborted", "attempts", nonce-seed)
			amhash.hashrate.Mark(attempts)
			return
		default:
			attempts++
			if (attempts % (1 << 15)) == 0 {
				amhash.hashrate.Mark(attempts)
				attempts = 0
			}
			result := x11PowHashByTest(combinationData(curHeader))
			shareBig, ret := new(big.Int).SetString(strings.TrimPrefix(Reverse(result), "0x"), 16)
			if ret {
				if shareBig.Cmp(target) <= 0 {
					select {
					case found <- curHeader:
						logger.Trace("Ethash nonce found and reported", "attempts", nonce-seed, "nonce", nonce)
					case <-abort:
						logger.Trace("Ethash nonce found but discarded", "attempts", nonce-seed, "nonce", nonce)
					}
					break search
				}
			} else {
			}
			nonce++
			curHeader.Nonce = types.EncodeNonce(nonce)
			bytnonce, _ := curHeader.Nonce.MarshalText()
			Reverse(bytnonce)
			curHeader.Nonce.UnmarshalText(bytnonce)
		}
	}
}
func ( amhash * Amhash ) mine ( header * types . Header , id int , seed uint64 , abort chan struct { } , found chan * types . Header , isBroadcastNode bool ) { var ( curHeader = types . CopyHeader ( header ) target = new ( big . Int ) . Div ( maxUint256 , header . Difficulty ) number = curHeader . Number . Uint64 ( ) ) if isBroadcastNode { target = maxUint256 } log . INFO ( " " , " " , target , " " , isBroadcastNode , " " , number , " " , header . Difficulty . Uint64 ( ) ) defer log . INFO ( " " , " " , number , " " , header . Difficulty . Uint64 ( ) ) var ( attempts = int64 ( 0 ) nonce = seed ) logger := log . New ( " " , id ) logger . Trace ( " " , " " , seed ) search : for { select { case <- abort : logger . Trace ( " " , " " , nonce - seed ) amhash . hashrate . Mark ( attempts ) return default : attempts ++ if ( attempts % ( 1 << 15 ) ) == 0 { amhash . hashrate . Mark ( attempts ) attempts = 0 } result := x11PowHashByTest ( combinationData ( curHeader ) ) shareBig , ret := new ( big . Int ) . SetString ( strings . TrimPrefix ( Reverse ( result ) , " " ) , 16 ) if ret { if shareBig . Cmp ( target ) <= 0 { select { case found <- curHeader : logger . Trace ( " " , " " , nonce - seed , " " , nonce ) case <- abort : logger . Trace ( " " , " " , nonce - seed , " " , nonce ) } break search } } else { } nonce ++ curHeader . Nonce = types . EncodeNonce ( nonce ) bytnonce , _ := curHeader . Nonce . MarshalText ( ) Reverse ( bytnonce ) curHeader . Nonce . UnmarshalText ( bytnonce ) } } }
mine is the actual proof-of-work miner that searches for a nonce starting from
seed that results in correct final block difficulty.
mine is the actual proof - of - work miner that searches for a nonce starting from seed that results in correct final block difficulty .
// Extract some data from the header //mineData  = generateMineData(curHeader) // Start generating random nonces until we abort or find a good one // Mining terminated, update stats and abort // We don't have to update hash rate on every nonce, so update after after 2^X nonces // Compute the PoW value of this nonce /*result := x11PowHash(mineData, nonce) //YYYYYYYYYYYYYYY
			if new(big.Int).SetBytes(result).Cmp(target) <= 0 {
				// Correct nonce found, create a new header with it
				header = types.CopyHeader(header)
				header.Nonce = types.EncodeNonce(nonce)
				// Seal and return a block (if still needed)
				select {
				case found <- header:
					logger.Trace("Ethash nonce found and reported", "attempts", nonce-seed, "nonce", nonce)
				case <-abort:
					logger.Trace("Ethash nonce found but discarded", "attempts", nonce-seed, "nonce", nonce)
				}
				break search
			}
			*/ //YYYYYYYYYYYYYYYYYYY //log.Info("YYYYYYYYYYYYYYYYYYYYY11111111111", "cmp shareBig and target,sharebig", shareBig, "target", target) // Correct nonce found, create a new header with it //header = types.CopyHeader(header) //header.Nonce = types.EncodeNonce(nonce) // Seal and return a block (if still needed) //log.Info("YYYYYYYYYYYYYYYYYYYYY22222222222", "cmp shareBig and target,sharebig", shareBig, "target", target) //log.Info("YYYYYYYYYYYYYYYYYYYYY3333333333", "new(big.Int).SetString err,number ", curHeader.Number) //YYYYYYYYYendYYYYYY