Ok, balancecurrent is really expensive in terms of performance and RPC is timing out with this long a round. I am trying to figure a faster way to do this.
Assuming the problem is summing over all the shares of the worker, note that shares older than the last 10,000 or so will have negligible score, so you can just find out the ID of the last share and use "where ID > X-10000" or similar.
Great, that's a big help. Yeah, it's the big table scan that's bogging it down.
Edit: balance updated to only scan last 10,000 shares. Note that the final round payment calculation still scans all shares.
There's still room for improvement in the final calculation. At the current r, shares older than 17,000 will have score less than double-precision granularity, so they won't have any effect anyway.
Hmm, you mean no material affect?
Round 4 payment calc:
select max(score) from share = 646.164449020304
shares = select count(*) from share where score is null = 281610
maxid = select max(id) from share 828713
totscore = select sum(exp(score-max))+exp(score-os) from share = 436.318039783311
payment calc
select exp(score-totscore) from share
order by id
values:
5.43924628175081e-284
5.45174116086077e-284
5.46426474284596e-284
5.47681709364117e-284
...
So they're very small, enough so that we could ignore them but they don't underflow the double precision type.