shohu / c0ban

c0ban source tree
MIT License
0 stars 0 forks source link

Pass for p2p-compactblocks.py #35

Closed shohu closed 6 years ago

shohu commented 6 years ago
# test/functional/p2p-compactblocks.py

2018-05-31 06:09:38.931000 TestFramework (INFO): Initializing test directory /tmp/test0zgvfos4
2018-05-31 06:09:39.426000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:15862
2018-05-31 06:09:39.432000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:15863
2018-05-31 06:09:39.433000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:15863
2018-05-31 06:09:39.832000 TestFramework (INFO): Running tests, pre-segwit activation:
2018-05-31 06:09:39.832000 TestFramework (INFO): Testing SENDCMPCT p2p message...
2018-05-31 06:09:42.616000 TestFramework (INFO): Testing compactblock construction...
2018-05-31 06:09:44.162000 TestFramework (INFO): Testing compactblock requests...
2018-05-31 06:10:14.210000 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/p2p-compactblocks.py", line 826, in run_test
    self.test_compactblock_requests(self.nodes[0], self.test_node, 1, False)
  File "test/functional/p2p-compactblocks.py", line 384, in test_compactblock_requests
    wait_until(lambda: "getdata" in test_node.last_message, timeout=30, lock=mininode_lock)
  File "/c0ban/test/functional/test_framework/util.py", line 222, in wait_until
    assert_greater_than(timeout, time.time())
  File "/c0ban/test/functional/test_framework/util.py", line 42, in assert_greater_than
    raise AssertionError("%s <= %s" % (str(thing1), str(thing2)))
AssertionError: 1527747014.1661088 <= 1527747014.2105384
2018-05-31 06:10:14.223000 TestFramework (INFO): Stopping nodes
2018-05-31 06:10:16.476000 TestFramework (WARNING): Not cleaning up dir /tmp/test0zgvfos4
2018-05-31 06:10:16.477000 TestFramework (ERROR): Test failed. Test logging available at /tmp/test0zgvfos4/test_framework.log
shohu commented 6 years ago

debug.log

2018-06-01 03:50:56.891169 ERROR: AcceptBlockHeader: Consensus::CheckBlockHeader: 4e513e788988d31f0ae3b67cc0e9c636e13a1d203cda64c16945828ef971882e, high-hash, proof of work failed (code 16)
shohu commented 6 years ago

c++

static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{
    // Get prev block index
    CBlockIndex* pindexPrev = NULL;
    int nHeight = 0;
    BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
    if (mi != mapBlockIndex.end()) {
        pindexPrev = (*mi).second;
        nHeight = pindexPrev->nHeight + 1;
    }

    // Check proof of work matches claimed amount
    if (fCheckPOW && !CheckProofOfWork(block.GetPoWHash(nHeight >= Params().SwitchLyra2REv2_DGWblock()), block.nBits, consensusParams))
        return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed");

    return true;
}

test

class CompactBlocksTest(BitcoinTestFramework):
    def set_test_params(self):
        self.setup_clean_chain = True
        # Node0 = pre-segwit, node1 = segwit-aware
        self.num_nodes = 2
        extra_args = "-issueprices=22000,22000,22000,22000,22000,22000,22000"
        self.extra_args = [["-vbparams=segwit:0:0", extra_args], ["-txindex", extra_args]]
        self.utxos = []

    def build_block_on_tip(self, node, segwit=False):
        height = node.getblockcount()
        tip = node.getbestblockhash()
        mtp = node.getblockheader(tip)['mediantime']
        block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
        block.nVersion = 4
        if segwit:
            add_witness_commitment(block)
        block.solve()
        return block
shohu commented 6 years ago
    if (fCheckPOW && !CheckProofOfWork(block.GetPoWHash(nHeight >= Params().SwitchLyra2REv2_DGWblock()), block.nBits, consensusParams))

above statement instead of following statetment.

    if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))

but following error

2018-06-01 04:38:00.531693 CreateNewBlock() packages: 0.01ms (0 packages, 0 updated descendants), validity: 0.67ms (total 0.68ms)
2018-06-01 04:38:00.531750 TESTTTTTT222 CheckBlockHeader GetPoWHash height = 200, 6ae670c17febb09286c88d7264a20b23442ac3e539cfd30aa291c6a3229bd03f
2018-06-01 04:38:00.531847 ERROR: ProcessNewBlock: AcceptBlock FAILED
shohu commented 6 years ago

error.log

  File "test/functional/p2p-compactblocks.py", line 826, in run_test
    self.test_compactblock_requests(self.nodes[0], self.test_node, 1, False)

test code

        self.log.info("Testing compactblock requests... ")
        self.test_compactblock_requests(self.nodes[0], self.test_node, 1, False)

error.log

 File "test/functional/p2p-compactblocks.py", line 384, in test_compactblock_requests
    wait_until(lambda: "getdata" in test_node.last_message, timeout=30, lock=mininode_lock)

test code

    # Test that bitcoind requests compact blocks when we announce new blocks
    # via header or inv, and that responding to getblocktxn causes the block
    # to be successfully reconstructed.
    # Post-segwit: upgraded nodes would only make this request of cb-version-2,
    # NODE_WITNESS peers.  Unupgraded nodes would still make this request of
    # any cb-version-1-supporting peer.
    def test_compactblock_requests(self, node, test_node, version, segwit):
        # Try announcing a block with an inv or header, expect a compactblock
        # request
        for announce in ["inv", "header"]:
            block = self.build_block_on_tip(node, segwit=segwit)
            with mininode_lock:
                test_node.last_message.pop("getdata", None)

            if announce == "inv":
                test_node.send_message(msg_inv([CInv(2, block.sha256)]))
                wait_until(lambda: "getheaders" in test_node.last_message, timeout=30, lock=mininode_lock)
                test_node.send_header_for_blocks([block])
            else:
                test_node.send_header_for_blocks([block])
            wait_until(lambda: "getdata" in test_node.last_message, timeout=30, lock=mininode_lock)

The code below is suspicious

test_node.send_message(msg_inv([CInv(2, block.sha256)]))
shohu commented 6 years ago

2018-06-05 12 12 41

shohu commented 6 years ago
  1. I installed lyra2re2_hash (I couldn't find monacoin_scrypt orz)
    pip3 install lyra2re2_hash
  2. I changed to the following source 2018-06-05 15 54 26

I got success !!

# test/functional/p2p-compactblocks.py
2018-06-05 06:49:34.392000 TestFramework (INFO): Initializing test directory /tmp/test7yqcmt7o
2018-06-05 06:49:34.888000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:12490
2018-06-05 06:49:34.888000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:12491
2018-06-05 06:49:34.889000 TestFramework.mininode (INFO): Connecting to Bitcoin Node: 127.0.0.1:12491
2018-06-05 06:49:35.228000 TestFramework (INFO): Running tests, pre-segwit activation:
2018-06-05 06:49:35.229000 TestFramework (INFO): Testing SENDCMPCT p2p message...
2018-06-05 06:49:37.993000 TestFramework (INFO): Testing compactblock construction...
2018-06-05 06:49:39.401000 TestFramework (INFO): Testing compactblock requests...
2018-06-05 06:49:40.683000 TestFramework (INFO): Testing getblocktxn requests...
2018-06-05 06:49:42.565000 TestFramework (INFO): Testing getblocktxn handler...
2018-06-05 06:49:46.261000 TestFramework (INFO): Testing compactblock requests/announcements not at chain tip...
2018-06-05 06:49:48.202000 TestFramework (INFO): Testing handling of incorrect blocktxn responses...
2018-06-05 06:49:49.071000 TestFramework (INFO): Testing end-to-end block relay...
2018-06-05 06:49:49.452000 TestFramework (INFO): Testing handling of invalid compact blocks...
2018-06-05 06:49:50.033000 TestFramework (INFO): Testing reconstructing compact blocks from all peers...
2018-06-05 06:49:50.791000 TestFramework (INFO): Advancing to segwit activation
2018-06-05 06:49:51.843000 TestFramework (INFO): Running tests, post-segwit activation...
2018-06-05 06:49:51.844000 TestFramework (INFO): Testing compactblock construction...
2018-06-05 06:49:54.424000 TestFramework (INFO): Testing compactblock requests (unupgraded node)...
2018-06-05 06:49:55.069000 TestFramework (INFO): Testing getblocktxn requests (unupgraded node)...
2018-06-05 06:49:55.979000 TestFramework (INFO): Syncing nodes...
2018-06-05 06:49:56.030000 TestFramework (INFO): Testing compactblock requests (segwit node)...
2018-06-05 06:49:56.618000 TestFramework (INFO): Testing getblocktxn requests (segwit node)...
2018-06-05 06:49:57.591000 TestFramework (INFO): Testing getblocktxn handler (segwit node should return witnesses)...
2018-06-05 06:50:00.046000 TestFramework (INFO): Testing end-to-end block relay...
2018-06-05 06:50:00.530000 TestFramework (INFO): Testing handling of invalid compact blocks...
2018-06-05 06:50:01.117000 TestFramework (INFO): Testing invalid index in cmpctblock message...
2018-06-05 06:50:01.482000 TestFramework (INFO): Stopping nodes
2018-06-05 06:50:03.597000 TestFramework (INFO): Cleaning up
2018-06-05 06:50:03.603000 TestFramework (INFO): Tests successful
shohu commented 6 years ago

https://github.com/shohu/c0ban/commit/cc35a8965d054f744a5adb6bcc48eab4f6c393a2