test: XORed blocks test follow up #30669

pull tdb3 wants to merge 6 commits into bitcoin:master from tdb3:20240817_test_new_xor_dat_created changing 4 files +22 −13
  1. tdb3 commented at 9:59 PM on August 17, 2024: contributor

    Builds on PR #30657.

    Refactors read_xor_key() from util.py to test_node.py (comment #30657 (review))

    Adds a check that xor.dat is created when missing (comment #30657 (review))

    Help states:

    -blocksxor
           Whether an XOR-key applies to blocksdir *.dat files. The created XOR-key
           will be zeros for an existing blocksdir or when `-blocksxor=0` is
           set, and random for a freshly initialized blocksdir. (default: 1)
    
  2. DrahtBot commented at 9:59 PM on August 17, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, theStack, brunoerg, achow101
    Stale ACK danielabrozzoni, glozow

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Tests on Aug 17, 2024
  4. danielabrozzoni approved
  5. danielabrozzoni commented at 11:59 AM on August 19, 2024: contributor

    tACK 07365d026127eb8435e7919a7793bd25d7f3ceca

  6. in test/functional/feature_blocksxor.py:64 in 07365d0261 outdated
      59 | @@ -59,6 +60,8 @@ def run_test(self):
      60 |          # checklevel=2 -> verify block validity + undo data
      61 |          # nblocks=0    -> verify all blocks
      62 |          node.verifychain(checklevel=2, nblocks=0)
      63 | +        self.log.info("Check that xor.dat is recreated")
      64 | +        assert read_xor_key(node=node) == NULL_BLK_XOR_KEY
    


    brunoerg commented at 2:51 PM on August 19, 2024:
            assert_equal(read_xor_key(node=node), NULL_BLK_XOR_KEY)
    

    tdb3 commented at 9:12 PM on August 19, 2024:

    Thanks for reviewing. Implemented

  7. tdb3 force-pushed on Aug 19, 2024
  8. tdb3 commented at 10:17 PM on August 19, 2024: contributor

    Thanks @danielabrozzoni and @brunoerg. Pushed an update to address comments, and clarified the log message.

  9. in test/functional/test_framework/util.py:395 in a214174324 outdated
     390 | @@ -391,6 +391,8 @@ def rpc_url(datadir, i, chain, rpchost):
     391 |  # The size of the blocks xor key,
     392 |  # from InitBlockdirXorKey::xor_key.size()
     393 |  NUM_XOR_BYTES = 8
     394 | +# The null block key (all 0s)
     395 | +NULL_BLK_XOR_KEY = bytes(NUM_XOR_BYTES)
    


    theStack commented at 1:48 PM on August 20, 2024:

    nit, personally I prefer to be explicit about the zeroes initialization, but no big deal

    NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES)
    

    tdb3 commented at 12:31 AM on August 21, 2024:

    lgtm, added.

  10. theStack approved
  11. theStack commented at 1:51 PM on August 20, 2024: contributor

    ACK 7b7c287a33dc0c6f09bf32f31a8f05941b0cc9a2

    Thanks for following up! If you want, you could also tackle the suggestion to move the read_xor_key helper to the TestNode class, see #30657 (review)

  12. DrahtBot requested review from danielabrozzoni on Aug 20, 2024
  13. glozow commented at 3:57 PM on August 20, 2024: member

    ACK 7b7c287a33dc0c6f09bf32f31a8f05941b0cc9a2

  14. brunoerg approved
  15. brunoerg commented at 8:07 PM on August 20, 2024: contributor

    ACK 7b7c287a33dc0c6f09bf32f31a8f05941b0cc9a2

  16. tdb3 commented at 12:34 AM on August 21, 2024: contributor

    If you want, you could also tackle the suggestion to move the read_xor_key helper to the TestNode class, see #30657 (comment)

    Thanks for the suggestion! This PR seems to be a reasonable place to perform the move, so I updated it to include this. Happy to make tweaks if you or @maflcko have any further suggestions.

  17. tdb3 force-pushed on Aug 21, 2024
  18. tdb3 renamed this:
    test: check xor.dat creation when missing
    test: XORed blocks test follow up
    on Aug 21, 2024
  19. in test/functional/test_framework/test_node.py:479 in a20789ed14 outdated
     468 | @@ -469,6 +469,12 @@ def blocks_path(self) -> Path:
     469 |      def blocks_key_path(self) -> Path:
     470 |          return self.blocks_path / "xor.dat"
     471 |  
     472 | +    @property
     473 | +    def read_xor_key(self) -> bytes:
     474 | +        with open(self.blocks_key_path, "rb") as xor_f:
     475 | +            NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size()
     476 | +            return xor_f.read(NUM_XOR_BYTES)
    


    theStack commented at 9:21 PM on August 22, 2024:

    Not sure if there are guidelines for this (and if yes, how strict we are), but I would tend to avoid using the "property" decorator for non-trivial methods that access state outside of the class (in this case, by interacting with the file system). At least I wouldn't expect as user that accessing a class field ever involves any I/O. I think dropping the property and keeping the name as-is "read_xor_key" might be just fine?


    tdb3 commented at 5:17 PM on August 23, 2024:

    Updated

  20. in test/functional/feature_blocksxor.py:59 in a20789ed14 outdated
      52 | @@ -54,7 +53,7 @@ def run_test(self):
      53 |              match=ErrorMatch.PARTIAL_REGEX)
      54 |  
      55 |          self.log.info("Delete XOR key, restart node with '-blocksxor=0', check blk*.dat/rev*.dat file integrity")
      56 | -        os.remove(node.blocks_path / 'xor.dat')
      57 | +        os.remove(node.blocks_key_path)
    


    theStack commented at 9:22 PM on August 22, 2024:

    nit: could put this already into the commit that introduces the blocks_key_path property to TestNode.


    tdb3 commented at 5:17 PM on August 23, 2024:

    Yup, that is more coherent. Updated.

  21. test: add blocks_key_path
    Adds a convenience function to TestNode
    to provide the path to the blocks xor key.
    Updates util and feature_blocksxor to use it.
    c8176f758b
  22. tdb3 force-pushed on Aug 23, 2024
  23. in test/functional/test_framework/test_node.py:47 in 01d4e5d32e outdated
      42 | @@ -43,6 +43,9 @@
      43 |  )
      44 |  
      45 |  BITCOIND_PROC_WAIT_TIMEOUT = 60
      46 | +# The size of the blocks xor key
      47 | +# from InitBlockdirXorKey::xor_key.size()
    


    theStack commented at 11:19 PM on August 24, 2024:

    an 's' got lost on the move up

    # from InitBlocksdirXorKey::xor_key.size()
    

    tdb3 commented at 11:30 PM on August 24, 2024:

    Thanks. Fixed.

  24. theStack approved
  25. theStack commented at 11:22 PM on August 24, 2024: contributor

    ACK ab9d2451c47fd30abecaea3f8d8a6e33541911d7

  26. DrahtBot requested review from glozow on Aug 24, 2024
  27. DrahtBot requested review from brunoerg on Aug 24, 2024
  28. tdb3 force-pushed on Aug 24, 2024
  29. theStack approved
  30. theStack commented at 11:32 PM on August 24, 2024: contributor

    re-ACK 1c403af92be13cbdfa6ab1906f8cc34fabc21e63

  31. refactor: use unlink rather than os.remove d43948c3ef
  32. refactor: move read_xor_key() to TestNode d8399584dd
  33. refactor: lift NUM_XOR_BYTES 1ad999b9da
  34. test: add null block xor key d1610962bf
  35. test: check xor.dat recreated when missing e1d5dd732d
  36. in test/functional/feature_blocksxor.py:59 in 1c403af92b outdated
      55 | @@ -54,11 +56,13 @@ def run_test(self):
      56 |              match=ErrorMatch.PARTIAL_REGEX)
      57 |  
      58 |          self.log.info("Delete XOR key, restart node with '-blocksxor=0', check blk*.dat/rev*.dat file integrity")
      59 | -        os.remove(node.blocks_path / 'xor.dat')
      60 | +        os.remove(node.blocks_key_path)
    


    maflcko commented at 10:08 AM on August 25, 2024:

    style nit, while touching this line: The argument is of type Path, so I think you can just call unlink() on it to avoid the os import?


    tdb3 commented at 12:53 PM on August 25, 2024:

    Thanks, that's cleaner. Added.

  37. tdb3 force-pushed on Aug 25, 2024
  38. maflcko commented at 7:32 AM on August 26, 2024: member

    ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b

  39. DrahtBot requested review from theStack on Aug 26, 2024
  40. theStack approved
  41. theStack commented at 8:10 AM on August 26, 2024: contributor

    re-ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b

  42. brunoerg approved
  43. brunoerg commented at 1:43 PM on August 26, 2024: contributor

    reACK e1d5dd732d5dc641faf1dde316275c84b6bb224b

  44. maflcko added this to the milestone 28.0 on Aug 26, 2024
  45. achow101 commented at 6:22 PM on August 26, 2024: member

    ACK e1d5dd732d5dc641faf1dde316275c84b6bb224b

  46. achow101 merged this on Aug 26, 2024
  47. achow101 closed this on Aug 26, 2024

  48. bitcoin locked this on Aug 26, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me