Skip to content

Conversation

dongcarl
Copy link
Contributor

@dongcarl dongcarl commented May 4, 2022

This decouples validation.cpp from netaddress.cpp (transitively,
timedata.cpp, and asmap.cpp).

This is important for libbitcoinkernel as:

- There is no reason for the consensus engine to be coupled with
  netaddress, timedata, and asmap
- Users of libbitcoinkernel can now easily supply their own
  std::function that provides the adjusted time.

See the src/Makefile.am changes for some satisfying removals.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 4, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25168 (refactor: Avoid passing params where not needed by MarcoFalke)
  • #25065 ([kernel 2c/n] Extract only what we use of init/common.cpp by dongcarl)
  • #24410 ([kernel 2a/n] Split hashing/index GetUTXOStats codepaths, decouple from coinstatsindex by dongcarl)

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.

@maflcko
Copy link
Member

maflcko commented May 5, 2022

So even if adjusted time was removed, there'd be a time callback?

@dongcarl
Copy link
Contributor Author

dongcarl commented May 5, 2022

@MarcoFalke

So even if adjusted time was removed, there'd be a time callback?

If usage of adjusted time in validation was removed, then we'd just remove the m_adjusted_time_callback member.

If you're asking about if we'll ever make the normal GetTime into a callback that users of libbitcoinkernel can plug into... Possibly! But it's quite low priority. GetAdjustedTime is much more of a problem since it relies on netaddress.

@sipa
Copy link
Member

sipa commented May 5, 2022

Why does adjusted time depend on asmap...?

@dongcarl
Copy link
Contributor Author

dongcarl commented May 5, 2022

@sipa

Why does adjusted time depend on asmap...?

Oh sorry, I misspoke. More precisely: adjusted time depends on netaddress, and linking in netaddress requires linking in asmap.

@dongcarl dongcarl force-pushed the 2022-05-libbitcoinkernel-adjtime branch from 4b5a8a1 to 45e2400 Compare May 13, 2022 15:52
@dongcarl
Copy link
Contributor Author

Pushed 4b5a8a1 -> 45e2400

@dongcarl dongcarl force-pushed the 2022-05-libbitcoinkernel-adjtime branch from 45e2400 to 52804f7 Compare May 16, 2022 15:49
@dongcarl
Copy link
Contributor Author

Pushed 45e2400 -> 52804f7

  • Don't use designated initializers 😢

Copy link
Contributor

@jamesob jamesob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 52804f7 (jamesob/ackr/25064.1.dongcarl.kernel_2b_n_add_chainst)

Built, reviewed, unittested locally. Change looks good and is very simple. A few minor points:

10:42 <_aj_> jamesob: #24531 -- VS 2019 (which CI uses) doesn't support them, and figuring out how to fix that isn't trivial
10:42 <@gribble> https://github.com/bitcoin/bitcoin/issues/24531 | Use designated initializers by MarcoFalke · Pull Request #24531 · bitcoin/bitcoin · GitHub
10:45 <sipsorcery> _aj_: in fairness VS2019 does seem support them it just seems to want to use a massive amount of memory to compile them...
10:47 <_aj_> sipsorcery: doesn't support them with the amount of memory we currently allocate for those CI jobs :-P
Show signature data

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK 52804f7ad0da32bc4d7be726e08e0b1e34619acb ([`jamesob/ackr/25064.1.dongcarl.kernel_2b_n_add_chainst`](https://github.com/jamesob/bitcoin/tree/ackr/25064.1.dongcarl.kernel_2b_n_add_chainst))

Built, reviewed, unittested locally. Change looks good and is very simple. A few minor points:

- - there's a lingering comment in `validation.cpp` that could use updating: https://github.com/jamesob/bitcoin/blob/52804f7ad0da32bc4d7be726e08e0b1e34619acb/src/validation.cpp#L2008
- - can't use designated initializers (yet?) because of a VS Code/CI issue:

10:42 <aj> jamesob: #24531 -- VS 2019 (which CI uses) doesn't support them, and figuring out how to fix that isn't trivial
10:42 <@gribble> #24531 | Use designated initializers by MarcoFalke · Pull Request #24531 · bitcoin/bitcoin · GitHub
10:45 aj: in fairness VS2019 does seem support them it just seems to want to use a massive amount of memory to compile them...
10:47 <aj> sipsorcery: doesn't support them with the amount of memory we currently allocate for those CI jobs :-P

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEGNRVI1NPYuZCSIrGepNdrbLETwUFAmKDyWUACgkQepNdrbLE
TwWRFQ//UtNY+1IMPL/xvHWvqwgWm9O9FzXZIswmIX3OVze3X9GFXk1sEb7RejHR
z8jFtQW+g5uh4I4vD85BoRyQPmhD2VSc4TCipRTLOjuzOp67OpgSrTq+my89Myh0
ggEQip73F+XPkQl1EjMF/YEH6W1xnUBtIZXLvrXuKm1W03BK5flfxVzsxKYIoj9p
Rb6zic0AaVnbFSxKFiz3F5QE/Vw5lfBbZGblHNAricmVneEX9UNt5CVhCn0mZ2Ki
Ad2UD3Ugbj/qXoF76QeN44QqMsoi57PxwF8Fs53KsuTjdAJSVnD4Ma3ulaeKAy2C
6RZsjJAFGXAGXVRIWr8vvneZmvXRSdnhYPOQvw5gGJTIJxcADH/pSuyP5kDP/CLA
gfCnq+/eK2zhf6B1u8JzUpEbik6IM0bVYamUShZqVQDOKH4nEf7aoOu7E+j0JbWf
gywqlOD3rpDeUS2o8c4TjRqRCIqWPXgHxRI53nQE6AXQvOnNzdLzmetRqvWlqFLu
SgYv4QE25XkFXjbQMDTE+VQ3Qf9/OiHrtRVdYMCpqEHiN2US9RAwGVOF2zqD3wxK
bcY6j5HtbGP341mhmlD3ERBvpk4qi+L5OQRd1s20LyiTVF4RIodOV9i0P1fLL/qh
nPCyUeEoxDp9xWDR9l7aMqxxxt8thNnBt1uvEqdElmdEDLZKTbk=
=9W+m
-----END PGP SIGNATURE-----

Show platform data

Tested on Linux-5.10.0-11-amd64-x86_64-with-glibc2.31

Configured with ./configure LDFLAGS=-L/home/james/src/bitcoin/db4/lib/ CPPFLAGS=-I/home/james/src/bitcoin/db4/include/ CXXFLAGS=-fPIE -pipe -O2 -g -Wthread-safety-analysis -Wall -Werror=sign-compare -Wsign-compare -Werror=thread-safety-analysis --enable-wallet --enable-debug --with-daemon --enable-natpmp-default CXX=/usr/local/bin/clang++ CC=/usr/local/bin/clang PYTHONPATH= --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --no-create --no-recursion

Compiled with /usr/bin/ccache /usr/local/bin/clang++ -std=c++17 -mavx -mavx2 -mpclmul -fPIE -pipe -O2 -g -Wthread-safety-analysis -Wall -Werror=sign-compare -Wsign-compare -Werror=thread-safety-analysis -O0 -g3 -ftrapv -fdebug-prefix-map=$(abs_top_srcdir)=.  -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -msse4.1 -msse4.2 -msse4 -msha  i

Compiler version: Debian clang version 13.0.1-++20220126092033+75e33f71c2da-1~exp1~20220126212112.63

@dongcarl dongcarl force-pushed the 2022-05-libbitcoinkernel-adjtime branch from 52804f7 to f554689 Compare May 17, 2022 16:48
@dongcarl
Copy link
Contributor Author

Pushed 52804f7 -> f554689

@dongcarl
Copy link
Contributor Author

@jamesob

  • can't use designated initializers (yet?) because of a VS Code/CI issue:

Yeah that's exactly right. We need to resolve #24531 first before we can use them :-/

@@ -17,6 +17,7 @@ class CChainParams;
*/
struct ChainstateManagerOpts {
const CChainParams& chainparams;
const std::function<int64_t()> adjusted_time_callback{nullptr};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good candidate for a not_null #24423

given that we assert not null where it is actually used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree!

@dongcarl dongcarl force-pushed the 2022-05-libbitcoinkernel-adjtime branch from f554689 to a4cb66a Compare May 18, 2022 15:59
@dongcarl
Copy link
Contributor Author

dongcarl added 3 commits May 20, 2022 11:54
[META] Although it seems like we don't need it for just one option,
       we're going to introduce another member to this struct *in the
       next commit*. In future patchsets for libbitcoinkernel decoupling
       it from ArgsManager, even more members will be added here.
This decouples validation.cpp from netaddress.cpp (transitively,
timedata.cpp, and asmap.cpp).

This is important for libbitcoinkernel as:

- There is no reason for the consensus engine to be coupled with
  netaddress, timedata, and asmap
- Users of libbitcoinkernel can now easily supply their own
  std::function that provides the adjusted time.

See the src/Makefile.am changes for some satisfying removals.
We want m_chainparams to be alive for the duration of
ChainstateManager's lifetime since ChainstateManager's behaviour depends
on m_chainparams.

We could allow for a std::shared_ptr to be passed in as m_chainparams,
but that complicates things further. Given that CChainParams is not an
entity class or struct, we can just copy it and have ChainstateManager
own it.
@dongcarl dongcarl force-pushed the 2022-05-libbitcoinkernel-adjtime branch from af8e546 to 53494bc Compare May 20, 2022 15:59
@dongcarl
Copy link
Contributor Author

Pushed af8e546 -> 53494bc

  • Rebased over master to resolve merge conflict

@JeremyRubin
Copy link
Contributor

JeremyRubin commented May 20, 2022

utack 53494bc

@maflcko maflcko merged commit 640eb77 into bitcoin:master May 20, 2022
@bitcoin bitcoin deleted a comment May 20, 2022
@bitcoin bitcoin locked as spam and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done or Closed or Rethinking
Development

Successfully merging this pull request may close these issues.

6 participants