How is the "N" in PPLNS chosen? 2xDiff appears to make no sense - OR - Why are Scrypt share difficulties off by a factor of 65536? while my example in the following question is using the altcoin "Bitconnect", I believe it is actually a general question which fits here - if not, let me know.

I am struggling to understand PPLNS (I need to implement it in a pool). I know in general how the system works, but what is a mystery to me is where the N comes from.

I read on many places on the Internet that N = 2 * difficulty is a good value, and that this would mean that on average a miner will earn rewards from two blocks for the same shares.

However, it simply does not add up for me.

Practical example: BitConnect pool. Let's say BitConnect's difficulty is currently ~900,000.

An AntMiner L3+ submits a share at difficulty ~150,000 (which counts as a share value of 150,000 then) every ~15 seconds, so in 3 minutes, that one AntMiner has already filled the whole "N" of 900,000x2=1,800,000. That would, in reverse, mean that I would expect to mine a BitConnect block every 90 seconds on average, with one AntMiner, which is of course not true.

100 AntMiners running on our pool gave a share value of 230,000,000 in the last 5 minutes, which would have been more than 100 times the whole "N" already!

So something can't be right here, and I don't understand what. Should I not multiply the submitted share with the work difficulty? But then a small miner would get the same reward as a large one which makes no sense. Or is the whole Internet wrong about the 2*diff for "N", and that it's based on the assumption that it takes on average a value of shares equal to the difficulty to find a block? Doesn't sound likely.

On average, it takes 2^32 hashes to find a valid share at difficulty 1, right? And on average, it takes X shares to find a share at difficulty X, hence why you increase the difficulty at the pool for your miner if the miner is powerful (it will then less often submit a share), right...? But the last point starts to make less sense already, together with the fact that you need a share at difficulty Y to find a block if the currently coin block difficutly is Y... And the pool software counts a share with difficulty X the same as X shares with difficulty 1. At the end I'm left confused how it all works together and how I can arrive at a value for "N" which actually results in a miner getting on average two rewards for the same share...!

Please help me understand what is wrong.

EDIT: I found that all calculations differ from reality by a factor of 2^16. Then I found this: https://bitcoin.stackexchange.com/a/11816/62320
This would suggest that for Scrypt, pools use a scaled "share difficulty" value by exactly that factor, but the reported block difficulty would not be scaled. This would explain everything but it's the only place I found this on the Internet (and it would mean that I need different calculations depending on the algorithm I'm handling) - can anyone confirm this?
An AntMiner L3+ submits a share at difficulty ~150,000 (which counts as a share value of 150,000 then) every ~15 seconds, so in 3 minutes, that one AntMiner has already filled the whole "N" of 900,000x2=1,800,000. That would, in reverse, mean that I would expect to mine a BitConnect block every 90 seconds on average, with one AntMiner, which is of course not true.


I don't think that is how shares are counted. According to this Bitcointalk post,


  When a share is submitted, assign to it a score of 1/D, where D is the difficulty at the time the share is submitted.


So in your scenario, when your AntMiner L3+ submits a share, that share is assigned a score of 1/900000, so its "share value" is 2, not 150000.