Bitcoin Forum
May 07, 2024, 08:29:11 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: set_difficulty in stratum  (Read 1185 times)
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 06, 2014, 09:01:31 AM
 #1

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
1715113751
Hero Member
*
Offline Offline

Posts: 1715113751

View Profile Personal Message (Offline)

Ignore
1715113751
Reply with quote  #2

1715113751
Report to moderator
1715113751
Hero Member
*
Offline Offline

Posts: 1715113751

View Profile Personal Message (Offline)

Ignore
1715113751
Reply with quote  #2

1715113751
Report to moderator
1715113751
Hero Member
*
Offline Offline

Posts: 1715113751

View Profile Personal Message (Offline)

Ignore
1715113751
Reply with quote  #2

1715113751
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
colinrgodsey
Newbie
*
Offline Offline

Activity: 39
Merit: 0



View Profile WWW
May 06, 2014, 10:31:42 PM
 #2

the max hash is going to be the difficulty 1 max hash (00000000ffff0000000000000000000000000000000000000000000000000000) shifted right by the difficulty.

so:

maxHash = 0x00000000ffff0000000000000000000000000000000000000000000000000000 >> difficulty;

if(hash > maxHash) tooShort(hash)
else goodToGo();

'short' actually refers to the hash being too low of a difficulty (bigger than it should be). thus with higher difficulty, the max acceptable becomes smaller, and harder to find a solution for.
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 07, 2014, 06:24:32 AM
 #3

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!
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 07, 2014, 07:19:24 AM
Last edit: May 07, 2014, 07:38:07 AM by rossihwang
 #4

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
colinrgodsey
Newbie
*
Offline Offline

Activity: 39
Merit: 0



View Profile WWW
May 07, 2014, 03:11:00 PM
 #5

lol yea wow sorry about that. divide Wink shift right if you're using a 2^n diff, divide by difficulty.

when using getwork, there should be a "target" field in the JSON response (should be data, hash1, and target).

target is the little-endian result of the divided dif 1 hash

targetBytes = bintToBytes(difMask / difficulty, 32).reverse //32 bytes

not sure the exact method for going backwards, but I think you can just do dif1hash / target
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 08, 2014, 04:07:38 AM
 #6

so, the nBits in getwork and stratum is for what?
colinrgodsey
Newbie
*
Offline Offline

Activity: 39
Merit: 0



View Profile WWW
May 09, 2014, 03:37:23 AM
 #7


dont remember what it actually means, but its part of the block header:

Code:
val serializedHeader = ScalaMiner.BufferType.empty ++
job.protoVersion ++ job.previousHash ++ merkleRoot ++
intToBytes(ntime.toInt) ++ job.nBits ++ intToBytes(0) ++ //enBytes ++
workBasePad

so, the nBits in getwork and stratum is for what?
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 09, 2014, 06:36:27 AM
 #8

this link define the bits

https://en.bitcoin.it/wiki/Difficulty

at How is difficulty stored in blocks?

but i cant tell the different between bits and difficulty we  discuss above
colinrgodsey
Newbie
*
Offline Offline

Activity: 39
Merit: 0



View Profile WWW
May 09, 2014, 03:48:07 PM
 #9

ahh, right. so 'bits' is the actual blockchain difficulty at the time- its stored in the header as a coherency mechanism for difficulty across the network (blocks calculated with an old or otherwise badly computed difficulty)

when working with stratum though, we dont really care about the network difficulty, because that's all the pool's dealings.

Pooled mining is basically based around overriding the network difficulty. if we didnt have pools, we'd all have to use the network difficulty and would have massive variance in our hashing power. So what pools do is make you work on a much lower difficulty so that you can prove to the pool that you are infact mining, and they can calculate from that the number of shares you produced and how many shares it would take on average to calculate a block (basically).

So basically they're just computing how many 'hashes' you've guessed in that round (theres a formula for how many hashes on average an x difficulty share would take to guess), and how many hashes were computed by everyone that round, then you get paid out proportionally when there's a block won.

and dealing with pooled mining, nbits doesnt really matter for your target, you're just targeting the pool difficulty. nBits will generally just be used for calculating the header and midstate.
rossihwang (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 21, 2014, 09:46:17 AM
 #10

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)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!