Block Wallet RPCs until wallet is synced to our current chain #9570

pull TheBlueMatt wants to merge 10 commits into bitcoin:master from TheBlueMatt:2017-01-fix-wallet-rpc-stale changing 14 files +259 −88
  1. TheBlueMatt commented at 11:53 pm on January 17, 2017: member

    This fixes #9148, though with a bit more code than I intended.

    There were two issues: a) wallet could return data based on partial block processing, because there were no locks between SyncTransaction calls, which is fixed relatively easily. and b) you could be busy-waiting on getbestblockheight , and call getbalance immediately after that changed, getting your balance as of the previous block instead of the new one, which is a regression in master from 0.13.

    To resolve the second, we introduce a primitive to block until the wallet has caught up either with the current chain, or the best chain (to resolve a simple race condition).

    This should probably get a test case, because I know you can see a in simple tests, but I’m not 100% sure about b.

  2. TheBlueMatt force-pushed on Jan 17, 2017
  3. TheBlueMatt force-pushed on Jan 18, 2017
  4. TheBlueMatt force-pushed on Jan 18, 2017
  5. TheBlueMatt force-pushed on Jan 18, 2017
  6. Make SyncTransaction provide an blocks instead of one transaction
    This simplifies fixing #9148 as we can now hold cs_wallet across
    an entire block instead of only per-tx.
    
    This change also removes the NOT_IN_BLOCK constant in favor of only
    passing the CBlockIndex* parameter to SyncTransactions when a new
    block is being connected, instead of also when a block is being
    disconnected.
    bc4c4c6686
  7. Make DisconnectBlock and ConnectBlock static in validation.cpp 4c70ae2606
  8. TheBlueMatt force-pushed on Jan 18, 2017
  9. TheBlueMatt force-pushed on Jan 18, 2017
  10. TheBlueMatt force-pushed on Jan 18, 2017
  11. TheBlueMatt force-pushed on Jan 18, 2017
  12. TheBlueMatt force-pushed on Jan 18, 2017
  13. Remove CValidationInterface::UpdatedTransaction
    This removes another callback from block connection logic, one more
    step towards fixing #9148.
    
    Note that this does a full mapWallet loop after the first block
    which is connected after restart. This is due to a previous bug
    where a coinbase transaction from the current best tip which
    existed in wallet immediately prior to restart would not be shown
    in the GUI except because on-load -checkblocks would call
    DisconnectBlock and ConnectBlock on the current tip. To avoid
    making it worse (ie that such transactions would never be displayed
    until restart), a scan to find such transactions was added.
    997b578c46
  14. Add ability to assert a lock is not held in DEBUG_LOCKORDER 05bd9d5ce3
  15. TheBlueMatt force-pushed on Jan 18, 2017
  16. Add CWallet::BlockUntilSyncedToCurrentChain()
    This blocks until the wallet has synced up to the current height.
    eda6afbac6
  17. Add calls to CWallet::BlockUntilSyncedToCurrentChain() in RPCs
    This resolves #9148
    d632a99951
  18. TheBlueMatt force-pushed on Jan 18, 2017
  19. jonasschnelli added the label RPC/REST/ZMQ on Jan 18, 2017
  20. TheBlueMatt commented at 7:57 pm on January 18, 2017: member

    @morcos points out that the cs_main holding at for the block’s transaction’s processing loop might interfere with all the fancy new fast block-response networking stuff we have going in 0.14. Sadly, because cs_main must come before cs_wallet, this isnt trivial to fix.

    One easy fix is to add another cs_wallet - cs_wallet_before_main which is locked here to emulate the behavior prior to the lock split in #7946.

  21. TheBlueMatt commented at 8:16 pm on January 18, 2017: member
    Thinking about it more, most of those things will not be running at that time anyway, because we only have one message processing thread. This may have adverse effects on miners who run with a wallet, but aside from that I dont think there is really all that much cs_main contention here (and certainly wouldn’t be a regression from 0.13). We can add a cs_wallet_before_main when we split message processing thread.
  22. f "Add CWallet::BlockUntilSyncedToCurrentChain()" add recheck timeout d26a43ce52
  23. f "Add CWallet::BlockUntilSyncedToCurrentChain()" Handle the case that we've moved passed the initial block without cs_main 6ddb874fbb
  24. f "Remove CValidationInterface::UpdatedTransaction" fix for multiwallet ff9d9603c0
  25. f "Add CWallet::BlockUntilSyncedToCurrentChain()" fix comment text da2861338f
  26. TheBlueMatt force-pushed on Jan 18, 2017
  27. laanwj added this to the milestone 0.14.0 on Jan 19, 2017
  28. morcos commented at 1:47 pm on January 19, 2017: member

    utACK?

    I think the code is right, but I wish there were a bit more straightforward way of doing this.

  29. TheBlueMatt commented at 4:28 pm on January 19, 2017: member
    Closing in favor of #9583 for 0.14. Will open a new PR with a bigger set of changes that also addresses the concerns in #9584.
  30. TheBlueMatt closed this on Jan 19, 2017

  31. MarcoFalke locked this on Sep 8, 2021


TheBlueMatt morcos

Labels
RPC/REST/ZMQ

Milestone
0.14.0


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-07-08 22:13 UTC

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