On the testnet, if a block hasn’t been mined in over double the block interval, a minimum-difficulty block is permitted. Whenever one is mined, getmininginfo will show 1.0 for the current difficulty (since it just shows the difficulty of the last block). However, the block after the minimum-difficulty block is required to satisfy the last non-minimum difficulty (unless it too takes longer than 5 minutes).

From my log, 70% of the time it’s jumping down to 1 if the previous block took less than 5 minutes. I could have a rounding error where I can’t see it, but 25% are less than 4 minutes. 21% of the time it jumps down to “1”. I am looking back 2 blocks because the difficulty is what it was on the previous block (from what str4d just said) and the “1” is chosen based on the block before that.

Ah, you misunderstand my comment. It’s not that a min-difficulty block is allowed if the previous block took longer than 5 minutes, but that a min-difficulty block is allowed if the current block will be mined more than five minutes since the previous block.

Each block header contains the difficulty it was mined at (nBits), and full nodes only accept a received block if (among other things) nBits matches what the node calculates should have been the difficulty for that block. The special testnet difficulty check is pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2, which can be verified at any future date since it relies on data in the block being checked and the previous block.

Note that this is open to gaming, since it is circumventing the difficulty adjustment algorithm to only rely on the untrusted time in the block header, so miners could fake minimum-difficulty blocks. But they have no incentive to do so, since this would only work on the zero-value testnet, and it is more valuable there for miners to test their configurations against the same proof-of-work as for the main blockchain (ie. not triggering this special rule if at all possible).

If by “min-difficulty block is allowed if the current block will be mined more than five minutes since the previous block” you mean “the next block difficulty will be set to 1 if the current block is taking more than 5 minutes to complete” then I understood. I said I had to look back 2 blocks (from my gathered data) to see what the trigger for “1” was because you said getinfo shows the previous block’s difficulty.

From the data the rule is apparently “if the sum of the current and previous block is taking longer than 5 minutes then set the next difficulty to 1, unless the previous difficulty was 1, in which case make it 1 again only if the current interval is taking more than 5 minutes”. I can see this from the data, but I can’t convert your wording to the data, so I am wondering if the programming is correct. Especially since it seems to be jumping around too much, and it would not jump around as much if it followed the rule your words seem to be saying.

It is selecting D=1 22% of the time and a Poisson calculation indicates that if nothing other than statistical variation were occurring, it should be selecting D=1 based on this rule 23% of the time. Therefore the network was probably stable during the night and the difficulty is reacting to expected statistical variation in an attempt to not have long delays between successive blocks. I got 23% based on it going to 1 after an average of L=2.88 intervals, using the equation in wikipedia for Poisson process P(k) = L^k / k! / e^L for k=2 since 2 blocks were found in an average of 2.88 intervals. This assumes the difficulty was already set correct for the network such that the network average was L=1 per 2.5 minutes. If you switch to the rule “go to 1 in next block if current block is taking more than 5 minutes” it will go to difficulty=1 13.5% of the time (k=0, L=2) if the network hash rate is as stable as it appears.

Here’s the difficulty data I have for a 7.3 hour period. The 1st column number is units of 1.0 = 2.5 minute interval at the difficulty in the 2nd column, assuming getinfo shows the difficulty of the previous block. Notice D=1 twice in a row at times in a way that is expected. Because of my sampling method, 1.9 may sometimes be 2.0.

I’ll try to work on an algorithm that accounts for the Poisson process, and you just plug in how often 10 minute wait times are acceptable. 5 minutes seems too short as that will occur 14% of the time due to it being a Poisson process. Although 14% isn’t too bad. If it changes too much simply due to the statistics, it invites smart mining that will be able to mine at less electrical cost or EC2 expense at the expense of others (if it also sticks to a 2.5 minute average). On the other hand, paying for smart mining to be smart at the expense of other miners will reduce statistical wait times for the benefit of fewer long waits.

If the currently displayed difficulty refers to the previous block, then difficulty=1 takes twice as long as difficulty between 50 and 60. The average time it took for difficulty=1 to be solved was about equal to the time it took to solve the much higher difficulties that were supposed to be triggering the “1”. The time slots before and after the “1”, or any average I take of pairs can’t show that the difficulty was reduced. It’s like the variable was not actually set to 1, but kept the previous value. Is this another programming error?

Huh, what’s the motivation for adding what appears to be a security bug to the testnet difficulty check? Shouldn’t the testnet rules be as close as possible to the mainnet rules with any differences having to be clearly motivated by usability for testing?

The difficulty was just now stuck at 1 for most of the past hour because the algorithm made a wide swing upwards to 340 after an influx of computers. Only 12 blocks were solved in the past hour even as this is the peak hash rate for the day and even though the difficulty says “1”. The difficulty’s not “1”, it’s just displaying that.

Also, the wide swings (500% when there is a 30% change in the hash rate) might be because it’s checking if the sum of the past 2 blocks > 5 minutes instead of just the previous block.

The following is the best I could find

next D = (avg of past 24 D) x SQRT (150 / (avg of past 24 times))

Stays on track 24/hour, only 50% swings in difficulty in response to 30% hash rate changes, only one 10 minute transaction delay per day (no need to jump down to “1”), and I would not know how to cheat it.

Just now as I was typing this it went back down to 60, an hour after it was at 350. Of course that is when EC2 servers should kick in if the algorithm is not changed or fixed. My percentage of blocks gained stays the same so I know hash rate is not changing.

When the real coin starts, you will not see such big swings as people cheating others will even it out.

Are the difficulty problems going to be fixed in z9? I was able to make it swing by 900% twice today when there were only about 50 computers on the network and got it to issue 44 blocks in 30 minutes.

By increasing network hash rate by 30% for 30 minutes. [edit: actually, there were probably only the equivalent of 20 good PCs on the network, and I added an equivalent 8 more so that’s like 40% “more” but only 30% of the “post” network) If other people join in to simulate a mining pool joining and then exiting, it might get stuck on d=500 possibly indefinitely (until network gets that big) and issue out only 5 blocks per hour. I’m fine-tuning when I join and exit to see what it is most sensitive to. The idea to test is to see if I can make it resonate and concentrate hash energy when it is low, making others pay the high hash energy cost when it is high. It has a PID controller characteristic (a momentum based on a belief about how the network is supposed to behave, i.e a Derivative factor) which makes it open to manipulation. The equation I suggested above is a PI controller that will not resonate. But I now think the following is better and posted to github

next difficulty = (avg of past 30 difficulties) x 150 seconds / (avg of past 30 blocks’ seconds / block)
or to save some computation replace both averages with sums since they are both divided by 30.
[edit: now I think 18 is better because it is more responsive to my type of “attack” see below]

By overshooting and undershooting “100%” based on random variation, the current algorithm is inviting concentrated mining to take advantage of others. It’s like it was written by someone who wanted to exploit coins that use it. It will be harder to see once it begins because the exploitations even out the swings.

The number of computers on the network based on the current algorithm is about 1/4 the time-weighted average of the difficulty, 1/8 the peaks, and about 1/2 the valleys.

Here’s the difficulty per block with the current algorithm (blue spikes)
when I was trying to get it to spike up, and what it would have been if the equation was
next D= (sum past 18 D’s) x 150 / (seconds of past 18 D’s)