Skip to content

Conversation

@TheBlueMatt
Copy link
Contributor

Previously, ChainStateFlushed would fire either if a full flush
completed (which can happen due to memory limits, forced flush, or
on its own DATABASE_WRITE_INTERVAL timer) or on a
ChainStateFlushed-specific DATABASE_WRITE_INTERVAL timer. This is
both less clear for clients (as there are no guarantees about a
flush having actually happened prior to the call), and reults in
extra flushes not clearly intended by the code. We drop the second
case, providing a strong guarantee without removing the periodit
timer-based flushing.

This is a follow-up to discussion in #11857.

This much more accurately captures the meaning of the callback.

-BEGIN VERIFY SCRIPT-
sed -i 's/SetBestChain/ChainStateFlushed/g' src/validationinterface.h src/validationinterface.cpp src/wallet/wallet.h src/wallet/wallet.cpp src/validation.cpp src/index/txindex.h src/index/txindex.cpp
-END VERIFY SCRIPT-
Previously, ChainStateFlushed would fire either if a full flush
completed (which can happen due to memory limits, forced flush, or
on its own DATABASE_WRITE_INTERVAL timer) *or* on a
ChainStateFlushed-specific DATABASE_WRITE_INTERVAL timer. This is
both less clear for clients (as there are no guarantees about a
flush having actually happened prior to the call), and reults in
extra flushes not clearly intended by the code. We drop the second
case, providing a strong guarantee without removing the periodit
timer-based flushing.
@TheBlueMatt TheBlueMatt force-pushed the 2018-04-wallet-flush-better-criteria branch from 4be88be to 9cb6cdc Compare April 27, 2018 18:45
@sipa
Copy link
Member

sipa commented Apr 27, 2018

utACK 9cb6cdc

I believe the old semantics made sense as long as the chainstate was brought up to date with the index before wallets/node were running. As this is no longer the case we should only emit a signal when the on-disk state is actually fully flushed.

@laanwj
Copy link
Member

laanwj commented Apr 30, 2018

Making the guarantees of this callback concrete and documenting that is a good idea as it makes the code easier to understand and reason about.
utACK 9cb6cdc

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 9cb6cdc.

New semantics are definitely nicer, but could you update the commit message to say what practical effect of this change will be? According to the discussion in the other issue: #11857 (comment), it seems this change doesn't fix any existing race condition, and since there is a difference between DATABASE_FLUSH_INTERVAL and DATABASE_WRITE_INTERVAL values (24h vs 1h), does this mean in practice an extra day or so of blocks might now get scanned on startup?

@TheBlueMatt
Copy link
Contributor Author

Chatted about it offline and there should be no additional rescan on startup unless you crash during the partial flushing of the UTXO DB. You always rescan from the last locator written to the UTXO DB tip, but if the UTXO DB tip falls behind where the locator is you'll receive the BlockConnected callbacks during the re-connect anyway.

Copy link
Contributor

@jimpo jimpo left a comment

Choose a reason for hiding this comment

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

utACK 9cb6cdc.

// Update best block in wallet (so we can detect restored wallets).
GetMainSignals().SetBestChain(chainActive.GetLocator());
nLastSetChain = nNow;
GetMainSignals().ChainStateFlushed(chainActive.GetLocator());
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason not to inline this where full_flush_completed is set to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Less diff/fewer lockorder deps added by adding an ordering from cs_LastBlockFile. Doesn't really matter, though, should be easy to review that as well.

@laanwj laanwj merged commit 9cb6cdc into bitcoin:master May 2, 2018
laanwj added a commit that referenced this pull request May 2, 2018
9cb6cdc Simplify semantics of ChainStateFlushed callback (Matt Corallo)
50b6533 scripted-diff: Rename SetBestChain callback ChainStateFlushed (Matt Corallo)

Pull request description:

  Previously, ChainStateFlushed would fire either if a full flush
  completed (which can happen due to memory limits, forced flush, or
  on its own DATABASE_WRITE_INTERVAL timer) *or* on a
  ChainStateFlushed-specific DATABASE_WRITE_INTERVAL timer. This is
  both less clear for clients (as there are no guarantees about a
  flush having actually happened prior to the call), and reults in
  extra flushes not clearly intended by the code. We drop the second
  case, providing a strong guarantee without removing the periodit
  timer-based flushing.

  This is a follow-up to discussion in #11857.

Tree-SHA512: 22ba3a0954d265d28413dbf87040790ca5b439820ee7bbadab14028295ec190de82ce5cd664426c82e58b706dc84278868026fa8d066702eb6e6962c9ace1f8e
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 2, 2018
laanwj added a commit that referenced this pull request May 3, 2018
…fter #13106

21f5680 Trivial: s/SetBestChain/ChainStateFlushed in comments after #13106 (Russell Yanofsky)

Pull request description:

Tree-SHA512: 373896dd73c3ba202739433b22320a4b7ea6dc80ef84547b4ed72c7ae0d6746b109c8b1879359c43374d1816fe384cc31b24b87879ddefe993887140c2f0df9c
stamhe pushed a commit to stamhe/bitcoin that referenced this pull request Jun 27, 2018
HashUnlimited pushed a commit to HashUnlimited/chaincoin that referenced this pull request Sep 6, 2018
HashUnlimited added a commit to chaincoin/chaincoin that referenced this pull request Sep 6, 2018
Trivial: s/SetBestChain/ChainStateFlushed in comments after bitcoin#13106
TheArbitrator pushed a commit to TheArbitrator/dash that referenced this pull request Jun 4, 2021
…ments after bitcoin#13106

21f5680 Trivial: s/SetBestChain/ChainStateFlushed in comments after bitcoin#13106 (Russell Yanofsky)

Pull request description:

Tree-SHA512: 373896dd73c3ba202739433b22320a4b7ea6dc80ef84547b4ed72c7ae0d6746b109c8b1879359c43374d1816fe384cc31b24b87879ddefe993887140c2f0df9c
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 5, 2021
9cb6cdc Simplify semantics of ChainStateFlushed callback (Matt Corallo)
50b6533 scripted-diff: Rename SetBestChain callback ChainStateFlushed (Matt Corallo)

Pull request description:

  Previously, ChainStateFlushed would fire either if a full flush
  completed (which can happen due to memory limits, forced flush, or
  on its own DATABASE_WRITE_INTERVAL timer) *or* on a
  ChainStateFlushed-specific DATABASE_WRITE_INTERVAL timer. This is
  both less clear for clients (as there are no guarantees about a
  flush having actually happened prior to the call), and reults in
  extra flushes not clearly intended by the code. We drop the second
  case, providing a strong guarantee without removing the periodit
  timer-based flushing.

  This is a follow-up to discussion in bitcoin#11857.

Tree-SHA512: 22ba3a0954d265d28413dbf87040790ca5b439820ee7bbadab14028295ec190de82ce5cd664426c82e58b706dc84278868026fa8d066702eb6e6962c9ace1f8e
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 5, 2021
…ments after bitcoin#13106

21f5680 Trivial: s/SetBestChain/ChainStateFlushed in comments after bitcoin#13106 (Russell Yanofsky)

Pull request description:

Tree-SHA512: 373896dd73c3ba202739433b22320a4b7ea6dc80ef84547b4ed72c7ae0d6746b109c8b1879359c43374d1816fe384cc31b24b87879ddefe993887140c2f0df9c
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants