shohu / c0ban

c0ban source tree
MIT License
0 stars 0 forks source link

Pass for test pruning.py #30

Open shohu opened 6 years ago

shohu commented 6 years ago
# test/functional/pruning.py
2018-03-26 00:35:14.726000 TestFramework (INFO): Initializing test directory /tmp/testx8gd93d7
2018-03-26 00:35:31.708000 TestFramework (INFO): Warning! This test requires 4GB of disk space and takes over 30 mins (up to 2 hours)
2018-03-26 00:35:31.708000 TestFramework (INFO): Mining a big blockchain of 995 blocks
2018-03-26 00:39:20.902000 TestFramework (INFO): Check that we haven't started pruning yet because we're below PruneAfterHeight
2018-03-26 00:39:20.903000 TestFramework (INFO): Success
2018-03-26 00:39:20.903000 TestFramework (INFO): Though we're already using more than 550MiB, current usage: 590
2018-03-26 00:39:20.903000 TestFramework (INFO): Mining 25 more blocks should cause the first block file to be pruned
2018-03-26 00:39:29.199000 TestFramework (INFO): Success
2018-03-26 00:39:29.199000 TestFramework (INFO): Usage should be below target: 479
2018-03-26 00:39:29.199000 TestFramework (INFO): Check that we'll exceed disk space target if we have a very high stale block rate
2018-03-26 00:39:29.200000 TestFramework (INFO): Mine 24 (stale) blocks on Node 1, followed by 25 (main chain) block reorg from Node 0, for 12 rounds
2018-03-26 00:46:22.058000 TestFramework (INFO): Usage can be over target because of high stale rate: 634
2018-03-26 00:46:22.060000 TestFramework (INFO): Check that we can survive a 288 block reorg still
2018-03-26 00:46:25.262000 TestFramework (INFO): Current block height: 1320
2018-03-26 00:46:25.263000 TestFramework (INFO): Invalidating block 607aa48a80386b398f96001495ea6efc7988be7a6c6d8c4e66a7fc6b52ccf371 at height 1033
2018-03-26 00:46:31.157000 TestFramework (INFO): New best height: 1032
2018-03-26 00:46:34.269000 TestFramework (INFO): Generating new longer chain of 300 more blocks
2018-03-26 00:46:36.095000 TestFramework (INFO): Reconnect nodes
2018-03-26 00:46:41.450000 TestFramework (INFO): Verify height on node 2: 1332
2018-03-26 00:46:41.450000 TestFramework (INFO): Usage possibly still high bc of stale blocks in block files: 648
2018-03-26 00:46:41.450000 TestFramework (INFO): Mine 220 more blocks so we have requisite history (some blocks will be big and cause pruning of previous chain)
2018-03-26 00:47:35.934000 TestFramework (INFO): Usage should be below target: 773
2018-03-26 00:47:35.935000 TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/c0ban/test/functional/test_framework/test_framework.py", line 120, in main
    self.run_test()
  File "test/functional/pruning.py", line 390, in run_test
    (self.forkheight,self.forkhash) = self.reorg_test() #(1033, )
  File "test/functional/pruning.py", line 182, in reorg_test
    raise AssertionError("Pruning target not being met")
AssertionError: Pruning target not being met
2018-03-26 00:47:35.963000 TestFramework (INFO): Stopping nodes
2018-03-26 00:47:42.547000 TestFramework (WARNING): Not cleaning up dir /tmp/testx8gd93d7
2018-03-26 00:47:42.547000 TestFramework (ERROR): Test failed. Test logging available at /tmp/testx8gd93d7/test_framework.log
shohu commented 6 years ago

I changed block generation speed, but I got same error...

shohu commented 6 years ago

bitcoin output

# test/functional/pruning.py
2018-04-04 00:37:56.460000 TestFramework (INFO): Initializing test directory /tmp/test_jaynjvz
2018-04-04 00:37:57.288000 TestFramework (INFO): Warning! This test requires 4GB of disk space and takes over 30 mins (up to 2 hours)
2018-04-04 00:37:57.288000 TestFramework (INFO): Mining a big blockchain of 995 blocks
2018-04-04 00:42:16.886000 TestFramework (INFO): Check that we haven't started pruning yet because we're below PruneAfterHeight
2018-04-04 00:42:16.886000 TestFramework (INFO): Success
2018-04-04 00:42:16.887000 TestFramework (INFO): Though we're already using more than 550MiB, current usage: 590
2018-04-04 00:42:16.887000 TestFramework (INFO): Mining 25 more blocks should cause the first block file to be pruned
2018-04-04 00:42:25.510000 TestFramework (INFO): Success
2018-04-04 00:42:25.510000 TestFramework (INFO): Usage should be below target: 479
2018-04-04 00:42:25.511000 TestFramework (INFO): Check that we'll exceed disk space target if we have a very high stale block rate
2018-04-04 00:42:25.511000 TestFramework (INFO): Mine 24 (stale) blocks on Node 1, followed by 25 (main chain) block reorg from Node 0, for 12 rounds
2018-04-04 00:56:43.276000 TestFramework (INFO): Usage can be over target because of high stale rate: 638
2018-04-04 00:56:43.278000 TestFramework (INFO): Check that we can survive a 288 block reorg still
2018-04-04 00:56:46.625000 TestFramework (INFO): Current block height: 1320
2018-04-04 00:56:46.626000 TestFramework (INFO): Invalidating block 54584b81dbd2b166665036371b9934fe45c0aabd38afdd820df059670c0561a1 at height 1033
2018-04-04 00:56:52.514000 TestFramework (INFO): New best height: 1032
2018-04-04 00:56:55.572000 TestFramework (INFO): Generating new longer chain of 300 more blocks
2018-04-04 00:56:57.651000 TestFramework (INFO): Reconnect nodes
2018-04-04 00:57:02.819000 TestFramework (INFO): Verify height on node 2: 1332
2018-04-04 00:57:02.820000 TestFramework (INFO): Usage possibly still high bc of stale blocks in block files: 654
2018-04-04 00:57:02.820000 TestFramework (INFO): Mine 220 more blocks so we have requisite history (some blocks will be big and cause pruning of previous chain)
2018-04-04 00:59:05.779000 TestFramework (INFO): Usage should be below target: 463
2018-04-04 00:59:05.780000 TestFramework (INFO): Test that we can rerequest a block we previously pruned if needed for a reorg
2018-04-04 00:59:05.781000 TestFramework (INFO): Will need to redownload block 1033
2018-04-04 00:59:08.302000 TestFramework (INFO): Rewind node 0 to prev main chain to mine longer chain to trigger redownload. Blocks needed: 233
2018-04-04 00:59:24.690000 TestFramework (INFO): Verify node 2 reorged back to the main chain, some blocks of which it had to redownload
2018-04-04 00:59:37.349000 TestFramework (INFO): Test manual pruning with block indices
2018-04-04 00:59:43.621000 TestFramework (INFO): Success
2018-04-04 00:59:43.621000 TestFramework (INFO): Test manual pruning with timestamps
2018-04-04 00:59:49.516000 TestFramework (INFO): Success
2018-04-04 00:59:49.516000 TestFramework (INFO): Test wallet re-scan
2018-04-04 00:59:49.517000 TestFramework (INFO): Stop and start pruning node to trigger wallet rescan
2018-04-04 00:59:52.238000 TestFramework (INFO): Success
2018-04-04 00:59:52.238000 TestFramework (INFO): Syncing node 5 to test wallet
2018-04-04 01:00:20.025000 TestFramework (INFO): Success
2018-04-04 01:00:20.026000 TestFramework (INFO): Done
2018-04-04 01:00:20.026000 TestFramework (INFO): Stopping nodes
2018-04-04 01:00:25.045000 TestFramework (INFO): Cleaning up
2018-04-04 01:00:25.680000 TestFramework (INFO): Tests successful
shohu commented 6 years ago

I will try to "blockmaxsize up"

    if (gArgs.IsArgSet("-blockmaxsize")) {
        unsigned int max_size = gArgs.GetArg("-blockmaxsize", 0);
        if (gArgs.SoftSetArg("blockmaxweight", strprintf("%d", max_size * WITNESS_SCALE_FACTOR))) {
            LogPrintf("%s: parameter interaction: -blockmaxsize=%d -> setting -blockmaxweight=%d (-blockmaxsize is deprecated!)\n", __func__, max_size, max_size * WITNESS_SCALE_FACTOR);
        } else {
            LogPrintf("%s: Ignoring blockmaxsize setting which is overridden by blockmaxweight", __func__);
        }
    }
shohu commented 6 years ago

I changed following source, because block size 4 times.but couldn't pass test ...

2018-04-04 11 25 36

shohu commented 6 years ago

output

2018-03-26 00:47:35.934000 TestFramework (INFO): Usage should be below target: 773
2018-04-04 00:59:05.779000 TestFramework (INFO): Usage should be below target: 463

testcode

        # Get node0's wallet transactions back in its mempool, to avoid the
        # mined blocks from being too small.
        self.nodes[0].resendwallettransactions()

        for i in range(22):
            # This can be slow, so do this in multiple RPC calls to avoid
            # RPC timeouts.
            self.nodes[0].generate(10) #node 0 has many large tx's in its mempool from the disconnects
        sync_blocks(self.nodes[0:3], timeout=300)

c0band

UniValue resendwallettransactions(const JSONRPCRequest& request)
{
    CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
 :
 :
    std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(GetTime(), g_connman.get());
    UniValue result(UniValue::VARR);
    for (const uint256& txid : txids)
    {
        result.push_back(txid.ToString());
    }
    return result;
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman)
{
    std::vector<uint256> result;

    LOCK(cs_wallet);

    // Sort them in chronological order
    std::multimap<unsigned int, CWalletTx*> mapSorted;
    for (std::pair<const uint256, CWalletTx>& item : mapWallet)
    {
        CWalletTx& wtx = item.second;
        // Don't rebroadcast if newer than nTime:
        if (wtx.nTimeReceived > nTime)
            continue;
        mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx));
    }
    for (std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
    {
        CWalletTx& wtx = *item.second;
        if (wtx.RelayWalletTransaction(connman))
            result.push_back(wtx.GetHash());
    }
    return result;
}
bool CWalletTx::RelayWalletTransaction(CConnman* connman)
{
    assert(pwallet->GetBroadcastTransactions());
    if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain() == 0)
    {
        CValidationState state;
        /* GetDepthInMainChain already catches known conflicts. */
        if (InMempool() || AcceptToMemoryPool(maxTxFee, state)) {
            LogPrintf("Relaying wtx %s\n", GetHash().ToString());
            if (connman) {
                CInv inv(MSG_TX, GetHash());
                connman->ForEachNode([&inv](CNode* pnode)
                {
                    pnode->PushInventory(inv);
                });
                return true;
            }
        }
    }
    return false;
}
shohu commented 6 years ago

I focused following difference

bitcoin

Usage can be over target because of high stale rate: 638

c0ban

Usage can be over target because of high stale rate: 634

I will try to change "issueprices" from c0ban to bitcoin.

        # self.issue_args = "-issueprices=22000,22000,22000,22000,22000,22000,22000"
        self.issue_args = "-issueprices=50,50,50,50,50,50,50"

But couldn't resolved...

testcode

    def create_chain_with_staleblocks(self):
        # Create stale blocks in manageable sized chunks
        self.log.info("Mine 24 (stale) blocks on Node 1, followed by 25 (main chain) block reorg from Node 0, for 12 rounds")

        for j in range(12):
            # Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
            # Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
            # Stopping node 0 also clears its mempool, so it doesn't have node1's transactions to accidentally mine
            self.stop_node(0)
            self.start_node(0, extra_args=self.full_node_default_args)
            # Mine 24 blocks in node 1
            for i in range(24):
                if j == 0:
                    mine_large_block(self.nodes[1], self.utxo_cache_1)
                else:
                    # Add node1's wallet transactions back to the mempool, to
                    # avoid the mined blocks from being too small.
                    self.nodes[1].resendwallettransactions()
                    self.nodes[1].generate(1) #tx's already in mempool from previous disconnects

            # Reorg back with 25 block chain from node 0
            for i in range(25):
                mine_large_block(self.nodes[0], self.utxo_cache_0)

            # Create connections in the order so both nodes can see the reorg at the same time
            connect_nodes(self.nodes[1], 0)
            connect_nodes(self.nodes[2], 0)
            sync_blocks(self.nodes[0:3])

        self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir))
def mine_large_block(node, utxos=None):
    # generate a 66k transaction,
    # and 14 of them is close to the 1MB block limit
    num = 14
    txouts = gen_return_txouts()
    utxos = utxos if utxos is not None else []
    if len(utxos) < num:
        utxos.clear()
        utxos.extend(node.listunspent())
    fee = 100 * node.getnetworkinfo()["relayfee"]
    create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
    node.generate(1)
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
# transaction to make it large.  See gen_return_txouts() above.
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
    addr = node.getnewaddress()
    txids = []
    for _ in range(num):
        t = utxos.pop()
        inputs = [{"txid": t["txid"], "vout": t["vout"]}]
        outputs = {}
        change = t['amount'] - fee
        outputs[addr] = satoshi_round(change)
        rawtx = node.createrawtransaction(inputs, outputs)
        newtx = rawtx[0:92]
        newtx = newtx + txouts
        newtx = newtx + rawtx[94:]
        signresult = node.signrawtransaction(newtx, None, None, "NONE")
        txid = node.sendrawtransaction(signresult["hex"], True)
        txids.append(txid)
    return txids
shohu commented 6 years ago

mine_large_block created block size is 4 times

I tryied to change and execute test

def mine_large_block(node, utxos=None):
    # generate a 66k transaction,
    # and 14 of them is close to the 1MB block limit
    # num = 14 TODO
    num = 20
    txouts = gen_return_txouts()
    utxos = utxos if utxos is not None else []
    if len(utxos) < num:
        utxos.clear()
        utxos.extend(node.listunspent())
    fee = 100 * node.getnetworkinfo()["relayfee"]
    create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
    node.generate(1)

I got error..

# test/functional/pruning.py
2018-04-04 09:09:23.566000 TestFramework (INFO): Initializing test directory /tmp/test31z_a8vv
2018-04-04 09:09:24.402000 TestFramework (INFO): Warning! This test requires 4GB of disk space and takes over 30 mins (up to 2 hours)
2018-04-04 09:09:24.402000 TestFramework (INFO): Mining a big blockchain of 995 blocks

2018-04-04 09:28:21.791000 TestFramework (INFO): Check that we haven't started pruning yet because we're below PruneAfterHeight
2018-04-04 09:28:21.800000 TestFramework (INFO): Success
2018-04-04 09:28:21.812000 TestFramework (INFO): Though we're already using more than 550MiB, current usage: 2094
2018-04-04 09:28:21.812000 TestFramework (INFO): Mining 25 more blocks should cause the first block file to be pruned
2018-04-04 09:29:08.811000 TestFramework (INFO): Success
2018-04-04 09:29:08.812000 TestFramework (INFO): Usage should be below target: 1039
2018-04-04 09:29:08.813000 TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/c0ban/test/functional/test_framework/test_framework.py", line 120, in main
    self.run_test()
  File "test/functional/pruning.py", line 363, in run_test
    self.test_height_min()
  File "test/functional/pruning.py", line 94, in test_height_min
    raise AssertionError("Pruning target not being met")
AssertionError: Pruning target not being met
2018-04-04 09:29:08.834000 TestFramework (INFO): Stopping nodes
2018-04-04 09:29:28.449000 TestFramework (WARNING): Not cleaning up dir /tmp/test31z_a8vv
2018-04-04 09:29:28.451000 TestFramework (ERROR): Test failed. Test logging available at /tmp/test31z_a8vv/test_framework.log
# Create a spend of each passed-in utxo, splicing in "txouts" to each raw
# transaction to make it large.  See gen_return_txouts() above.
def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
    addr = node.getnewaddress()
    txids = []
    for _ in range(num):
        t = utxos.pop()
        inputs = [{"txid": t["txid"], "vout": t["vout"]}]
        outputs = {}
        change = t['amount'] - fee
        outputs[addr] = satoshi_round(change)
        rawtx = node.createrawtransaction(inputs, outputs)
        newtx = rawtx[0:92]
        newtx = newtx + txouts
        newtx = newtx + rawtx[94:]
        signresult = node.signrawtransaction(newtx, None, None, "NONE")
        txid = node.sendrawtransaction(signresult["hex"], True)
        txids.append(txid)
    return txids

testcode

# Create large OP_RETURN txouts that can be appended to a transaction
# to make it large (helper for constructing large transactions).
def gen_return_txouts():
    # Some pre-processing to create a bunch of OP_RETURN txouts to insert into transactions we create
    # So we have big transactions (and therefore can't fit very many into each block)
    # create one script_pubkey
    script_pubkey = "6a4d0200"  # OP_RETURN OP_PUSH2 512 bytes
    for i in range(512):
        script_pubkey = script_pubkey + "01"
    # concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
    txouts = "81"
    for k in range(128):
        # add txout value
        txouts = txouts + "0000000000000000"
        # add length of script_pubkey
        txouts = txouts + "fd0402"
        # add script_pubkey
        txouts = txouts + script_pubkey
    return txouts

gen_return_txouts's txouts size = 134914.

(Pdb) len(txouts)
134914

I will try to make txouts 4 times . but txouts length can't changed ? so mine_large_block num change 14 to 50. (50 is max)

shohu commented 6 years ago

c0band

    // block pruning; get the amount of disk space (in MiB) to allot for block & undo files
    int64_t nPruneArg = gArgs.GetArg("-prune", 0);
    if (nPruneArg < 0) {
        return InitError(_("Prune cannot be configured with a negative value."));
    }
    nPruneTarget = (uint64_t) nPruneArg * 1024 * 1024;
    if (nPruneArg == 1) {  // manual pruning: -prune=1
        LogPrintf("Block pruning enabled.  Use RPC call pruneblockchain(height) to manually prune block and undo files.\n");
        nPruneTarget = std::numeric_limits<uint64_t>::max();
        fPruneMode = true;
    } else if (nPruneTarget) {
        if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) {
            return InitError(strprintf(_("Prune configured below the minimum of %d MiB.  Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024));
        }
        LogPrintf("Prune configured to target %uMiB on disk for block and undo files.\n", nPruneTarget / 1024 / 1024);
        fPruneMode = true;
    }
// Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
// At 1MB per block, 288 blocks = 288MB.
// Add 15% for Undo data = 331MB
// Add 20% for Orphan block rate = 397MB
// We want the low water mark after pruning to be at least 397 MB and since we prune in
// full block file chunks, we need the high water mark which triggers the prune to be
// one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
// Setting the target to > than 550MB will make it likely we can respect the target.
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
// If pruning, don't inv blocks unless we have on disk and are likely to still have
// for some reasonable time window (1 hour) that block relay might require.
const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus().nPowTargetSpacing;
if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
{
    LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
    break;
}
/** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of chainActive.Tip() will not be pruned. */
static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
shohu commented 6 years ago
bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &state, FlushStateMode mode, int nManualPruneHeight) {
    int64_t nMempoolUsage = mempool.DynamicMemoryUsage();
    LOCK(cs_main);
    static int64_t nLastWrite = 0;
    static int64_t nLastFlush = 0;
    static int64_t nLastSetChain = 0;
    std::set<int> setFilesToPrune;
    bool fFlushForPrune = false;
    bool fDoFullFlush = false;
    int64_t nNow = 0;
    try {
    {
        LOCK(cs_LastBlockFile);
        if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && !fReindex) {
            if (nManualPruneHeight > 0) {
                FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
            } else {
                FindFilesToPrune(setFilesToPrune, chainparams.PruneAfterHeight());
                fCheckForPruning = false;
            }
            if (!setFilesToPrune.empty()) {
                fFlushForPrune = true;
                if (!fHavePruned) {
                    pblocktree->WriteFlag("prunedblockfiles", true);
                    fHavePruned = true;
                }
            }
        }
/* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight)
{
    assert(fPruneMode && nManualPruneHeight > 0);

    LOCK2(cs_main, cs_LastBlockFile);
    if (chainActive.Tip() == nullptr)
        return;

    // last block to prune is the lesser of (user-specified height, MIN_BLOCKS_TO_KEEP from the tip)
    unsigned int nLastBlockWeCanPrune = std::min((unsigned)nManualPruneHeight, chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP);
    int count=0;
    for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
        if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
            continue;
        PruneOneBlockFile(fileNumber);
        setFilesToPrune.insert(fileNumber);
        count++;
    }
    LogPrintf("Prune (Manual): prune_height=%d removed %d blk/rev pairs\n", nLastBlockWeCanPrune, count);
}
/**
 * Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.
 * The user sets the target (in MB) on the command line or in config file.  This will be run on startup and whenever new
 * space is allocated in a block or undo file, staying below the target. Changing back to unpruned requires a reindex
 * (which in this case means the blockchain must be re-downloaded.)
 *
 * Pruning functions are called from FlushStateToDisk when the global fCheckForPruning flag has been set.
 * Block and undo files are deleted in lock-step (when blk00003.dat is deleted, so is rev00003.dat.)
 * Pruning cannot take place until the longest chain is at least a certain length (100000 on mainnet, 1000 on testnet, 1000 on regtest).
 * Pruning will never delete a block within a defined distance (currently 288) from the active chain's tip.
 * The block index is updated by unsetting HAVE_DATA and HAVE_UNDO for any blocks that were stored in the deleted files.
 * A db flag records the fact that at least some block files have been pruned.
 *
 * @param[out]   setFilesToPrune   The set of file indices that can be unlinked will be returned
 */
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
{
    LOCK2(cs_main, cs_LastBlockFile);
    if (chainActive.Tip() == nullptr || nPruneTarget == 0) {
        return;
    }
    if ((uint64_t)chainActive.Tip()->nHeight <= nPruneAfterHeight) {
        return;
    }

    unsigned int nLastBlockWeCanPrune = chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP;
    uint64_t nCurrentUsage = CalculateCurrentUsage();
    // We don't check to prune until after we've allocated new space for files
    // So we should leave a buffer under our target to account for another allocation
    // before the next pruning.
    uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE;
    uint64_t nBytesToPrune;
    int count=0;

    if (nCurrentUsage + nBuffer >= nPruneTarget) {
        for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
            nBytesToPrune = vinfoBlockFile[fileNumber].nSize + vinfoBlockFile[fileNumber].nUndoSize;

            if (vinfoBlockFile[fileNumber].nSize == 0)
                continue;

            if (nCurrentUsage + nBuffer < nPruneTarget)  // are we below our target?
                break;

            // don't prune files that could have a block within MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning
            if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
                continue;

            PruneOneBlockFile(fileNumber);
            // Queue up the files for removal
            setFilesToPrune.insert(fileNumber);
            nCurrentUsage -= nBytesToPrune;
            count++;
        }
    }

    LogPrint(BCLog::PRUNE, "Prune: target=%dMiB actual=%dMiB diff=%dMiB max_prune_height=%d removed %d blk/rev pairs\n",
           nPruneTarget/1024/1024, nCurrentUsage/1024/1024,
           ((int64_t)nPruneTarget - (int64_t)nCurrentUsage)/1024/1024,
           nLastBlockWeCanPrune, count);
}
/* Prune a block file (modify associated database entries)*/
void PruneOneBlockFile(const int fileNumber)
{
    for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it) {
        CBlockIndex* pindex = it->second;
        if (pindex->nFile == fileNumber) {
            pindex->nStatus &= ~BLOCK_HAVE_DATA;
            pindex->nStatus &= ~BLOCK_HAVE_UNDO;
            pindex->nFile = 0;
            pindex->nDataPos = 0;
            pindex->nUndoPos = 0;
            setDirtyBlockIndex.insert(pindex);

            // Prune from mapBlocksUnlinked -- any block we prune would have
            // to be downloaded again in order to consider its chain, at which
            // point it would be considered as a candidate for
            // mapBlocksUnlinked or setBlockIndexCandidates.
            std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex->pprev);
            while (range.first != range.second) {
                std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first;
                range.first++;
                if (_it->second == pindex) {
                    mapBlocksUnlinked.erase(_it);
                }
            }
        }
    }

    vinfoBlockFile[fileNumber].SetNull();
    setDirtyFileInfo.insert(fileNumber);
}
shohu commented 6 years ago
/** The maximum size of a blk?????.dat file (since 0.8) */
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
/** The pre-allocation chunk size for rev?????.dat files (since 0.8) */
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
/* Calculate the amount of disk space the block & undo files currently use */
static uint64_t CalculateCurrentUsage()
{
    uint64_t retval = 0;
    for (const CBlockFileInfo &file : vinfoBlockFile) {
        retval += file.nSize + file.nUndoSize;
    }
    return retval;
}
shohu commented 6 years ago

Insert log . check prune logic

static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
{
    LOCK2(cs_main, cs_LastBlockFile);
    if (chainActive.Tip() == nullptr || nPruneTarget == 0) {
        return;
    }
    if ((uint64_t)chainActive.Tip()->nHeight <= nPruneAfterHeight) {
        return;
    }

    unsigned int nLastBlockWeCanPrune = chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP;
    uint64_t nCurrentUsage = CalculateCurrentUsage();
    // We don't check to prune until after we've allocated new space for files
    // So we should leave a buffer under our target to account for another allocation
    // before the next pruning.
    uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE;
    uint64_t nBytesToPrune;
    int count=0;

    LogPrintf("MMMMMMMMM %d >= %d. nCurrentUsage = %d, nBuffer = %d, nPruneTarget = %d\n", nCurrentUsage + nBuffer, nPruneTarget, nCurrentUsage, nBuffer, nPruneTarget);
    if (nCurrentUsage + nBuffer >= nPruneTarget) {
        for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
            nBytesToPrune = vinfoBlockFile[fileNumber].nSize + vinfoBlockFile[fileNumber].nUndoSize;

            if (vinfoBlockFile[fileNumber].nSize == 0){
                LogPrintf("MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0\n");
                continue;
            }

            if (nCurrentUsage + nBuffer < nPruneTarget) {  // are we below our target?
                LogPrintf("MMMMMMMMM nCurrentUsage + nBuffer (%d) < nPruneTarget(%d)\n", nCurrentUsage + nBuffer, nPruneTarget);
                break;
            }

            // don't prune files that could have a block within MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning
            if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) {
                LogPrintf("MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(%d) > nLastBlockWeCanPrune(%d)\n", vinfoBlockFile[fileNumber].nHeightLast, nLastBlockWeCanPrune);
                continue;
            }

            LogPrintf("MMMMMMMMM PruneOneBlockFile(%d)\n", fileNumber);
            PruneOneBlockFile(fileNumber);
            // Queue up the files for removal
            setFilesToPrune.insert(fileNumber);
            nCurrentUsage -= nBytesToPrune;
            count++;
        }
    }

output

2018-04-06 07:17:04.411872 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:04.411884 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:04.411897 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:04.411909 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:04.411922 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1044) > nLastBlockWeCanPrune(745)
2018-04-06 07:17:04.411935 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(745)
2018-04-06 07:17:04.411947 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1175) > nLastBlockWeCanPrune(745)
2018-04-06 07:17:04.411960 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1248) > nLastBlockWeCanPrune(745)
2018-04-06 07:17:04.411972 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(745)
2018-04-06 07:17:11.254355 MMMMMMMMM 696859469 >= 576716800. nCurrentUsage = 679033677, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:17:11.254381 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:11.254396 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:11.254410 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:11.254424 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:11.254438 MMMMMMMMM PruneOneBlockFile(4)
2018-04-06 07:17:11.254693 MMMMMMMMM nCurrentUsage + nBuffer (563228899) < nPruneTarget(576716800)
2018-04-06 07:17:16.687911 MMMMMMMMM 583194909 >= 576716800. nCurrentUsage = 565369117, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:17:16.687942 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:16.687960 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:16.687976 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:16.687991 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:16.688006 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:16.688022 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1050)
2018-04-06 07:17:16.688037 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1175) > nLastBlockWeCanPrune(1050)
2018-04-06 07:17:16.688052 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1248) > nLastBlockWeCanPrune(1050)
2018-04-06 07:17:16.688067 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1050)
2018-04-06 07:17:53.661763 MMMMMMMMM 815006969 >= 576716800. nCurrentUsage = 797181177, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:17:53.661778 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:53.661792 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:53.661806 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:53.661820 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:53.661834 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:17:53.661848 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1108)
2018-04-06 07:17:53.661862 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1175) > nLastBlockWeCanPrune(1108)
2018-04-06 07:17:53.661876 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1248) > nLastBlockWeCanPrune(1108)
2018-04-06 07:17:53.661889 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1108)
2018-04-06 07:17:53.661903 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1363) > nLastBlockWeCanPrune(1108)
2018-04-06 07:17:53.661917 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1398) > nLastBlockWeCanPrune(1108)
2018-04-06 07:09:07.781405 Prune: target=550MiB actual=462MiB diff=87MiB max_prune_height=714 removed 1 blk/rev pairs
2018-04-06 07:09:07.805292 Prune: UnlinkPrunedFiles deleted blk/rev (00000)
2018-04-06 07:09:34.805097 Prune: target=550MiB actual=479MiB diff=70MiB max_prune_height=732 removed 0 blk/rev pairs
2018-04-06 07:09:41.744299 Prune: target=550MiB actual=494MiB diff=55MiB max_prune_height=749 removed 0 blk/rev pairs
2018-04-06 07:09:55.379347 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=756 removed 0 blk/rev pairs
2018-04-06 07:09:56.029095 Prune: target=550MiB actual=522MiB diff=27MiB max_prune_height=743 removed 0 blk/rev pairs
2018-04-06 07:10:17.679368 Prune: target=550MiB actual=526MiB diff=23MiB max_prune_height=757 removed 0 blk/rev pairs
2018-04-06 07:10:18.576766 Prune: target=550MiB actual=416MiB diff=133MiB max_prune_height=762 removed 1 blk/rev pairs
2018-04-06 07:10:18.626543 Prune: UnlinkPrunedFiles deleted blk/rev (00001)
2018-04-06 07:10:29.563887 Prune: target=550MiB actual=431MiB diff=118MiB max_prune_height=781 removed 0 blk/rev pairs
2018-04-06 07:10:51.562037 Prune: target=550MiB actual=446MiB diff=103MiB max_prune_height=783 removed 0 blk/rev pairs
2018-04-06 07:11:02.797237 Prune: target=550MiB actual=462MiB diff=87MiB max_prune_height=806 removed 0 blk/rev pairs
2018-04-06 07:11:03.032093 Prune: target=550MiB actual=479MiB diff=70MiB max_prune_height=806 removed 0 blk/rev pairs
2018-04-06 07:11:26.900484 Prune: target=550MiB actual=494MiB diff=55MiB max_prune_height=809 removed 0 blk/rev pairs
2018-04-06 07:11:37.833926 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=831 removed 0 blk/rev pairs
2018-04-06 07:11:38.125074 Prune: target=550MiB actual=526MiB diff=23MiB max_prune_height=831 removed 0 blk/rev pairs
2018-04-06 07:11:38.496945 Prune: target=550MiB actual=527MiB diff=22MiB max_prune_height=812 removed 0 blk/rev pairs
2018-04-06 07:12:02.430099 Prune: target=550MiB actual=415MiB diff=134MiB max_prune_height=835 removed 1 blk/rev pairs
2018-04-06 07:12:02.468912 Prune: UnlinkPrunedFiles deleted blk/rev (00002)
2018-04-06 07:12:11.516256 Prune: target=550MiB actual=431MiB diff=118MiB max_prune_height=856 removed 0 blk/rev pairs
2018-04-06 07:12:36.876973 Prune: target=550MiB actual=448MiB diff=101MiB max_prune_height=857 removed 0 blk/rev pairs
2018-04-06 07:12:37.290253 Prune: target=550MiB actual=463MiB diff=86MiB max_prune_height=861 removed 0 blk/rev pairs
2018-04-06 07:12:47.184284 Prune: target=550MiB actual=479MiB diff=70MiB max_prune_height=881 removed 0 blk/rev pairs
2018-04-06 07:13:13.938782 Prune: target=550MiB actual=496MiB diff=53MiB max_prune_height=883 removed 0 blk/rev pairs
2018-04-06 07:13:14.385510 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=887 removed 0 blk/rev pairs
2018-04-06 07:13:14.416762 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=887 removed 0 blk/rev pairs
2018-04-06 07:13:23.185903 Prune: target=550MiB actual=524MiB diff=25MiB max_prune_height=906 removed 0 blk/rev pairs
2018-04-06 07:13:50.128114 Prune: target=550MiB actual=540MiB diff=9MiB max_prune_height=908 removed 0 blk/rev pairs
2018-04-06 07:14:01.566503 Prune: target=550MiB actual=429MiB diff=120MiB max_prune_height=931 removed 1 blk/rev pairs
2018-04-06 07:14:01.628402 Prune: UnlinkPrunedFiles deleted blk/rev (00003)
2018-04-06 07:14:01.888314 Prune: target=550MiB actual=444MiB diff=105MiB max_prune_height=931 removed 0 blk/rev pairs
2018-04-06 07:14:29.866479 Prune: target=550MiB actual=461MiB diff=88MiB max_prune_height=934 removed 0 blk/rev pairs
2018-04-06 07:14:39.703142 Prune: target=550MiB actual=477MiB diff=72MiB max_prune_height=956 removed 0 blk/rev pairs
2018-04-06 07:14:39.925226 Prune: target=550MiB actual=493MiB diff=56MiB max_prune_height=956 removed 0 blk/rev pairs
2018-04-06 07:15:08.942686 Prune: target=550MiB actual=509MiB diff=40MiB max_prune_height=960 removed 0 blk/rev pairs
2018-04-06 07:15:08.989150 Prune: target=550MiB actual=509MiB diff=40MiB max_prune_height=960 removed 0 blk/rev pairs
2018-04-06 07:15:19.543469 Prune: target=550MiB actual=522MiB diff=27MiB max_prune_height=981 removed 0 blk/rev pairs
2018-04-06 07:15:19.789790 Prune: target=550MiB actual=538MiB diff=11MiB max_prune_height=981 removed 0 blk/rev pairs
2018-04-06 07:15:49.576317 Prune: target=550MiB actual=553MiB diff=-3MiB max_prune_height=985 removed 0 blk/rev pairs
2018-04-06 07:16:00.280452 Prune: target=550MiB actual=570MiB diff=-20MiB max_prune_height=1006 removed 0 blk/rev pairs
2018-04-06 07:16:31.382325 Prune: target=550MiB actual=586MiB diff=-36MiB max_prune_height=1007 removed 0 blk/rev pairs
2018-04-06 07:16:32.015900 Prune: target=550MiB actual=601MiB diff=-51MiB max_prune_height=1011 removed 0 blk/rev pairs
2018-04-06 07:16:42.889756 Prune: target=550MiB actual=618MiB diff=-68MiB max_prune_height=1031 removed 0 blk/rev pairs
2018-04-06 07:17:00.115316 Prune: target=550MiB actual=634MiB diff=-84MiB max_prune_height=1032 removed 0 blk/rev pairs
2018-04-06 07:17:04.411986 Prune: target=550MiB actual=639MiB diff=-89MiB max_prune_height=745 removed 0 blk/rev pairs
2018-04-06 07:17:11.254711 Prune: target=550MiB actual=520MiB diff=29MiB max_prune_height=1045 removed 1 blk/rev pairs
2018-04-06 07:17:11.297176 Prune: UnlinkPrunedFiles deleted blk/rev (00004)
2018-04-06 07:17:16.688082 Prune: target=550MiB actual=539MiB diff=10MiB max_prune_height=1050 removed 0 blk/rev pairs
2018-04-06 07:17:20.941600 Prune: target=550MiB actual=554MiB diff=-4MiB max_prune_height=1054 removed 0 blk/rev pairs
2018-04-06 07:17:23.599115 Prune: target=550MiB actual=569MiB diff=-19MiB max_prune_height=1058 removed 0 blk/rev pairs
2018-04-06 07:17:25.774563 Prune: target=550MiB actual=584MiB diff=-34MiB max_prune_height=1062 removed 0 blk/rev pairs
2018-04-06 07:17:29.021594 Prune: target=550MiB actual=600MiB diff=-50MiB max_prune_height=1066 removed 0 blk/rev pairs
2018-04-06 07:17:33.256460 Prune: target=550MiB actual=619MiB diff=-69MiB max_prune_height=1071 removed 0 blk/rev pairs
2018-04-06 07:17:35.519302 Prune: target=550MiB actual=634MiB diff=-84MiB max_prune_height=1075 removed 0 blk/rev pairs
2018-04-06 07:17:35.596100 Prune: target=550MiB actual=634MiB diff=-84MiB max_prune_height=1075 removed 0 blk/rev pairs
2018-04-06 07:17:38.875768 Prune: target=550MiB actual=649MiB diff=-99MiB max_prune_height=1079 removed 0 blk/rev pairs
2018-04-06 07:17:40.918704 Prune: target=550MiB actual=664MiB diff=-114MiB max_prune_height=1083 removed 0 blk/rev pairs
2018-04-06 07:17:43.140785 Prune: target=550MiB actual=680MiB diff=-130MiB max_prune_height=1087 removed 0 blk/rev pairs
2018-04-06 07:17:45.358699 Prune: target=550MiB actual=695MiB diff=-145MiB max_prune_height=1091 removed 0 blk/rev pairs
2018-04-06 07:17:47.799043 Prune: target=550MiB actual=714MiB diff=-164MiB max_prune_height=1096 removed 0 blk/rev pairs
2018-04-06 07:17:49.794864 Prune: target=550MiB actual=729MiB diff=-179MiB max_prune_height=1100 removed 0 blk/rev pairs
2018-04-06 07:17:51.533463 Prune: target=550MiB actual=744MiB diff=-194MiB max_prune_height=1104 removed 0 blk/rev pairs
2018-04-06 07:17:53.576406 Prune: target=550MiB actual=760MiB diff=-210MiB max_prune_height=1108 removed 0 blk/rev pairs
2018-04-06 07:17:53.661931 Prune: target=550MiB actual=760MiB diff=-210MiB max_prune_height=1108 removed 0 blk/rev pairs
shohu commented 6 years ago

bitcoin output

2018-04-06 08:04:54.706919 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1044) > nLastBlockWeCanPrune(755)
2018-04-06 08:04:54.706932 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(755)
2018-04-06 08:04:54.706946 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(755)
2018-04-06 08:04:54.706958 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(755)
2018-04-06 08:04:54.706971 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(755)
2018-04-06 08:06:34.805308 MMMMMMMMM 703079437 >= 576716800. nCurrentUsage = 685253645, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:34.805410 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:34.805447 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:34.805468 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:34.805486 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:34.805505 MMMMMMMMM PruneOneBlockFile(4)
2018-04-06 08:06:34.805981 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1058)
2018-04-06 08:06:34.806019 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(1058)
2018-04-06 08:06:34.806039 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1058)
2018-04-06 08:06:34.806056 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1058)
2018-04-06 08:06:42.398211 MMMMMMMMM 586510384 >= 576716800. nCurrentUsage = 568684592, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:42.398259 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:42.398464 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:42.398490 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:42.398771 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:42.398801 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:42.398824 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1075)
2018-04-06 08:06:42.398842 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(1075)
2018-04-06 08:06:42.399196 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1075)
2018-04-06 08:06:42.399226 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1075)
2018-04-06 08:06:48.277223 MMMMMMMMM 603570539 >= 576716800. nCurrentUsage = 585744747, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:48.277249 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:48.277268 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:48.277285 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:48.277301 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:48.277317 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:48.277333 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1094)
2018-04-06 08:06:48.277350 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(1094)
2018-04-06 08:06:48.277366 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1094)
2018-04-06 08:06:48.277382 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1094)
2018-04-06 08:06:52.671015 MMMMMMMMM 619682500 >= 576716800. nCurrentUsage = 601856708, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:52.671040 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:52.671056 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:52.671071 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:52.671085 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:52.671099 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:52.671114 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1119) > nLastBlockWeCanPrune(1111)
2018-04-06 08:06:52.671132 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(1111)
2018-04-06 08:06:52.671146 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1111)
2018-04-06 08:06:52.671161 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1111)
2018-04-06 08:06:53.754718 MMMMMMMMM 636742275 >= 576716800. nCurrentUsage = 618916483, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:53.754780 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:53.754805 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:53.754840 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:53.754890 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:53.754916 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:06:53.754940 MMMMMMMMM PruneOneBlockFile(5)
2018-04-06 08:06:53.755305 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1193) > nLastBlockWeCanPrune(1129)
2018-04-06 08:06:53.755344 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1129)
2018-04-06 08:06:53.755369 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1129)
2018-04-06 08:06:55.413294 MMMMMMMMM 520182029 >= 576716800. nCurrentUsage = 502356237, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:56.942424 MMMMMMMMM 536294072 >= 576716800. nCurrentUsage = 518468280, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:58.014131 MMMMMMMMM 553353901 >= 576716800. nCurrentUsage = 535528109, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:58.028586 MMMMMMMMM 553354334 >= 576716800. nCurrentUsage = 535528542, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:06:59.044385 MMMMMMMMM 569465975 >= 576716800. nCurrentUsage = 551640183, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:07:00.332997 MMMMMMMMM 586525820 >= 576716800. nCurrentUsage = 568700028, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:07:00.333024 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333041 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333056 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333071 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333086 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333100 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 08:07:00.333114 MMMMMMMMM PruneOneBlockFile(6)
2018-04-06 08:07:00.333340 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1262) > nLastBlockWeCanPrune(1217)
2018-04-06 08:07:00.333358 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1320) > nLastBlockWeCanPrune(1217)
2018-04-06 08:07:00.333372 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(1470) > nLastBlockWeCanPrune(1217)
2018-04-06 08:07:01.482252 MMMMMMMMM 469965940 >= 576716800. nCurrentUsage = 452140148, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:07:02.562888 MMMMMMMMM 486078063 >= 576716800. nCurrentUsage = 468252271, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 08:01:36.088874 Prune: target=550MiB actual=431MiB diff=118MiB max_prune_height=931 removed 0 blk/rev pairs
2018-04-06 08:01:36.405031 Prune: target=550MiB actual=446MiB diff=103MiB max_prune_height=931 removed 0 blk/rev pairs
2018-04-06 08:02:05.797460 Prune: target=550MiB actual=462MiB diff=87MiB max_prune_height=945 removed 0 blk/rev pairs
2018-04-06 08:02:17.489467 Prune: target=550MiB actual=478MiB diff=71MiB max_prune_height=956 removed 0 blk/rev pairs
2018-04-06 08:02:17.695361 Prune: target=550MiB actual=494MiB diff=55MiB max_prune_height=956 removed 0 blk/rev pairs
2018-04-06 08:02:49.994566 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=974 removed 0 blk/rev pairs
2018-04-06 08:02:50.087198 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=974 removed 0 blk/rev pairs
2018-04-06 08:03:01.452429 Prune: target=550MiB actual=525MiB diff=24MiB max_prune_height=981 removed 0 blk/rev pairs
2018-04-06 08:03:33.582442 Prune: target=550MiB actual=542MiB diff=7MiB max_prune_height=985 removed 0 blk/rev pairs
2018-04-06 08:03:34.570762 Prune: target=550MiB actual=558MiB diff=-8MiB max_prune_height=1003 removed 0 blk/rev pairs
2018-04-06 08:03:46.037821 Prune: target=550MiB actual=573MiB diff=-23MiB max_prune_height=1006 removed 0 blk/rev pairs
2018-04-06 08:04:18.911091 Prune: target=550MiB actual=590MiB diff=-40MiB max_prune_height=1014 removed 0 blk/rev pairs
2018-04-06 08:04:32.346446 Prune: target=550MiB actual=606MiB diff=-56MiB max_prune_height=1031 removed 0 blk/rev pairs
2018-04-06 08:04:32.650765 Prune: target=550MiB actual=621MiB diff=-71MiB max_prune_height=1031 removed 0 blk/rev pairs
2018-04-06 08:04:50.648555 Prune: target=550MiB actual=638MiB diff=-88MiB max_prune_height=1032 removed 0 blk/rev pairs
2018-04-06 08:04:54.706985 Prune: target=550MiB actual=639MiB diff=-89MiB max_prune_height=755 removed 0 blk/rev pairs
2018-04-06 08:06:34.806074 Prune: target=550MiB actual=653MiB diff=-103MiB max_prune_height=1058 removed 1 blk/rev pairs
2018-04-06 08:06:34.856842 Prune: UnlinkPrunedFiles deleted blk/rev (00004)
2018-04-06 08:06:42.399245 Prune: target=550MiB actual=542MiB diff=7MiB max_prune_height=1075 removed 0 blk/rev pairs
2018-04-06 08:06:48.277399 Prune: target=550MiB actual=558MiB diff=-8MiB max_prune_height=1094 removed 0 blk/rev pairs
2018-04-06 08:06:52.671176 Prune: target=550MiB actual=573MiB diff=-23MiB max_prune_height=1111 removed 0 blk/rev pairs
2018-04-06 08:06:53.755395 Prune: target=550MiB actual=590MiB diff=-40MiB max_prune_height=1129 removed 1 blk/rev pairs
2018-04-06 08:06:53.993628 Prune: UnlinkPrunedFiles deleted blk/rev (00005)
2018-04-06 08:06:55.413344 Prune: target=550MiB actual=479MiB diff=70MiB max_prune_height=1147 removed 0 blk/rev pairs
2018-04-06 08:06:56.942458 Prune: target=550MiB actual=494MiB diff=55MiB max_prune_height=1164 removed 0 blk/rev pairs
2018-04-06 08:06:58.014161 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=1182 removed 0 blk/rev pairs
2018-04-06 08:06:58.028614 Prune: target=550MiB actual=510MiB diff=39MiB max_prune_height=1182 removed 0 blk/rev pairs
2018-04-06 08:06:59.044411 Prune: target=550MiB actual=526MiB diff=23MiB max_prune_height=1199 removed 0 blk/rev pairs
2018-04-06 08:07:00.333394 Prune: target=550MiB actual=542MiB diff=7MiB max_prune_height=1217 removed 1 blk/rev pairs
2018-04-06 08:07:00.410827 Prune: UnlinkPrunedFiles deleted blk/rev (00006)
2018-04-06 08:07:01.482283 Prune: target=550MiB actual=431MiB diff=118MiB max_prune_height=1235 removed 0 blk/rev pairs
2018-04-06 08:07:02.562919 Prune: target=550MiB actual=446MiB diff=103MiB max_prune_height=1252 removed 0 blk/rev pairs
shohu commented 6 years ago

Firstlog

The first log actualfile size is different...

c0ban

Prune: target=550MiB actual=462MiB diff=87MiB max_prune_height=714 removed 1 blk/rev pairs
2018-04-06 07:09:07.781220 MMMMMMMMM 636807615 >= 576716800. nCurrentUsage = 618981823, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:09:07.781243 MMMMMMMMM PruneOneBlockFile(0)
2018-04-06 07:09:07.781390 MMMMMMMMM nCurrentUsage + nBuffer (503079957) < nPruneTarget(576716800)
2018-04-06 07:09:34.805075 MMMMMMMMM 520139283 >= 576716800. nCurrentUsage = 502313491, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:09:41.744276 MMMMMMMMM 536247498 >= 576716800. nCurrentUsage = 518421706, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:09:55.379322 MMMMMMMMM 553302386 >= 576716800. nCurrentUsage = 535476594, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:09:56.029080 MMMMMMMMM 565622791 >= 576716800. nCurrentUsage = 547796999, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:10:17.679338 MMMMMMMMM 569618193 >= 576716800. nCurrentUsage = 551792401, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:10:18.576585 MMMMMMMMM 588364114 >= 576716800. nCurrentUsage = 570538322, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:10:18.576614 MMMMMMMMM vinfoBlockFile[fileNumber].nSize == 0
2018-04-06 07:10:18.576632 MMMMMMMMM PruneOneBlockFile(1)

bitcoin

Prune: target=550MiB actual=590MiB diff=-40MiB max_prune_height=714 removed 2 blk/rev pairs
2018-04-06 07:56:14.874824 MMMMMMMMM 636798040 >= 576716800. nCurrentUsage = 618972248, nBuffer = 17825792, nPruneTarget = 576716800
2018-04-06 07:56:14.874844 MMMMMMMMM PruneOneBlockFile(0)
2018-04-06 07:56:14.874999 MMMMMMMMM PruneOneBlockFile(1)
2018-04-06 07:56:14.875047 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(773) > nLastBlockWeCanPrune(714)
2018-04-06 07:56:14.875061 MMMMMMMMM vinfoBlockFile[fileNumber].nHeightLast(914) > nLastBlockWeCanPrune(714)
2018-04-06 07:56:42.140749 MMMMMMMMM 386498920 >= 576716800. nCurrentUsage = 368673128, nBuffer = 17825792, nPruneTarget = 576716800
shohu commented 6 years ago
static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize)
{
    pos.nFile = nFile;

    LOCK(cs_LastBlockFile);

    unsigned int nNewSize;
    pos.nPos = vinfoBlockFile[nFile].nUndoSize;
    nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize;
    // Write undo information to disk
    if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS))
    {
        if (pindex->GetUndoPos().IsNull()) {
            CDiskBlockPos _pos;
            if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
                return error("ConnectBlock(): FindUndoPos failed");
            if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart()))
                return AbortNode(state, "Failed to write undo data");

            // update nUndoPos in block index
            pindex->nUndoPos = _pos.nPos;
            pindex->nStatus |= BLOCK_HAVE_UNDO;
        }

        pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
        setDirtyBlockIndex.insert(pindex);
    }
template <typename T>
size_t GetSerializeSize(const T& t, int nType, int nVersion = 0)
{
    return (CSizeComputer(nType, nVersion) << t).size();
}
shohu commented 6 years ago

I will try to change "num" from 14 to 60 But local pc is low spec. so I will try to it on cloud

def mine_large_block(node, utxos=None):
    # generate a 66k transaction,
    # and 14 of them is close to the 1MB block limit
    num = 14
    txouts = gen_return_txouts()
    utxos = utxos if utxos is not None else []
    if len(utxos) < num:
        utxos.clear()
        utxos.extend(node.listunspent())
    fee = 100 * node.getnetworkinfo()["relayfee"]
    create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
    node.generate(1)
shohu commented 6 years ago

Change code for cloud test 2018-04-06 18 30 30

shohu commented 6 years ago

add generate block because array index error was occured at mine_large_block "num = 60"

2018-04-09 14 22 33

shohu commented 6 years ago

GKE forced termination program...

# nohup test/functional/pruning.py &
# tail -f nohup.out
2018-04-09 05:20:39.868000 TestFramework (INFO): Initializing test directory /tmp/test18wrdnb5
2018-04-09 05:20:41.250000 TestFramework (INFO): Warning! This test requires 4GB of disk space and takes over 30 mins (up to 2 hours)
2018-04-09 05:20:41.250000 TestFramework (INFO): Mining a big blockchain of 995 blocks
command terminated with exit code 137