Do I understand correctly that if a share (or several shares in a row) takes a long time to be found, the difficulty for the next share will decrease? If so, will the payout per share be proportional to the difficulty? How will this synergize with the 3*n rule?
Yes, difficulty for the next share is computed from the time elapsed between the last share and the 200th ago share. Payouts are proportional to difficulty. Difficulty of individual shares is factored in when the chain is traversed backwards to find which shares to payout to - shares are included until the total difficulty of the shares is equal to 3*(current difficulty), which the last share being partially included to get it exact.
Also, how will you handle updates of the global difficulty mid-round? If not done correctly these matters can make the pool prone to hopping.
The '3*n rule' was chosen to minimize the effect of global difficulty changes. Using it makes the expected value of shares approximately follow the expected value of mining independently, with a period where there is higher-than-solo return followed by lower-than-solo return.
larger:
http://u.forre.st/u/snuqtcri/return.pngBlue: Expected return on solo mining
Green: Expected return if p2pool were to use a sliding window of a fixed number of shares
Purple: Expected return using p2pool's '3*n rule'
The higher-than-solo region will encourage miners to keep mining afterwards in order to preserve their value. If everyone stopped mining after the return went under solo, the region of shares that pay higher than solo mining would shift backwards.
I put a lot of thought into this issue, and this was the best solution I could find. The increase/decrease in expected yield is proportional to the change in difficulty and is much lower than what can be obtained from pool hopping on a proportional pool, so I believe that effects will be minimal.
Also, won't communication latency be a major problem with a share per 5 seconds?
Five seconds is a bit higher than I originally thought would work.
Share validation and passing is fast with the p2pool client - with a well connected network of p2p nodes the effect of latency should be minimal. If latency is assumed to plague all users evenly, there is no net loss because orphan shares don't actually 'lose' anything. If an orphan share qualifies as a block, it will still be accepted by the bitcoin network and paid to the shares' owners. If it isn't, its 'value' is evenly distributed to the rest of people using p2pool.