Algorithm for Ninja style mining pool block share assignment
-
It's at objects/Block.cpp line 110, the method called Block::recalculate_shares() and here's some simplified pseudo-code to explain it:
sum_scaled_shares = 0 for each account's best deadline (let's call this "deadline") { // because it's possible, but rare, to have a 0 deadline // and we don't want a divide by zero error later deadline += 1 // deadline raised to the power of 1.2 (1.2 is set in pool's config file) scaled_share = pow(deadline, 1.2) // SOME_BIG_INT is actually 0x7fffffffffffffff in the code scaled_share = SOME_BIG_INT / scaled_share sum_scaled_shares += scaled_share }So after this loop, each account's slice of the pie will be their "scaled_share" out of "sum_scaled_shares".
As a dummy run, say you have 3 miners (a, b and c) with 3 deadlines ("0", "123" aka 2 minutes 3 seconds and "8125" aka 2 hours 15 minutes 25 seconds):a's "scaled_share" would be:
0 +1 = 1 ^1.2 = 1 0x7ffffffffffffffff/ = 0x7fffffffffffffffb's scaled_share would be:
123 +1 = 124 ^1.2 = 325.16666 0x7fffffffffffffff/ = 0x0064c5df25dc5f6cc's scaled_share would be:
8125 +1 = 8126 ^1.2 = 49187.2091402907 0x7fffffffffffffff/ = 0x0000aa8b645dc96bsum_scaled_shares = 0x7fffffffffffffff + 0x0064c5df25dc5f6c + 0x0000aa8b645dc96b = 0x8065706a8a3a28d6
so as percentages:
a: 0x7fffffffffffffff / 0x8065706a8a3a28d6 = 99.6914%
b: 0x0064c5df25dc5f6c / 0x8065706a8a3a28d6 = 0.3066%
c: 0x0000aa8b645dc96b / 0x8065706a8a3a28d6 = 0.0020%99.6914% + 0.3066% + 0.0020% = 100%
-
@catbref , thanks your pseudo code it much easier to understand.
-
@rds just a curiosity buddy: @catbref was the one writing the ninja code, back in the days, as i've been told... ;D
-
@gpedro He wrote the whole thing.
-
@catbref , props to you on your work.
Two observations:
-
It appears to me that the ^1.2 is the "skew" I referred to above, to reward miners with better deadlines? You said it's in the pool's config file, so each pool could have a different skew as they choose?
-
When I first read your discussion, I couldn't understand why you used some_big_int to be the numerator for the scaled_share formula instead of sum_scaled_shares. Then I checked out both ways and they yield the same exact % result. Interesting! So then I took out a piece of paper and started scribbling some high school algebra and came to the conclusion some_big_int can actually be any non zero number, big or small, positive or negative, e.g. 1 and the share percentages remain the same. More interesting!!
So enough discourse, this was very interesting and enlightening for me and I thank you.
I should also say it is academic for me at this point, as I switched over to solo mining shortly after my original post :)
-

