2

What is the lowest possible difficulty that can be set in genesis file so the first block starts with minimal difficulty and then grows slowly to reach the regular >100k difficulty levels ?

I have done some tests , and if I set the difficulty to 1,2, 16 or 32 the difficulty doesn't grow. It stays constant, and I have proofs of that.

This is how I do it:

[niko@localhost difeth]$ cat genesis.json 
{
    "config": {
        "chainId": 444,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "0x20",
    "gasLimit": "2100000",
    "alloc": {
    }
}
[niko@localhost difeth]$ 
[niko@localhost difeth]$ g --datadir /home/niko/saved-niko-home/difeth init ./genesis.json 
[niko@localhost difeth]$ g --datadir /home/niko/saved-niko-home/difeth --networkid 444 console
Welcome to the Geth JavaScript console!

instance: Geth/v1.7.2-unstable-ad444752/linux-amd64/go1.8.3
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> personal.newAccount()
Passphrase: 
Repeat passphrase: 
"0xc2b3b2f2ce7945cd60f3c7c30a4b02565c4786cf"
> miner.start(1)
INFO [10-16|17:17:52] Updated mining threads                   threads=1
INFO [10-16|17:17:52] Transaction pool price threshold updated price=18000000000
INFO [10-16|17:17:52] Starting mining operation 
null
> INFO [10-16|17:17:52] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=332.1µs
INFO [10-16|17:17:52] Successfully sealed new block            number=1 hash=5bdbe9…387386
INFO [10-16|17:17:52] 🔨 mined potential block                  number=1 hash=5bdbe9…387386
INFO [10-16|17:17:52] Commit new mining work                   number=2 txs=0 uncles=0 elapsed=243.157µs
INFO [10-16|17:17:52] Successfully sealed new block            number=2 hash=52b61f…66617b
INFO [10-16|17:17:52] 🔨 mined potential block                  number=2 hash=52b61f…66617b
.....

On another console I do:

[niko@localhost difeth]$ g --datadir /home/niko/saved-niko-home/difeth attach ipc:/home/niko/saved-niko-home/difeth/geth.ipc
Welcome to the Geth JavaScript console!

instance: Geth/v1.7.2-unstable-ad444752/linux-amd64/go1.8.3
coinbase: 0xc2b3b2f2ce7945cd60f3c7c30a4b02565c4786cf
at block: 8 (Mon, 16 Oct 2017 17:17:59 CDT)
 datadir: /home/niko/saved-niko-home/difeth
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> loadScript("/home/niko/saved-niko-home/myeth/snippets/dumpdiff.js");
true
> dumpDiff()
32  0   0
32  1508192272  1508192272
32  1508192273  1
32  1508192274  1
32  1508192275  1
32  1508192276  1
32  1508192277  1
32  1508192278  1
32  1508192279  1
32  1508192280  1
32  1508192281  1
32  1508192282  1
32  1508192283  1
32  1508192284  1
32  1508192285  1
32  1508192286  1
32  1508192287  1
32  1508192288  1
32  1508192289  1
32  1508192290  1
32  1508192291  1
32  1508192292  1
32  1508192293  1
undefined
> exit

Here the first column is the difficulty, the second is the timestamp, and the third is the time to create a block, in seconds. What I was expecting is that the first column had the difficulty like 32,40,54,67,89,122... and so on, but not constant 32.

This is how dumpdiff() is defined:

[niko@localhost snippets]$ cat dumpdiff.js 
function dumpDiff() {
    var i,end;
    var block;

    end=web3.eth.blockNumber;
    var prev_ts=0;
    var seconds;
    for (i=0;i<end;i++) {
        block=web3.eth.getBlock(i,true);
        seconds=block.timestamp-prev_ts
        console.log(block.difficulty+"\t"+block.timestamp+"\t"+seconds);
        prev_ts=block.timestamp;
    }
}
[niko@localhost snippets]$ 

Now, I had to modify params/protocol_params.go to set MinimumDifficulty to 2 because it didn't work with lower difficulties than 131072, but I am not sure if this is still relevant with latest sources.

  • 1
    It is not the same but to generate blocks as quickly as possible we changed CalcDifficulty to always return 1. ``` func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int { return big.NewInt(1) } ```, also have to remove some other warnings. – Ismael Oct 17 '17 at 3:15
  • 1
    @Ismael yes, I know, I changed it removing the time bomb. I guess I will have to look at difficulty algorithm , some math is wrong there with low numbers, it must be rising always. – Nulik Oct 17 '17 at 9:37
2

with trial and error, I found a number of 2250. If lower numbers are used the difficulty can freeze at constant rate below 2050.

> dumpDiff()
2250    0   0
2151    1508233789  1508233789
2152    1508233790  1
2153    1508233791  1
2154    1508233792  1
2155    1508233793  1
2156    1508233794  1
2157    1508233795  1
2158    1508233796  1
2159    1508233797  1
2160    1508233798  1
2161    1508233799  1
2162    1508233800  1
2163    1508233801  1
2164    1508233802  1
2165    1508233803  1
2166    1508233804  1
2167    1508233805  1
2168    1508233806  1
2169    1508233807  1
2170    1508233808  1
2171    1508233809  1
2172    1508233810  1
2173    1508233811  1
2174    1508233812  1
2175    1508233813  1
2176    1508233814  1
2177    1508233815  1
2178    1508233816  1
2179    1508233817  1
2180    1508233818  1
2181    1508233819  1
2182    1508233820  1
2183    1508233821  1
2184    1508233822  1
2185    1508233823  1
2186    1508233824  1
2187    1508233825  1
2188    1508233826  1
2189    1508233827  1

Now it is constantly rising.

  • 1
    This is probably due to the difficultbounddivisor being 2048. I haven't looked at this further though. – T9b Oct 27 '17 at 10:43
  • 1
    @T9b , definitely it is. Thanks for pointing it out! – Nulik Oct 27 '17 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.