cpuminer-opt-3.19.5 includes an enhanced stratum-keepalive feature to prevent lost shares.
TLDR stop here.
There really is no actual stratum-keepalive, it's a hack as described below. It doesn't really keep the
connection alive but it prevents the negative effects of the pool server timing out if no shares are
submitted for a long time.
CPU miners are challenged by pools that set a minimum difficulty too high for CPUs to find shares
regularly. After around 5 minutes with no shares submitted the pool will drop the connection but not
notify the miner. Often the miner detects the dropped connection only when submitting a share.
This results in a lost share and is noted in the summary log as stratum errors and share count mismatches.
Every mismatch in the counter represents a lost share. When shares are so rare this is a big loss.
The first stratum-keepalive was a futile attempt to send a harmless message to the server in the hope it would
prevent the timeout. It was also convenient that the protocol defines a specific method "mining.suggest-difficulty"
which perfectly suits the situation. Unfortunately this was not successful. Pools not only ignore the request for
lower difficulty it doesn't reset the's pool timeout either. In effect it's useless.
However, it will remain in case pools decide to support the method some time in the future.
The enhanced stratum-keepalive goes one step further, it will pre-emptively reset the stratum connection before
the pool times out and closes it. This will prevent the miner from sending a share over a dead connection. It also
eliminates wasted time hashing with a dead connection even if no share is found.
The suggest difficulty method is sent after 3 minutes with no shares submitted and the pre-emptive reset is done
after 4 minutes with still no shares submitted. Timing is not precise but the reset is usually done before 5 minutes.
The option is disabled by default and can be enabled with --stratum-keepalive. There should be no harm in using
even if timeouts aren't a problem.
Here's a sample of it in action:
[2022-01-30 22:41:54] New Block 1373920, Net diff 0.00082473, Job 2ae5
Diff: Net 0.00082473, Stratum 0.05, Target 7.6294e-07
TTF @ 50.73 h/s: Block 19h23m, Share 1m04s
Net hash rate (est) 60.04 kh/s
[2022-01-30 22:42:14] Stratum keepalive requesting lower difficulty
[2022-01-30 22:42:14] New Block 1373921, Net diff 0.00082874, Job 2ae6
Diff: Net 0.00082874, Stratum 0.05, Target 7.6294e-07
TTF @ 48.44 h/s: Block 20h24m, Share 1m07s
Net hash rate (est) 60.33 kh/s
[2022-01-30 22:43:18] No shares submitted, resetting stratum connection
[2022-01-30 22:43:18] Stratum connection reset
[2022-01-30 22:43:18] Stratum extranonce1= 810dff03, extranonce2 size= 4
[2022-01-30 22:43:18] Stratum connection established