Show Posts
|
Pages: [1]
|
thx a lot!
now i handle the target like this:
In the getwork i get target part from json package, and reverse it with byte for example, i get 0x0000000000000000000000000000000000000000000000000000ffff00000000 then i transform it into 0x00000000ffff0000000000000000000000000000000000000000000000000000
In the stratum the BASE_DIFFICULTY is 0x00000000ffff0000000000000000000000000000000000000000000000000000 when i get a "set_difficulty" param is 256 and my target should be int(BASE_DIFFICULTY / 256)
|
|
|
firstly, i try to check the mining.notify during every few seconds(30s), at the beginning, i can successfully get the json message, but after few times(maybe 2-4), i can only receive a empty message. then i try to submit a message(a wrong one) before every time i check the notify, i found it goes well question 1 is this the correct method to handler mining.notify?  question 2 in my opinion, the former situation, when i receive the empty message the server has disconnected with my miner. in other hand, the miner need to keep itself online with submit, is it right?  thanks 
|
|
|
so, the nBits in getwork and stratum is for what?
|
|
|
are you sure that is shift right by difficulty?
in your example
maxHash = 0x00000000ffff0000000000000000000000000000000000000000000000000000 >> difficulty;
if i get a difficulty = 256 from set_difficulty, the maxHash is equal to 0!!! and sometimes the difficulty is more than 300!
in some code, i saw this
server_difficulty = BASE_DIFFICULTY / difficulty where BASE_DIFFICULTY = 0x00000000ffff0000000000000000000000000000000000000000000000000000
|
|
|
oh! i see, i needn't to calculate the target, only use base_difficulty and the difficulty from the set_difficulty, i can get the the max hash to compare with the hash calculated by miner.
but, in the getwork protocol there is no set_difficulty, where i can get the max hash or target?
thx, again!
|
|
|
i wonder that what's the relationship between the params in set_difficulty and the target used for comparing with the nonce? or the target just comes from the Bits?
thx
|
|
|
get it!thank u very much!
|
|
|
many thanks again!
so as you posted above, i can get a work from stratum server. and disconnect the network. then the miner software increase extranonce2 (randomly?!) to build different header. for each header, in the worest condition, I should guess the nonce for 2^32 -1 times. until I find a nonce whose result hash can meet the target. I reconnect to the stratum server, and submit the extranonce2, nonce and ...in the predefined format. is it correct?
|
|
|
As far as I've seen, the extranonce2 info is always 4 bytes.... here's a snippet from ScalaMiner ( https://github.com/colinrgodsey/scalaminer) for generating the header from stratum info (extraNonceInt is a randomly generated 32b int): def getWork(hashType: ScalaMiner.HashType, extraNonceInt: Int, job: MiningJob, extraNonceInfo: ExtraNonce, targetBytes: Seq[Byte], needsMidstate: Boolean) = { val bytes = intToBytes(extraNonceInt) val enBytes = Seq.fill[Byte](extraNonceInfo.extranonce2Size - bytes.length)(0) ++ bytes
val extraNonce = extraNonceInfo.extranonce1 ++ enBytes
val sha256 = new ScalaSha256
val coinbase = ScalaMiner.BufferType.empty ++ job.coinbase1 ++ extraNonce ++ job.coinbase2
val coinbaseHash = doubleHash(coinbase, sha256)
val merkleRoot = reverseEndian(job.merkleBranches.foldLeft(coinbaseHash) { (a, b) => doubleHash(a ++ b, sha256) })
val ntime = (System.currentTimeMillis / 1000) + job.dTime
val serializedHeader = ScalaMiner.BufferType.empty ++ job.protoVersion ++ job.previousHash ++ merkleRoot ++ intToBytes(ntime.toInt) ++ job.nBits ++ intToBytes(0) ++ //enBytes ++ workBasePad
//require(serializedHeader.length == 128, "bad length " + serializedHeader.length)
//TODO: this is the 'old' target? val target = ScalaMiner.BufferType.empty ++ (if(targetBytes.isEmpty) "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000".fromHex.toSeq else targetBytes)
val midstate = if(needsMidstate) calculateMidstate(serializedHeader.take(64)) else Nil
Stratum.Job(Work(hashType, serializedHeader, midstate, target), job.id, merkleRoot, enBytes) }
to colinrgodsey first of all, thank u for replying me and my new confusion comes: 1) the extraNonceInt in your post is the so-called extranonce2? 2) how can it randomly generated? 3) where does it come from?
|
|
|
with extranonce2 coinb1 coinb2 extranonce1, i can get the coinbase. and then the coinbase operate with merkle branch somehow, i can get the merkle root. and then combine the version hash1...etc together, i can get the block header. so for example the extranonce2_size is 4 so the extranonce2 is from 0 to 2^32 - 1. is it means that when i get a notify from server, i can generate 2^32 block header from it? is my understanding all right? thx guys!
|
|
|
|