Serialization improvements (step 2) #17896

pull sipa wants to merge 3 commits into bitcoin:master from sipa:202001_noncastserial_2 changing 2 files +61 −50
  1. sipa commented at 5:22 pm on January 8, 2020: member

    This is a second carve-out from #10785.

    This introduces a const-correct generic approach for serializing objects using custom serializers (defined separately from the object being serialized), then converts VARINT to use that approach, and then converts chain.h to the new framework (including the new const-correct VARINT macro).

  2. DrahtBot added the label Validation on Jan 8, 2020
  3. DrahtBot commented at 11:23 pm on January 8, 2020: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #10785 (Serialization improvements by sipa)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. laanwj added this to the "Blockers" column in a project

  5. laanwj commented at 12:25 pm on January 13, 2020: member
    Code review ACK 07b43b2de51ed133bfca865e8e8034c66559ca1d
  6. in src/serialize.h:450 in d27cd0a304 outdated
    441@@ -442,6 +442,31 @@ I ReadVarInt(Stream& is)
    442     }
    443 }
    444 
    445+/** Simple wrapper class to serialize objects using a formatter; used by Using(). */
    446+template<typename Formatter, typename T>
    447+class Wrapper
    448+{
    449+protected:
    450+    T& m_object;
    


    ryanofsky commented at 3:57 pm on January 13, 2020:
    Instead of adding & reference here and removing it with std::remove_reference below, maybe this could change from T& to T, and typename std::remove_reference<T>::type below could change to T&

    sipa commented at 4:25 pm on January 13, 2020:
    Nice idea, done.
  7. ryanofsky approved
  8. ryanofsky commented at 4:01 pm on January 13, 2020: member
    Code review ACK 07b43b2de51ed133bfca865e8e8034c66559ca1d. Nice simplification! Feel free to tag me or request review in any future PR’s too, I’m happy to look at these.
  9. Add a generic approach for (de)serialization of objects using code in other classes
    This adds the (internal) Wrapper class, and the Using function that uses it. Given
    a class F that implements Ser(stream, const object&) and Unser(stream, object&)
    functions, this permits writing e.g. READWRITE(Using<F>(object)).
    ca62563df3
  10. Convert VARINT to the formatter/Using approach 2f1b2f4ed0
  11. Convert chain to new serialization 9b66083788
  12. sipa force-pushed on Jan 13, 2020
  13. ryanofsky approved
  14. ryanofsky commented at 5:23 pm on January 13, 2020: member
    Code review ACK 9b66083788581c264a097e26795561cb3eac455d. Only change since last review is suggested lvalue reference tweak
  15. in src/chain.h:343 in 9b66083788
    354+        READWRITE(VARINT(obj.nHeight, VarIntMode::NONNEGATIVE_SIGNED));
    355+        READWRITE(VARINT(obj.nStatus));
    356+        READWRITE(VARINT(obj.nTx));
    357+        if (obj.nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) READWRITE(VARINT(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED));
    358+        if (obj.nStatus & BLOCK_HAVE_DATA) READWRITE(VARINT(obj.nDataPos));
    359+        if (obj.nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(obj.nUndoPos));
    


    kallewoof commented at 4:33 am on January 16, 2020:

    9b66083788581c264a097e26795561cb3eac455d

    I know people aren’t fans of macros so this will probably be shut down, but this pattern appears often enough to almost warrant a READWRITEIF(condition, ...). Above cases would be

    0READWRITEIF(!(s.GetType() & SER_GETHASH), VARINT(_nVersion, VarIntMode::NONNEGATIVE_SIGNED));
    1...
    2READWRITEIF(obj.nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO), VARINT(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED));
    3READWRITEIF(obj.nStatus & BLOCK_HAVE_DATA, VARINT(obj.nDataPos));
    4READWRITEIF(obj.nStatus & BLOCK_HAVE_UNDO, VARINT(obj.nUndoPos));
    

    sipa commented at 1:16 pm on January 16, 2020:
    In general I’m not opposed to adding more macros for commonly-used serialization patterns, but I think that the benefit of “READWRITEIF(a, b)” over “if (a) READWRITE(b)” is marginal at best.
  16. kallewoof approved
  17. kallewoof commented at 4:39 am on January 16, 2020: member
    Code review ACK 2f1b2f4ed044fe005e5a6c1b55e95822e83c16df
  18. fanquake requested review from jamesob on Jan 16, 2020
  19. jamesob approved
  20. jamesob commented at 5:59 pm on January 17, 2020: member

    ACK 9b66083788581c264a097e26795561cb3eac455d (jamesob/ackr/17896.1.sipa.serialization_improvemen)

    Built locally, tested starting and stopping bitcoind twice with an existing datadir. These changes are thoroughly tested by functional tests.

    0Tested on Linux-4.15.0-47-generic-x86_64-with-Ubuntu-18.04-bionic
    1
    2Configured with `./configure LDFLAGS=-L/home/james/src/bitcoin/db4/lib/ CPPFLAGS=-I/home/james/src/bitcoin/db4/include/ CXXFLAGS=-std=c++11 -Wthread-safety-analysis -Werror -Wthread-safety-analysis -Werror --enable-wallet --enable-debug --with-daemon CXX=/usr/bin/clang++-4.0 CC=/usr/bin/clang-4.0 --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni PYTHONPATH= --disable-shared --with-pic --enable-benchmark=no --with-bignum=no --enable-module-recovery --disable-jni --no-create --no-recursion`
    3
    4Compiled with `/usr/bin/ccache /usr/bin/clang++-4.0 -std=c++11 -mavx -mavx2 -std=c++11 -Wthread-safety-analysis -Werror -Wthread-safety-analysis -Werror -O0 -g3 -ftrapv  -Wstack-protector -fstack-protector-all -msse4 -msha -msse4.1 -msse4.2`
    5
    6Compiler version: clang version 4.0.1-10 (tags/RELEASE_401/final)
    
  21. fanquake referenced this in commit a654626f07 on Jan 18, 2020
  22. fanquake merged this on Jan 18, 2020
  23. fanquake closed this on Jan 18, 2020

  24. fanquake removed this from the "Blockers" column in a project

  25. sidhujag referenced this in commit fc3573c422 on Jan 18, 2020
  26. sidhujag referenced this in commit a5a456f9a2 on Nov 10, 2020
  27. Fabcien referenced this in commit 742cd7c902 on Dec 8, 2020
  28. Fabcien referenced this in commit 2953167fb5 on Dec 8, 2020
  29. Fabcien referenced this in commit 0b536d79fb on Dec 8, 2020
  30. kittywhiskers referenced this in commit 9ccfec5a5c on Mar 10, 2021
  31. kittywhiskers referenced this in commit 62ea2c6dd6 on Mar 10, 2021
  32. kittywhiskers referenced this in commit bbe9c25e36 on Mar 16, 2021
  33. kittywhiskers referenced this in commit cf52d88923 on Mar 16, 2021
  34. PastaPastaPasta referenced this in commit 46cb6e23dc on Apr 18, 2021
  35. UdjinM6 referenced this in commit 20b71700dc on May 14, 2021
  36. kittywhiskers referenced this in commit fb6872d3da on May 20, 2021
  37. furszy referenced this in commit 5c93f159bc on Jul 5, 2021
  38. random-zebra referenced this in commit b4751e10ce on Aug 11, 2021
  39. DrahtBot locked this on Feb 15, 2022

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: 2024-12-18 18:12 UTC

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