Commit graph

195 commits

Author SHA1 Message Date
Andrew Chow
16b5b4b674
Merge bitcoin/bitcoin#28579: refactor: Remove redundant checks in compat/assumptions.h
fa1a384706 Move compat.h include from system.h to system.cpp (MarcoFalke)
88887531b7 Move compat/assumptions.h include to one place that actually needs it (MarcoFalke)
77774110f4 Remove __cplusplus from compat/assumptions.h (MarcoFalke)
faa3d4f1d8 Remove duplicate NDEBUG check from compat/assumptions.h (MarcoFalke)

Pull request description:

  Generally, compile-time checks should be close to the code that use them. Especially, since `compat/assumptions.h` is only included in one place, where iwyu suggests to remove it.

  Fix all issues:
  * The `NDEBUG` check is used in `util/check`, so it is redundant in `compat/assumptions.h`.
  * The `__cplusplus` check is redundant with `doc/dependencies.md` (see commit message).
  * Add missing `// IWYU pragma: keep` to avoid removing the include by accident.

ACKs for top commit:
  achow101:
    ACK fa1a384706
  TheCharlatan:
    re-ACK fa1a384706
  theuni:
    ACK fa1a384706

Tree-SHA512: f8b6db84be5d8844a2267345c0b1405fcbc39b8b5eeaa24db5b8412a74145fe44cf188b6b0c39cc2b062690ed37ca5b4662473484afe28dbec6469e79961389b
2023-11-28 16:51:28 -05:00
Anthony Towns
1410d300df serialize: Drop useless version param from GetSerializeSize() 2023-11-16 11:14:13 +10:00
Anthony Towns
bf574a7501 serialize: drop GetSerializeSizeMany 2023-11-16 11:14:10 +10:00
Anthony Towns
efa9eb6d7c serialize: Drop nVersion from [C]SizeComputer
Protocol version is no longer needed to work out the serialized size
of objects so drop that information from CSizeComputer and rename the
class to SizeComputer.
2023-11-16 10:20:30 +10:00
MarcoFalke
99990194ce
Remove WithParams serialization helper 2023-10-30 13:54:52 +01:00
MarcoFalke
ffffb4af83
scripted-diff: Use ser params operator
-BEGIN VERIFY SCRIPT-
 sed -i 's|WithParams(\([a-zA-Z:._]\+\), |\1(|g' $( git grep -l WithParams )
-END VERIFY SCRIPT-
2023-10-13 10:30:49 +02:00
Antoine Poinsot
9cb4c68b89
serialize: make GetSizeOfCompactSize constexpr 2023-10-08 02:43:17 +02:00
MarcoFalke
88887531b7
Move compat/assumptions.h include to one place that actually needs it
Also add the <IWYU pragma: keep> to avoid removing it by accident.
2023-10-04 11:25:23 +02:00
MarcoFalke
fac29a0ab1
Remove SER_GETHASH, hard-code client version in CKeyPool serialize
It was never set, so it can be removed along with any code reading it.
2023-09-19 16:11:59 +00:00
fanquake
5c7cdda992
Merge bitcoin/bitcoin#28473: refactor: Serialization parameter cleanups
fb6a2ab63e scripted-diff: use SER_PARAMS_OPFUNC (Anthony Towns)
5e5c8f86b6 serialize: add SER_PARAMS_OPFUNC (Anthony Towns)
33203f59b4 serialize: specify type for ParamsWrapper not ref (Anthony Towns)
bf147bfffa serialize: move ser_action functions out of global namespace (Anthony Towns)

Pull request description:

  Cleanups after #25284:

   * ser_action namespacing - https://github.com/bitcoin/bitcoin/pull/25284#discussion_r1316189977
   * make reference implicit - https://github.com/bitcoin/bitcoin/pull/25284#discussion_r1316277030
   * function notation - https://github.com/bitcoin/bitcoin/pull/25284#issuecomment-1710714821

ACKs for top commit:
  MarcoFalke:
    lgtm ACK fb6a2ab63e 💨
  TheCharlatan:
    ACK fb6a2ab63e

Tree-SHA512: aacca2ee9cfec360ade6b394606e13d1dfe05bc29c5fbdd48a4e6992bd420312d4ed0d32218d95c560646af326e9977728dc2e759990636298e326947f6f9526
2023-09-15 14:27:20 +01:00
Anthony Towns
5e5c8f86b6 serialize: add SER_PARAMS_OPFUNC 2023-09-14 10:25:26 +10:00
Anthony Towns
33203f59b4 serialize: specify type for ParamsWrapper not ref 2023-09-14 10:25:20 +10:00
Anthony Towns
bf147bfffa serialize: move ser_action functions out of global namespace 2023-09-14 10:00:45 +10:00
MarcoFalke
37e2b01113
[refactor] Allow std::array<std::byte, N> in serialize.h
This is already possible for C-style arrays, so allow it for C++11
std::array as well.
2023-09-12 22:44:28 +02:00
MarcoFalke
faec591d64
Support for serialization parameters
The moved part can be reviewed with the git options
 --ignore-all-space --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space

(Modified by Marco Falke)

Co-authored-by: Pieter Wuille <pieter@wuille.net>
2023-08-28 17:48:26 +02:00
MarcoFalke
fac42e9d35
Rename CSerAction* to Action*
This allows new code, added in the next commit, to conform to the coding
guideline: No C-prefix for class names.
2023-08-28 17:48:15 +02:00
MarcoFalke
aaaa3fa947
Replace READWRITEAS macro with AsBase wrapping function
Co-authored-by: Pieter Wuille <pieter@wuille.net>
2023-08-28 17:48:15 +02:00
Martin Leitner-Ankerl
f054bd072a refactor: use "if constexpr" in std::vector's Unserialize()
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
2023-08-03 10:35:22 +02:00
Martin Leitner-Ankerl
088caa68fb refactor: use "if constexpr" in std::vector's Serialize()
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
2023-08-03 10:34:42 +02:00
Martin Leitner-Ankerl
0fafaca4d3 refactor: use "if constexpr" in prevector's Unserialize()
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
2023-08-03 10:34:09 +02:00
Martin Leitner-Ankerl
c8839ec5cd refactor: use "if constexpr" in prevector's Serialize()
This gets rid of unnecessarily creating a temporary object T() to call
the right function.
2023-08-03 10:32:25 +02:00
Martin Leitner-Ankerl
1403d181c1 refactor: use fold expressions instead of recursive calls in UnserializeMany()
Instead of recursively calling `UnserializeMany` and peeling off one
argument at a time, use a fold expression. This simplifies the code,
makes it most likely faster because it reduces the number of function
calls, and compiles faster because there are fewer template
instantiations.
2023-08-03 10:31:33 +02:00
Martin Leitner-Ankerl
bd08a008b4 refactor: use fold expressions instead of recursive calls in SerializeMany()
Instead of recursively calling `SerializeMany` and peeling off one
argument at a time, use a fold expression. This simplifies the code,
makes it most likely faster because it reduces the number of function
calls, and compiles faster because there are fewer template
instantiations.
2023-08-03 10:30:02 +02:00
MarcoFalke
fac6af16f4
Allow std::byte serialization 2023-06-30 12:09:45 +02:00
Andrew Chow
561915f35f
Merge bitcoin/bitcoin#27978: refactor: Drop unsafe AsBytePtr function
7c853619ee refactor: Drop unsafe AsBytePtr function (Ryan Ofsky)

Pull request description:

  Replace calls to `AsBytePtr` with calls to `AsBytes` or `reinterpret_cast`. `AsBytePtr` is just a wrapper around `reinterpret_cast`. It accepts any type of pointer as an argument and uses `reinterpret_cast` to cast the argument to a `std::byte` pointer.

  Despite taking any type of pointer as an argument, it is not useful to call `AsBytePtr` on most types of pointers, because byte representations of most types will be platform specific or undefined. Also, because it is named similarly to the `AsBytes` function, `AsBytePtr` looks safer than it actually is. Both `AsBytes` and `AsBytePtr` call reinterpret_cast internally and may be unsafe to use with certain types, but AsBytes at least has some type checking and can only be called on `Span` objects, while `AsBytePtr` can be called on any pointer argument.

  The change was motivated by discussion on #27973 and #27927 and is compatible with those PRs

ACKs for top commit:
  jonatack:
    re-ACK 7c853619ee
  sipa:
    utACK 7c853619ee
  achow101:
    ACK 7c853619ee

Tree-SHA512: 200d858b1d4d579f081a7f9a14d488a99713b4918b4564ac3dd5c18578d927dbd6426e62e02f49f04a3fa73ca02ff7109c495cb0b92bec43c27d9b74e2f95757
2023-06-29 17:29:40 -04:00
Ryan Ofsky
7c853619ee refactor: Drop unsafe AsBytePtr function
Replace calls to AsBytePtr with direct calls to AsBytes or reinterpret_cast.
AsBytePtr is just a wrapper around reinterpret_cast. It accepts any type of
pointer as an argument and uses reinterpret_cast to cast the argument to a
std::byte pointer.

Despite taking any type of pointer as an argument, it is not useful to call
AsBytePtr on most types of pointers, because byte representations of most types
will be implmentation-specific. Also, because it is named similarly to the
AsBytes function, AsBytePtr looks safer than it actually is. Both AsBytes and
AsBytePtr call reinterpret_cast internally and may be unsafe to use with
certain types, but AsBytes at least has some type checking and can only be
called on Span objects, while AsBytePtr can be called on any pointer argument.

Co-authored-by: Pieter Wuille <pieter@wuille.net>
2023-06-28 15:14:45 -04:00
MarcoFalke
fa257bc831
util: Allow std::byte and char Span serialization 2023-06-27 10:13:29 +02:00
Hennadii Stepanov
96ee992ac3
clang-tidy: Fix modernize-use-default-member-init in headers
See https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-default-member-init.html
2023-01-31 11:50:10 +00:00
Hennadii Stepanov
306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
MarcoFalke
fa5103a9f5
Add ChronoFormatter to serialize 2022-07-26 11:05:04 +02:00
João Barbosa
bae4561938 scripted-diff: rename BytePtr to AsBytePtr
Building with iPhoneOS SDK fails because it also has `BytePtr` defined 
in /usr/include/MacTypes.h.

-BEGIN VERIFY SCRIPT-
sed -i 's/BytePtr/AsBytePtr/' $(git grep -l "BytePtr" src)
-END VERIFY SCRIPT-
2022-04-26 09:41:45 +01:00
MarcoFalke
fa5d2e678c
Remove unused char serialize 2022-01-02 11:52:11 +01:00
MarcoFalke
fa24493d63
Use spans of std::byte in serialize
This switches .read() and .write() to take spans of bytes.
2022-01-02 11:40:31 +01:00
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
Andrew Chow
3235847473 Types are compact size uints 2021-12-10 08:29:24 -05:00
MarcoFalke
ffff0d0442
refactor: Switch serialize to uint8_t (1/n) 2021-05-31 14:56:17 +02:00
Pieter Wuille
66545da200 Remove support for double serialization 2021-05-24 16:15:05 -07:00
MarcoFalke
e40224d0c7 Remove unused float serialization 2021-05-24 16:04:44 -07:00
Pieter Wuille
1d3ec2a1fd
Support bypassing range check in ReadCompactSize
This is needed when we want to encode an arbitrary number as CompactSize
like node service flags, which is a bitmask and could be bigger than the
usual size of an object.
2020-10-09 10:32:19 +02:00
Aaron Hook
1cabbddbca refactor: Use uint16_t instead of unsigned short
removed trailing whitespace to make linter happy
2020-06-22 12:12:22 +02:00
Pieter Wuille
71f016c6eb Remove old serialization primitives 2020-05-24 10:35:00 -07:00
Pieter Wuille
92beff15d3 Convert LimitedString to formatter 2020-05-24 10:35:00 -07:00
MarcoFalke
448bdff263
Merge #18317: Serialization improvements step 6 (all except wallet/gui)
f9ee0f37c2 Add comments to CustomUintFormatter (Pieter Wuille)
4eb5643e35 Convert everything except wallet/qt to new serialization (Pieter Wuille)
2b1f85e8c5 Convert blockencodings_tests to new serialization (Pieter Wuille)
73747afbbe Convert merkleblock to new serialization (Pieter Wuille)
d06fedd1bc Add SER_READ and SER_WRITE for read/write-dependent statements (Russell Yanofsky)
6f9a1e5ad0 Extend CustomUintFormatter to support enums (Russell Yanofsky)
769ee5fa00 Merge BigEndian functionality into CustomUintFormatter (Pieter Wuille)

Pull request description:

  The next step of changes from #10785.

  This:
  * Adds support for enum serialization to `CustomUintFormatter`, used in `CAddress` for service flags.
  * Merges `BigEndian` into `CustomUintFormatter`, used in `CNetAddr` for port numbers.
  * Converts everything (except wallet and gui) to use the new serialization framework.

ACKs for top commit:
  MarcoFalke:
    re-ACK f9ee0f37c2, only change is new documentation commit for CustomUintFormatter 📂
  ryanofsky:
    Code review ACK f9ee0f37c2. Just new commit adding comment since last review
  jonatack:
    Code review re-ACK f9ee0f37c2 only change since last review is an additional commit adding Doxygen documentation for `CustomUintFormatter`.

Tree-SHA512: e7a0a36afae592d5a4ff8c81ae04d858ac409388e361f2bc197d9a78abca45134218497ab2dfd6d031e0cce0ca586cf857077b7c6ce17fccf67e2d367c1b6cd4
2020-05-20 07:30:29 -04:00
Pieter Wuille
f9ee0f37c2 Add comments to CustomUintFormatter 2020-05-19 14:30:30 -07:00
MarcoFalke
fa488f131f
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-04-16 13:33:09 -04:00
Russell Yanofsky
d06fedd1bc Add SER_READ and SER_WRITE for read/write-dependent statements
Extracted and extended by Pieter Wuille from a comment by Russ
Yanofsky (see
https://github.com/bitcoin/bitcoin/pull/18317#discussion_r398625457).
2020-03-30 15:36:16 -07:00
Russell Yanofsky
6f9a1e5ad0 Extend CustomUintFormatter to support enums
Extracted by Pieter Wuille from a comment by Russ Yanofsky, see
https://github.com/bitcoin/bitcoin/pull/18317#discussion_r398821936.
2020-03-30 15:36:16 -07:00
Pieter Wuille
769ee5fa00 Merge BigEndian functionality into CustomUintFormatter 2020-03-30 15:36:14 -07:00
Wladimir J. van der Laan
727857d12d
Merge #18112: Serialization improvements step 5 (blockencodings)
353f376277 Convert blockencodings.h to new serialization framework (Pieter Wuille)
e574fff53e Add CustomUintFormatter (Pieter Wuille)
10633398f2 Add DifferenceFormatter (Russell Yanofsky)
56dd9f04c7 Make VectorFormatter support stateful formatters (Russell Yanofsky)
3ca574cef0 Convert CCompactSize to proper formatter (Pieter Wuille)

Pull request description:

  This is probably the most involved change in the sequence of changes extracted from #10785.

  In order to implement the differential encoding of BIP152, this change changes `VectorFormatter` to permit a stateful sub-formatter, which is then used by `DifferenceFormatter`. A `CustomUintFormatter` is added as well to do the 48-bit serialization of short ids.

ACKs for top commit:
  laanwj:
    ACK 353f376277, nice change
  ryanofsky:
    Code review ACK 353f376277. Only changes since last review are suggested assert change and MASK->MAX rename

Tree-SHA512: 976618991a8be62ba0738725b7cfa166a56cde998ebf1031ba6f28557032f1577b666ac7ae25cd498c0e1e740108c3c56a342620b724df41d6cc9d8bdafac037
2020-03-05 19:56:26 +01:00
Pieter Wuille
e574fff53e Add CustomUintFormatter 2020-02-25 14:10:38 -08:00