Difficulty

降低 testnet-in-a-box 的難度?

  • March 5, 2012

我正在做一些測試,經常發現自己需要快速生成 6 個塊來確認一些 tx。在我的 macbook 上生成每個塊需要幾分鐘,所以這會大大減慢速度。

有沒有辦法調整難度?請注意,這通常不適用於測試網,而是用於在我的開發機器上只有 2 個節點的盒子中的私有測試網。謝謝!

改變這兩行得到你想要的。請注意,它又快又髒,並且會破壞非測試網,所以不要將它用於除測試網之外的任何東西:

diff --git a/src/main.cpp b/src/main.cpp
index a9311e2..b3496a1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -780,7 +780,7 @@ int64 static GetBlockValue(int nHeight, int64 nFees)
}

static const int64 nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
-static const int64 nTargetSpacing = 10 * 60;
+static const int64 nTargetSpacing = 10;
static const int64 nInterval = nTargetTimespan / nTargetSpacing;

//
@@ -1784,7 +1784,7 @@ bool LoadBlockIndex(bool fAllowNew)
    if (fTestNet)
    {
        hashGenesisBlock = uint256("0x00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008");
-        bnProofOfWorkLimit = CBigNum(~uint256(0) >> 28);
+        bnProofOfWorkLimit = CBigNum(~uint256(0) >> 15);
        pchMessageStart[0] = 0xfa;
        pchMessageStart[1] = 0xbf;
        pchMessageStart[2] = 0xb5;

這是帶有這些更改的一些 debug.log 輸出。我每 2 秒左右生成一個塊。如果太快,請相應地增加“>> 15”。那裡的每個增量都會使塊之間的時間加倍。

03/05/12 07:21:54 Flushing wallet.dat
Flushed wallet.dat 132ms
askfor block 000000935f454d1641e5   0
sending getdata: block 000000935f454d1641e5
received block 000000935f454d1641e5
SetBestChain: new best=000000935f454d1641e5  height=23  work=559980566
ProcessBlock: ACCEPTED
askfor block 00000c4d375ce8f92166   0
sending getdata: block 00000c4d375ce8f92166
received block 00000c4d375ce8f92166
SetBestChain: new best=00000c4d375ce8f92166  height=24  work=561029143
ProcessBlock: ACCEPTED
askfor block 000007e863a6d86bfb1d   0
sending getdata: block 000007e863a6d86bfb1d
received block 000007e863a6d86bfb1d
SetBestChain: new best=000007e863a6d86bfb1d  height=25  work=562077720
ProcessBlock: ACCEPTED
03/05/12 07:21:59 Flushing wallet.dat

引用自:https://bitcoin.stackexchange.com/questions/3069